date int64 1,220B 1,719B | question_description stringlengths 28 29.9k | accepted_answer stringlengths 12 26.4k | question_title stringlengths 14 159 |
|---|---|---|---|
1,665,540,504,000 |
I want to get some parts from my log file, I tried to cut request part for to get the user, module, action, doAjax and ajaxAction
For example, I have
195.xx.x.x - - [25/Apr/2017:09:60:xx +0200] "POST /userx/index.php?m=contacts&a=form&...
192.xx.x.x - - [25/Apr/2017:09:45:xx +0200] "POST /usery/index.php?m=custome... |
A perl "one-liner":
$ perl -lne '
BEGIN{
printf "%-10s%-10s%-10s%-10s%-15s\n", qw([user] [module] [action] [doAjax] [ajaxAction]);
}
$usr = $mde = $act = $doAj = $ajAc = "null";
$usr=$1 if m|\s/([^/]+)/|;
$mde=$1 if /m=(.+?)(&|$)/;
$act=$1 if /a=(.+?)(&|$)/;
$doAj=$1 if /doajax=(.+?)(&|$)/;
$ajAc=$1 if /acti... | Get specific information from a log file |
1,665,540,504,000 |
The ultimate goal here is to turn on/off touchpad on mouse plug, so
I'm trying to get some property of my mouse and my touchpad from udev database, using udevadm but I don't get how this working and unfortunately the manpage isn't clear enough to me…
$ lsb_release -irc
Distributor ID: Debian
Release: 8.4
Codename:... |
Note that the input number changed (from 25, what you tried, to 26, what ), because those are not guaranteed to be constant across boots. Try
udevadm info -q path -n /dev/input/by-id/usb-1ea7_2.4G_Wireless_Mouse-mouse
with the constant by-id symlinkg to get the path in the format udev expects, then something like
u... | confused about udevadm usage |
1,665,540,504,000 |
I have a file created with mysqldump that is 11GB. I need to use the "mysql" command to import it into a database, but I need to add:
USE db1;
at the top. It would take forever to rewrite the file. Is there a way I can concatenate another file at the beginning of the input redirect to fool it into looking at it as a... |
You can pipe it in:
cat text.txt sql_out.sql | mysql --host=...
Alternatively, to avoid having to create a new file:
(echo "USE db1;"; cat sql_out.sql) | mysql --host=...
| using cat at input file |
1,665,540,504,000 |
Let's say I started a service by using sudo service service_name start, I am interested in knowing all the port opened by this service. I can know port - program mapping by sudo netstat -tulnp but I need to know for a specific service.
|
For this, I usually use lsof with the option to show the ports in use.
Here's an example:
[root@localhost ~]# lsof -Pi | grep myprog
myprog 23411 user 9u IPv6 9828537 0t0 TCP 1.2.3.167:51163->1.2.3.54:8090 (ESTABLISHED)
myprog 23411 user 16u IPv4 9827813 0t0 TCP 1.2.3.167:60783->1.2.3.186:23 (ES... | How to check port opened on running a service? |
1,665,540,504,000 |
A bash scrip is invoked like this:
$./script 25 "str1 str2"
and it is supposed to launch a terminal, that runs another script that receives both arguments, exactly as they are above (including quotation marks). I've tried this:
lxterminal --command=$"./script2 "$"$@"
but this seems to omit the quotations marks, so t... |
The problem is that the argument to lxterminal's --command is just one string, it can't take a command and its arguments like some other terminals like xterm do.
lxterminal parses that string using its own rules to determine the command to run an its arguments. That's similar but not identical to the Bourne shell pars... | Pass on arguments with double quotation marks from one bash script to another |
1,665,540,504,000 |
How can I remove the first letter from a directory name? for example:
Folder is named as "AFolder_01" how can I rename it to "Folder_01"
The reason for my question is that I have list of folders and I want to rename all these folders at once by removing the first letter.
I found this code online to remove the last c... |
Once you have your directory name in a variable (e. g. dir), you can:
mv "$dir" "${dir:1}"
This will strip the first character from the variable. I shall leave sanity-checking that the new directory does not yet already exist up to you.
To add something to the beginning (e. g. the letter A):
mv "$dir" "A$dir"
| Remove first character in a folder name [duplicate] |
1,665,540,504,000 |
From a bash or sh shell, how can I determine if it was called with the bash or sh command, a login shell, an xterm, and, in the case of the former, how was that called?
For example, if I call bash from an xterm, and then call it again, inside that instance, it might output something like
me@mylinuxmachine:~$ bash
me@m... |
You may use pstree for this:
$ bash
bash-4.4$ pstree -p "$$"
-+= 00001 root /sbin/init
\-+= 85460 kk tmux: server (/tmp/tmux-1000/default) (tmux)
\-+= 96572 kk -ksh93 (ksh93)
\-+= 72474 kk bash
\-+= 14184 kk pstree -p 72474
\-+- 51965 kk sh -c ps -kaxwwo user,pid,ppid,pgid,command
\... | Determine how bash or sh was called |
1,665,540,504,000 |
I have found a behavior of shell I don't understand. When you execute
echo foo > /tmp/bar & exit
, the terminal is closed. But when you execute
exit & echo foo > /tmp/bar
, the terminal stays open and something like
[1] 4001
is printed on it.
The output of the first version can be seen, too, if you log into a diffe... |
Your first command,
echo foo > /tmp/bar & exit
starts a subshell in the background to run echo foo > /tmp/bar, and exits (the foreground shell). This closes your terminal, in the same way as simply typing exit. The background shell won't stay around very long at all, so you won't get a race; but if you do this with a... | End of session if exit command run in parallel to different command |
1,480,706,472,000 |
I've got a peace of large text file with readings like below,
name=ABC
class=3
age=7
roll_no=41
name=XYZ
class=4
age=9
roll_no=23
So, how can I separate each name with their respective age and write the result in a single line, values separated by a space, like this
ABC 3
XYZ 9
Is there any tool/script to save th... |
I'd use awk:
awk -F"=" '
{data[$1] = $2}
function output() {
if ("name" in data && "age" in data)
print data["name"], data["age"]
delete data
}
NF == 0 {output()}
END {output()}
' filename
| Separate two values from a large of text, while each of readings separated by a blank line |
1,480,706,472,000 |
The computer is running Yosemite. I was trying to move a couple documents from the download folder to documents via the command line using
find . -iname '*.pdf' -exec mv "{}" ./Documents \
The answer given answered a almost everything. I just an wondering now what happens to the files moved. Are they in the root user... |
The command might better have been as follows.
find ~/Downloads -iname "*.pdf" -exec mv '{}' ~/Documents \;
Note the semi-colon after the backslash. Or, also better as follows.
find ~/Downloads -iname "*.pdf" -exec mv '{}' ~/Documents +
Note the plus used instead.
Or even as follows.
find ~/Downloads -iname *.pdf -e... | Using 'find' in the command line |
1,480,706,472,000 |
I have this command:
ptr=`host $hostname`
Which results in this:
test.tester.test has address 192.168.1.1
This Works!
What I want now is to extract only the IP address (192.168.1.1), pass it
to the variable $myptr and run the following command:
if $myptr | sed -n '/\(\(1\?[0-9][0-9]\?\|2[0-4][0-9]\|25[0-5]\)\.\)\{3... |
You don't need any extravagant text processing on the output of host, you can just use dig +short to get only the IP address (and do the required reverse lookup on the IP).
dig +short "$hostname"
e.g.
ip="$(dig +short "$hostname")"
host "$ip"
Or directly:
host "$(dig +short "$hostname")"
| Pass variable IP address to if else |
1,480,706,472,000 |
I'm looking for a one-line command to make a file more readable. I want to replace all ; characters with newline unless it is inside a set of (). This is on a firewall, so I can only use bash; no perl etc.
Example input:
ProductName: Threat Emulation; product_family: Threat; Destination: (countryname: United States;... |
A little bit confusing regex for sed but workable
sed '
:a #mark return point
s/\(\(^\|)\)[^(]\+\);\s*\([^)]\+\((\|$\)\)/\1\n\3/ #remove ; between ) and (
ta #repeat if substitute success
s/[[:blank:];]\+$//... | Replace particular character but not if it is inside () |
1,480,706,472,000 |
I am on Debian 8 and I am searching for a command in debian to use root privilege without password. I am asking because I already saw it somewhere but can't find it anymore.
|
The command is sudo.
Add a line such as below into /etc/sudoers
sigis ALL=(ALL) NOPASSWD: ALL
This means user sigis can now run things like the command below without requiring password.
sudo shutdown -h now
| Use root privilege without password |
1,480,706,472,000 |
I do this in BASH
echo test "$1"
..expecting to get..
test test
..but I get..
test
Is this something possible to do? It would make my life easier since having a list files I could do something like mv a/b/test.py proj_copy/$1
|
You can use history expansion
$ echo test !#:^
echo test test
test test
$ echo a/b/test.py proj_copy/!#:^
echo a/b/test.py proj_copy/a/b/test.py
a/b/test.py proj_copy/a/b/test.py
!#
The entire command line typed so far.
:^
The first argument
You could also use brace expansion
$echo test{,}
test test
$echo ... | Possible to reuse first argument of BASH line in the same line? |
1,480,706,472,000 |
I am writing a script that checks a certain directory for any sub-directories starting with a specific word.
Here is my script thus far:
#!/bin/bash
function checkDirectory() {
themeDirectory="/usr/share/themes"
iconDirectory="/usr/share/icons"
# I don't know what to put for the regex.
regex=
if... |
If you only want to find directories matching a given pattern/prefix, I think you could just use find:
find /target/directory -type d -name "prefix*"
or, if you only want immediate subdirectories:
find /target/directory -maxdepth 1 -type d -name "prefix*"
Of course, there's also -regexif you need an actual regex mat... | Use regex to check if particular directory has folders starting with specific word |
1,480,706,472,000 |
I want to delete file not by date access or created, but by filename. The filenames will be dates and I want to have a cronjob run once a week that will purge filename dates older than 7 days. I could do a
find /my/directory -type f -name '*file-name.yyyy-mm-dd.qz' -delete
But I would have to change the script on a w... |
Here is a more robust form that correctly handles spaces (or even newlines) in filenames and directory names.
find . -type f -name '*.[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9].qz' -exec sh -c 'fdate="${1%.qz}"; fdate="${fdate##*.}"; [ "$fdate" "<" "$(date +%F -d "7 days ago")" ] && rm "$1"' find-sh {} \;
This invol... | How do I delete file by filename that are set as dates? |
1,480,706,472,000 |
I'm currently doing my thesis and thus working on a school server. And unfortunately, I'm struggling with even the most basic concepts. Such as this.
I have a directory /home/myname/Data
If I'm in /home, and use ls I don't see the directory myname, yet, when I specify cd myname it still works and l works as well. Can... |
This feels like your home directory is being automounted on demand. This configuration is most frequently used when there are a number of free access workstations. It allows for backups to be taken of files on the central server, and the workstations can be rebuilt at any time from a standard image that has no need to... | Command works, and then doesn't (cd/ls) |
1,480,706,472,000 |
I have a
nginx -V 2>&1 | \
grep -qi 'nginx/1.9.10\|ngx_pagespeed-release-1.9.32.10\|openssl-1.0.2f\|modsecurity-2.9.0' \
&& echo "has the stuff we need" \
|| echo "missing something"
which is going against
[root@mage2appblock vagrant]# nginx -V
nginx version: nginx/1.9.10
built by gcc 4.4.7 20120313 (Red Hat 4.4.7... |
Work with a little modification:
[ $(nginx -V 2>&1 |
grep -cFf <(
echo 'nginx/1.9.10
ngx_pagespeed-release-1.9.32.10
openssl-1.0.2f
modsecurity-2.9.0'
)) -eq 4 ] &&
echo "has the stuff we need" ||
echo "missing something"
| grep match multiple substrings and pass or fail on missing |
1,480,706,472,000 |
a question -
in some case, I saw command line like this
. ./test.sh
I'm curious why use "." before "./test.sh"
what condition we have to use "." before a command?
|
Running . ./test.sh is similar to running source ./test.sh. It's not running the file test.sh as an executable. Instead it's running it's contents line by line into your current shell. So it could for example also modify your current environment.
| what condition we need to use "." in command line? [duplicate] |
1,480,706,472,000 |
Edited due to people want to know more then me just wanting to know how to deal with two directories with same names in different places and move one into another when mv will not allow it if files are in destanation area ..
they want to know what I am trying to do and why so ...
my script gets all of the directores w... |
had it check to see if parent dir was already created in the different desanation base folder then if true just copy into it then delete the old dir else move the whole thing
## check to see if other parent dir is there if not then make it so
if [[ ! -d "$move_t... | cannot move Directory not empty |
1,480,706,472,000 |
While comparing 2 fairly big directories using diff -rq ... I want to exclude certain file types like tar.gz or error_log.
How do I do that?
|
GNU diff has options for doing this (see manual page):
-x, --exclude=PAT
exclude files that match PAT
-X, --exclude-from=FILE
exclude files that match any pattern in FILE
The pattern in each case is a glob (* for any number of characters):
diff -rq -x '*.tar.gz' -x '*error_log' foo bar
See... | Diff command with file type exceptions |
1,480,706,472,000 |
I'm looking for a simple way to configure an external Access Point (IP address, SSID, WPA key, turn WiFi on/off, etc.) via Linux command line instead of the standard web interface that APs offer.
This could be either an off-the-shelf AP that offers this feature, or a procedure to accomplish this with any standard APs... |
You'll (almost certainly) need to flash a custom firmware on the AP to enable this functionality. The two most common firmwares to use for this are OpenWRT and DD-WRT. They're very similar but have slightly different hardware compatibility lists. If you already have the AP check to see if one of them support it. I... | Access Point configurable via Linux [duplicate] |
1,480,706,472,000 |
I have in a folder (eg /tmp) the following files
1.id
2.id
3.id
4.id
so on...
In these files, there is one number inside. For example in 1.id it can be the 1000, in 2.id it can be the 2000 etc.
I want an one line bash command to get the value (number) of all these files automatically (*.id) but append also the filena... |
Just use grep in this folder:
grep "" *.id
Output:
1.id:123
2.id:13
3.id:5
4.id:87876
BTW: I often use this in proc or sysfs filesystems;
cd /sys/class/net/eth0
grep "" *
This gives you all infos in sysfs about the ethernet interface eth0.
| Bash Command Get Data from multiple files and append the file name |
1,480,706,472,000 |
I am attempting to do the matasano cryptopals challenges in bash.
The first step is here
I found this stackexchange thread with a partial solution.
printf 49276d2 | xxd -r -p | base64
which produces SSdt as wanted.
I am looking to make a bash script so I can simply do
hexto64 49276d2
and get the same result. I'm no... |
In your script file named hexto64, simply write :
#!/bin/bash
printf "%s" "$1" | xxd -r -p | base64
And then you can use it as such :
hexto64 49276d2
Just so you know, $1 means the first parameter you gave after the program name : 49276d2 in our case.
| I am attempting to write a bash script to convert hex to base64 |
1,480,706,472,000 |
I have a problem with my remote server hosted by my provider, I have only SSH access. The problem consist of getting this error file system rootfs has reached critical status that causes problems with several services like smtp, I want to resize my partitions.
I want to:
- Decrease size of /home
- Increase the size of... |
Given your comment on Anthon's answer, I think the actual solution to your problem may be to tighten down your OS's logrotate configuration.
While it is possible to move /var/log per Anthon's answer, I wouldn't recommend it.
| Live resizing of an ext3 filesytem on CentOS6.5 |
1,480,706,472,000 |
I'm taking a basic Unix course and right now we're learning terminal.
My directions are
create a directory called company and subdirectories called sales, accounting and marketing.
So I did that.
mkdir company
cd company
mkdir sales
mkdir accounting
mkdir marketing
And then create files called file1, file2 and fi... |
If you are in the company directory then try this:
cp file1 sales
cp file2 sales
OR
cp file1 sales; cp file2 sales
Or
cp file1 file2 file3 sales
The last is the easiest and can accomplish copying all files it a single subdirectory in one line. If you want to complete the task and copy each file to each subdirector... | No such directory after creating it |
1,480,706,472,000 |
I have directory A and B. Each of them contains another directory with item.json inside.
Only item.json file is persistent in directories so I can't copy-paste the directories.
A:
./path/Item A/item.json
./path/Item B/item.json
...
./path/Item Z/item.json
B:
./new/Item A/item.json
./new/Item B/item.json
...
./new/Ite... |
Your solution is fine! If you like to see alternatives, my suggestion is just cp!
I presume you want to copy just "item.json" files and that you can have other
contents not to be copied.
cd path; cp --parents */item.json ../new
| Replace bunch of files maintaining path |
1,480,706,472,000 |
I use this following sed command for display names of files with a specific form:
ls -1 *|sed 's/^\(.*\).png/\1\/\1,/g'
If I have two files named BOH_Contour.png and BOV_Web.png, I obtain
BOH_Contour/BOH_Contour,
BOV_Web/BOV_Web,
Now I want to remove all _ in the second part of this result and to obtain
BOH_Contour/... |
That's typically where you'd use the hold space:
ls | sed '
/\.png$/!d; # discard everything but lines ending in .png
s///; # remove that .png
h; # store on the hold space
s/_//g; # remove underscores
H; # append (with a newline) to the hold space
g; # retrieve that hol... | Two operations with sed on the same pattern |
1,480,706,472,000 |
I have a task to copy all files from multiple directories with special names to a target directory.
So I build this directory to test my command. The test directory tree looks like:
.
├── dir1
│ └── file1
└── test
My intended command to mv all files from dir1 to test is:
find . -type d -name "*dir*" -exec mv {}/* t... |
mv "$dir_path"/* ... will not only move files but everything in "$dir_path". At least everything whose name does not start with a dot (hidden files). In bash you can change this with the option dotglob. But if the * expands nicely (matches everything but not too much for a command line) then you can use a shell for in... | How to express all files/directories at the extra -exec option of `find` command? |
1,480,706,472,000 |
I want to remove .txt or .csv files in a single line.
What I have in my directory
tachomi$ ls
file1.csv file1.sql file1.txt file2.csv file2.sql file2.txt
I only want .sql files so I want to know if there's a way to execute commands using logical operators such as AND or OR in a single line
tachomi$ rm *.txt AND... |
Simply:
rm *.txt *.csv
And if your shell supports brace expansion, you can:
rm *.{txt,csv}
| can I use logical operators to remove all files that matches with one and/or other pattern in a single line? |
1,480,706,472,000 |
I often use the space-backslash combination ( ) to split a command and its parameters into various lines and make it more readable:
/home/user> ls -ltra \
> file1.txt \
> file2.txt
Recently I used an instruction with a similar format on my terminal window. Since I was going use the same files in various instructions... |
If you're using a sh-compatible shell (like bash), that > prompt is called the "secondary prompt". It's set by the value of the PS2 variable, just like PS1 sets the normal prompt.
You should be able to change it to # pretty easily:
PS2='# '
You might want to put that into your ~/.bashrc (or whatever the equivalent is... | Problem when splitting command with backslash in unix prompt |
1,480,706,472,000 |
I want to perform the following command in command line :
$ md5sum $(find . -type f)
But this would cause problems when it encounter files with spaces in filenames :
md5sum: Kaufmann: No such file or directory
md5sum: Mobile: No such file or directory
md5sum: 3D: No such file or directory
md5sum: Graphics: No such... |
Do this way instead:
find . -type f -exec md5sum {} \;
This way spaces in the matched filenames will be handled correctly.
| How to escape spaces while using command's output in command line [duplicate] |
1,480,706,472,000 |
How can I get the speed of my internet connection from the terminal? Is there any script or commandline application(s) available?
I'm using CentOS 6.5 .
|
you can do it, open your terminal and type as
wget -O speedtest-cli https://raw.github.com/sivel/speedtest-cli/master/speedtest_cli.py
chmod +x speedtest-cli
./speedtest-cli
For example:
[raja@localhost ~]$ ./speedtest-cli
Retrieving speedtest.net configuration...
Retrieving speedtest.net server lis... | check internet speed from terminal? [duplicate] |
1,480,706,472,000 |
I have a directory with daily backups of my entire MySQL database.
I want to import the most recent backup into the database.
I know to import a backup I need to use mysql -u root -ppasswordhere < backup.sql
I've managed to get the most recent file with ls -Art | grep '.sql' | tail -n 1, but I don't really know how ... |
Have you tried this?
mysql -u root -ppasswordhere < $(ls -Art | grep '.sql' | tail -n 1)
| Mysql import the most recent file from a directory |
1,480,706,472,000 |
I have file int the following format:
.
.
.
Name:abc
Occupation:def
.
.
Name:xyz
Occupation:ghi
.
.
I want to extract the name and occupation field and save it in another file out.txt using vim in the following format:
Name:abc
Occupation:def
Name:def
Occupation:ghi
EDIT:Occupation field position in in... |
ggyG:e out.txt<cr>p:v/Name\|Occupation/d<cr>:w<cr>
Explanation
gg # Go to beginning of file
y # yank (copy)
G # to end of file
:e out.txt # Open a new file called out.txt
p # paste what you just copied
:v/Name\|Occupation/d # Delete all lines that don't contain Name or Occupation
:w # save
| Exracting fields in file and storing it in different file in vim |
1,480,706,472,000 |
I am confused on the -exec command. E.g. in this case:
find . -type f -name "*.c" -exec cat {} \;>all_c_files.txt
It seems that I get cat file1 file2 file3 ... fileN
While in this case:
find . -type f -name "*.txt" -exec cp {} OLD \;
I get:
`cp file1 OLD`
`cp file2 OLD`
`cp file3 OLD`
...
`cp fileN O... |
I suppose that you are confused by cat command (and shell redirection), and not by find one.
find . -type f -name "*.c" -exec cat {} \; > all_c_files.txt is equivalent to:
(
cat file1 ;
cat file2 ;
cat file3 ;
...
cat fileN
) > all_c_files.txt
obviously the previous command and the following one have the s... | How does -exec actually work |
1,480,706,472,000 |
I have a lot of scanned images and images/photos I'm working on with
multiple versions. When I print them (using various programs), all I
get is the image and, often, it's difficult to tell which image came
from which file. This is particularly frustrating with my (27K) photos
when I have a print and want another co... |
You might look at feh (http://feh.finalrewind.org/), which has a --caption-path option:
--caption-path PATH
Path to directory containing image captions. This turns on caption
viewing, and if captions are found in PATH, which is relative to
the directory of each image, they are overlayed ... | Automatically printing images with added captions |
1,480,706,472,000 |
When I reboot my machine (as I did today) I seem to lose some functionality, specifically my previous ssh keys that I had copied over to other machines that had allowed me to login without a password seem to have stopped functioning.
I've tried replacing the key by generating a new key, destroying the old keys on both... |
If you have encrypted your private key (by supplying a passphrase when you created it), then you have to decrypt it before you can log into remote systems. It is possible you were using an ssh agent on the local system to store the unencrypted key. When you rebooted, the key would have been flushed from the agent's ... | Rebooting makes me lose my password-less keys on other machines |
1,480,706,472,000 |
This question is somewhat similar to this: Unix/Linux command syntax
Suppose I have a program foo that takes arguments -a and -b. If both a and b take a string argument what is the meaning of this
foo -b -a bar
If multiple b:s are allowed
foo -b -a -b
??
Is there a true specification of the command line syntax somew... |
Unless you can find something that says option arguments can't start with a minus sign, then the only possible interpretation is
-b=-a
bar
See also: POSIX Utility Conventions.
| Standard command line syntax ambigiuty in interpretation rules? |
1,480,706,472,000 |
Is there an equivalent to the NET.exe suite for linux systems with which I can do net view queries for example?
|
Samba ships a net executable itself. From the man page:
The Samba net utility is meant to work just like the net utility
available for windows and DOS.
| Program to manipulate Samba shares (net.exe equivalent) |
1,480,706,472,000 |
I have a list of scripts
./myscript <param> | grep "asd"
./myotherscript <param> <param> > file
...
How can I automaticaly run another script when one of these command in the list is executed and finished?
|
There are multiple ways to automatically execute something after a specific command:
function
Create a function named after your specific command and execute the specific command afterwards. This is in my opinion the simplest and cleanest solution.
function myotherscript() {
command myotherscript "$@"
other_comm... | Run a script after some command were executed |
1,480,706,472,000 |
When I run:
ssh [email protected] bash -c "/home/devops_staging/deployJob.sh example"
I encounter the following error:
/home/devops_staging/deployJob.sh: line 4: $1: unbound variable
If I run it without the bash -c part, it works as expected.
ssh [email protected] /home/devops_staging/deployJob.sh example
deploy su... |
I think it's a duplicate of the following question: ssh command with quotes. It had been noted, but the author here stated:
after reading that I'm still not sure why it works like this
therefore this answer tries to explain the issue specifically in the context of the code used in the current question.
The most impo... | Bash script errors with "unbound variable" only when invoked via SSH [duplicate] |
1,480,706,472,000 |
I have the following directory names:
/aaa
/bbb
/ccc
/ddd
And I want to run the following command passing in the directory names with just ls:
ls | composer show drupal/MY_DIRECTORY_NAME_HERE --available | ack versions
How can I create a one line command to pass in the directory name into this composer command in a... |
Since you obviously want to apply the command to all of the existing sub-directories, the cleanest way to do so (avoids the issue of directory names with special characters) would be
for dir in */
do
composer show drupal/"$dir" --available | ack versions
done
This will iterate over all non-hidden directories and s... | Passing directory names into a bash command individually [duplicate] |
1,480,706,472,000 |
I've been going down the i3wm road of pain and can't for the life of me understand how to change the output device with cli commands.
Setup:
Using i3-gaps (Base Distro is Garuda Linux)
pipewire is the audio provider
When using pavucontrol I can switch between my Headphones and Speakers as the output port but can't se... |
Found a solution and wrote a short script for it
if [[ $(pactl list | grep "Active Port: analog-output") == *"headphones"* ]]; then
pactl set-sink-port 0 analog-output-lineout
else
pactl set-sink-port 0 analog-output-headphones
fi
Also added this to my i3config:
bindsym F6 exec --no-startup-id sh ~/path/to/sc... | Having trouble using cli to switch between playback devices with pipewire |
1,658,510,518,000 |
I have a text file with however many lines. One line is:
fixed_stringA = 123, fixed_stringB = 456
I have a second text file (again with however many lines). These 2 lines are in this order, in middle of the file:
found_value1=unknown1
found_value2=unknown2
My goal is to modify these two lines second text file so t... |
I can get it down to these two lines:
values="$(sed -n -E 's/^.*fixed_stringA\s*=\s*([0-9]+)\s*,\s*fixed_stringB\s*=\s*([0-9]+).*$/\1,\2/p' first_file)"
sed -i -E -e "s/unknown1/${values%,*}/" -e "s/unknown2/${values#*,}/" second_file.txt
The first line uses sed with the -n flag so it suppresses regular output, and i... | substitute 2 substrings from a single line in a file into 2 different lines in a different file from command line |
1,658,510,518,000 |
Why this sed command:
sed /^a/,/i$/p
prints all lines and not just the lines that beginning with "a" and end with "i"?
It is not too clear to me how sed /BEGIN/,/END/p works.
STDIN:
arthuri
John
Johnny
Michael
STDOUT:
arthuri
arthuri
John
John
Johnny
Johnny
Michael
Michael
|
sed by defaults prints the pattern space at the end of each cycle as long as the d command has not been invoked.
That can be disabled with the -n option, or by making the first line of the sed script: #n.
So, here, in addition to that default printing, you're telling sed to also print the pattern space starting with t... | Why this sed command prints all the lines? |
1,658,510,518,000 |
About man shutdown at:
shutdown(8) — Linux manual page
it indicates:
...
The first argument may be a time string (which is usually "now").
Optionally, this may be followed by a wall message to be sent to
all logged-in users before going down.
...
Note that to specify a wall message you must specify... |
The information is buried in systemd's sources in src/login/logind-utmp.c:
Warn immediately if less than 15 minutes are left (when the command is run):
/* Warn immediately if less than 15 minutes are left */
if (elapse - n < 15 * USEC_PER_MINUTE) {
r = warn_wall(m, n);
if (r == 0)
retur... | shutdown command: why the "wall message" is not broadcast to all logged users if the time is equals or greater than 16 minutes? |
1,658,510,518,000 |
I have a following list of files;
11F.fastq.gz
11R.fastq.gz
12F.fastq.gz
12R.fastq.gz
I'd like to rename these file names to the following;
11_S11_L001_R1_001.fastq.gz
11_S11_L001_R2_001.fastq.gz
12_S12_L001_R1_001.fastq.gz
12_S12_L001_R2_001.fastq.gz
I tried reanme as follows
rename 's/F.fastq/_S_L001_R1_001.fastq/... |
With Perl's rename commandline, you can capture the variable part ((...)) and use back references ($1):
rename -n 's/(\d+)F\.fastq/$1_S$1_L001_R1_001.fastq/' *F.fastq.gz
rename -n 's/(\d+)R\.fastq/$1_S$1_L001_R2_001.fastq/' *R.fastq.gz
Remove the -n if you're happy with the output.
| Batch renaming file names including a part of old file name |
1,658,510,518,000 |
I'm looking to substitute text inside a file after a certain pattern.
For example:
The content of example.txt is
Something==x.y.z
I'd like to change it to
Something>=x.y.z,<x.y.z+1.0
I know I can use sed -i 's/==/>=/g' example.txt to change the == but I do not know add <x.y.z+1.0 after a certain pattern.
(Please not... |
The following sed command assumes that there is exactly one == in the line and extracts the parts before and after it as groups 1 and 2 which can be used in the substitution.
sed 's/\(.*\)==\(.*\)/\1>=\2,<\2+1.0/'
With the input
Something==x.y.z
argcomplete==1.12.3
youtube-dl==2021.6.6
systemd-python==234
the output... | Using sed to substitute text and add text after certain pattern |
1,658,510,518,000 |
When I write multi-line statements in interactive mode in Zsh, it will prefix my statements with the block type I'm in like so:
% for i in $(seq 3); do
for> echo $i
for> done
1
2
3
% function foo() {
function> echo bar
function> }
% foo
bar
I prefer not to see for> and function> and other code block prefixes. I'm not... |
This is the secondary prompt, configured through the variable PS2, in all Bourne-style shells including zsh. In zsh, it defaults to showing which shell constructs (loops, quotes, etc.) are open, using the %_ prompt escape. In bash, it defaults to > and you can use escape sequences but they aren't very useful.
If you ... | Zsh: how do I remove block prefixes when writing multi-line statements in interactive mode? |
1,658,510,518,000 |
I am trying to build Cube2 Sauerbraten, But I need the OpenGL and SDL2 libraries to run the makefile. (I am using ubuntu here) I tried running sudo apt-get install --yes software-properties-common g++ make then sudo apt-get install --yes libsdl2-dev then sudo apt-get install --yes freeglut3-dev and lastly, to compile,... |
Your program has many files, then a single g++ won’t be enough. A make (No arguments) command is often the right way to compile the software from the Makefile.
The Makefile is in the src folder… you should enter it (cd src) before launching make. make install compile the software if not done and install it.
According ... | How to install OpenGl and SDL2 libraries on ubuntu |
1,658,510,518,000 |
How do I kill all processes with my username that were started within (past hour, past day) etc?
|
find your processes that are younger than an hour
extract the pids
kill the pids
process list:
$ ps -e -o pid,user,etimes,comm \
| awk -v me=$USER '$2 == me && $3 <= 3600 { print }'
Produces
661162 jaroslav 3006 chrome
667859 jaroslav 1711 chrome
669145 jaroslav 1471 chrome
671222 jaroslav 1016 ... | Kill all of my processes that were started within the past hour? |
1,658,510,518,000 |
I created a new user and logged in successfully on my ubuntu 20.04 machine.
When I logged in as root the terminal looks like this:
root@ubuntu-s-1vcpu-1gb-fra1-01:~#
When I login with my "mynewuser" account I only see a $, nothing more. I want to display the same information as before:
mynewuser@ubuntu-s-1vcpu-1gb-fra... |
If you change the order of operations then it can be simplified somewhat:
useradd -m -s /bin/bash mynewuser
usermod -aG sudo mynewuser
su -u mynewuser - mkdir -m 700 .ssh
echo "...public key..." | su -u mynewuser - tee .ssh/authorized_keys
This should also mean that when you create the home directory the scripts from... | Information of new user won´t show in terminal |
1,658,510,518,000 |
I am building a script with usr/bin/time program to monitor the RAM usage of a script and storing it in a variable so i can check if it is higher than a specified limit $mlimit, like this example using ls / as the command:
$mlimit=512000 #512mb limit in kilobytes
$musage=$(/usr/bin/time -f "%M" ls / | rev | cut -f 1 ... |
GNU time outputs the resource usage information on stderr, though can be told to write it elsewhere with -o
{
musage=$(command time -o /dev/fd/4 -f %M ls / 4>&1 >&3 3>&-)
} 3>&1
Would record the max memory usage in the variable whilst leaving ls' stdout and stderr alone.
That works by duplicating the original fd 1 ... | How to get only memory peak usage with /usr/bin/time? |
1,658,510,518,000 |
this question (to my knowledge) has not been asked before, yet would benefit anyone that uses tmux!
I tried searching github too for plugins etc, but no luck yet.
What I'd like to achieve:
Cycle between windows of the same name.
Why?
Imagine you have 6 tmux windows, in the following order, status bar would look simi... |
I created a basic solution.
Save the following script as _tmux-cycle-samename and make it executable (chmod +x _tmux-cycle-samename).
#!/bin/sh
if [ "$1" = "-r" ]; then filter=tac; else filter=cat; fi
name="$(tmux display-message -p '#W' | sed 's|\(.\)|[\\\1]|g')"
tmux select-window -t "$(
tmux list-windows -F ... | cycle tmux windows of the same name |
1,658,510,518,000 |
In tmux I get into the 2nd nested session by using C-b C-b (Ctrl+b twice). But if I have a 3rd nested session, I can't use C-b C-b C-b to get to the 3rd nested session. Somehow if I spam C-b, sometimes it can get to the 3rd nested session. What's happening?
|
You have to use 1*2*2 (=4) control-b's to get a control-b to the third level tmux with the default bindings, and 1*2*2*2 (=8) to get it to a fourth level tmux, and in general 2n-1 to get to the nth tmux.
"What is happening?". All the control-b's are read by the first level tmux. The first one is taken to introduce a c... | How can I make tmux use "C-b C-b C-b" to get into the 3rd nested tmux session? |
1,658,510,518,000 |
I have txt file that I have to swap the first paragraph with last one. I did it but now I don't know how to paste everything in a new txt file.
This is my command
tail -14 gl.txt ; head -n 74 gl.txt | tail -n 68 ; head -5 gl.txt
I tried to use > like this
tail -14 gl.txt ; head -n 74 gl.txt | tail -n 68 ; head -5 gl.... |
try to grouping the commands within { ...; } and redirect the output at the end to a file:
{ tail -14 gl.txt ; head -n 74 gl.txt | tail -n 68 ; head -5 gl.txt; } > gl_ok.txt
note that the last semi-colon before close bracket is mandatory or group commands can be terminated with a newline like below:
{ tail -14 gl.txt... | How to paste multiple commands output into single output file |
1,658,510,518,000 |
I am working on vxlan tunneling between Linux - commercial routers. I need to debug some interface settings.
The command sudo ip -d link show DEV gives me a great output but the output format is like a long single line as below.
katabey@leaf-1:mgmt:~$ sudo ip -d link show vxlan_10
11: vxlan_10: <BROADCAST,MULTICAST,UP... |
try:
your-command |grep -Eo '(vxlan id|srcport|dstport) [0-9]+|local [0-9.]+'
| Formatting command output that is a long single line |
1,658,510,518,000 |
Is there any command line tool to list the newly added package in debian?
Answers accepted for debian stable, testing or Sid (because it is a highly active release)
|
aptitude keeps track of new packages, and you can list them using
aptitude search '~N'
They show up in the “New Packages” section in the UI.
To clear the list of new packages, run
aptitude forget-new
or press f in the UI; you can also specify a subset of new packages to be “forgotten”.
The set of packages considered... | How to get the list of the newcomers packages in debian? |
1,658,510,518,000 |
This question is very similar to Is there a standard command that always exits with a failure?
I'm writing some code which I need to test that it handles subprocesses gracefully when the child process exits due to a signal (say SIGTERM or SIGINT).
Is there something concise that I can call like true or false to achiev... |
Ok :-)
The script you want looks like this:
#! /bin/sh
kill $$
This relies on the fact that kill is a builtin command, and not the /bin/kill program.
| Is there a standard command that always exits with a signal? |
1,658,510,518,000 |
I have two pipe delimited file like below
file1.txt
A1234|JESSIE|OPTED
A1224|JOHN|OPTED
L1212|RAMSAY|OPTED
L1832|TIZEN|TESTED
file2.txt
A1234|B1465
G1211|L1211
G1241|L1212
G1271|L1232
Desired output
A1234|B1465
G1241|L1212
I am trying to compare column 1 and column 2 in file2.txt with column 1 in file1.txt and get ... |
$ awk -F '|' 'NR==FNR{a[$1]; next} ($1 in a) || ($2 in a)' file1.txt file2.txt
A1234|B1465
G1241|L1212
| Compare two files and get the matching rows based on two columns |
1,658,510,518,000 |
I am trying to delete all zip files from a folder /mnt/drive1/temp and its subfolders recursivley.
I am aware that an incorrect command here could have disastrous consequences so wanted to check I had the right format, so far I have...
find /mnt/drive/temp -type f -name '*.zip' -delete
Will this command achieve what ... |
If you omit the -delete option, find will print out a list of all files that match the test conditions you have specified. This is great way to check that you have caught the right files, especially before you delete them. Once you're sure that the files are the right ones, append the -delete option and run the comman... | Delete all zip files from a folder recursivley |
1,658,510,518,000 |
I have a logfile that is generating hundreds of lines per second – say, 12 specific lines, 16× per sec.
I want to run either a command-line or a shell script that can display this logfile neatly in real-time. But if I run tail -f logfile.txt, the text rapidly scrolls off the terminal window and can't be read by human... |
You can view the last N lines at a M second interval using watch. Assuming N=20 and M=3,
watch -n3 tail -n20 logfile.txt
Obviously you'll lose great chunks of output as the update interval exceeds the write interval, but as far as I understand it this is what you want.
| How to 'tail' a logfile, X lines at a time |
1,658,510,518,000 |
Recently, I opened terminal and started typing everything i can, after which i accidentally put " and something like python shell was initialised:
muhammadrasul@AMR:~/Desktop$ lksdflaflakd;kfa;lk"
> a
> s
>
> fd
> sfs
> fs
>
Then I realised that it works just for " as well. So, what that environment actually is and... |
" starts a string. The string lasts until the next " (except that \" put a " in the string and doesn't end the string). The string can contain newlines. So after entering a single ", the shell keeps reading input, because the string is unfinished.
When you terminate the string with another ", the shell will start exec... | What does " command do in terminal? [duplicate] |
1,658,510,518,000 |
How to get a listing of all occurences of the folder foo (or node_modules in my case) in my home folder, like this:
~/a/foo
~/b/d/foo
~/b/d/e/foo
...
My goal is to manually remove all unnecessary node_modules folder from my hard disk which has very limited space.
|
You could use find command:
find ~ -type d -name node_modules
To exclude nested node_modules directories, use -prune on the folders that are found to stop find from descending into them:
find ~ -type d -name node_modules -prune
And then, to delete:
find ~ -type d -name node_modules -prune -exec rm -rf {} +
| List given folder everywhere it exists |
1,658,510,518,000 |
There are multiple versions of g++ packages in the default Ubuntu repositories. I already know that the package names of the packages that I am searching for all start with g++-, but searching for these packages with apt-cache search g++- returns many unhelpful search results that don't start with g++- because the g++... |
Anchoring and escaping the special character + like in a regular expression works:
# apt-cache search '^g\+\+-'
g++-7 - GNU C++ compiler
g++-7-multilib - GNU C++ compiler (multilib support)
g++-aarch64-linux-gnu - GNU C++ compiler for the arm64 architecture
...
(A visual scan didn't show any packages that didn't begi... | Search for packages from Ubuntu repositories whose names start with g++- |
1,658,510,518,000 |
I have many images and each image has little watermark at the bottom, I want to remove that by cropping the images in bulk. Here is an image that shows what I want to do. How to do that in bulk using the command line tools?
|
Cropping images using command line tools mentioned in the comments is a good initial reference, but it lacks this very convenient variation with percentages in Width x Height, which is just what you need.
convert -crop 100%x100%+0-20 original.png cropped.png
Of course, substitute 20 with your actual x value of vertic... | How to remove some pixels with respect to bottom in multiple images. [crop] |
1,658,510,518,000 |
In the example bellow:
function zp () {
zparseopts -E -walk:=o_walk
echo "walk: $o_walk"
}
I get the following output:
$ zp --walk "Walking"
walk : --walk Walking
$ zp --walk
zp:zparseopts:2: missing argument for option: -walk
walk :
Here the argument of the option is mandatory so I am ... |
I don't know exactly about zparseopts, but I think getopt doesn't have that and I only see references to mandatory arguments in the manual for zparseopts.
You can always just check manually if the resulting option is set:
function zp () {
if ! zparseopts -E -walk:=o_walk; then
return 1
fi
if [ $#o_... | How do I make an option (not argument of the option) mandatory in zparseopts? |
1,658,510,518,000 |
Show character at position in a file
The above page shows how to use dd to print the nth char in a file. Is there a way to print a file starting from the nth char? Thanks.
|
You could use tail, for example, from the 5th character onwards:
tail -c +5 FILE
| How to print a file starting from the nth char? |
1,658,510,518,000 |
The command mid3v2 -l someFile.mp3
gives the following output for a file with name someFile.mp3 in mp3-format:
IDv2 tag info for someFile.mp3
APIC=cover front, (image/jpg, 52016 bytes)
TALB=someAlbumName
TCON=amusicGenre
TDRC=2000
TIT2=songname
TPE1=singer
TPE2=singer
TRCK=1
I would like to store the value of TPE1 t... |
There are many ways to answer this question.
The first step is to understand that the output of a command could be received by other commands via a pipe, or, could be captured in a variable:
cmd | next command ... etc
var=$(cmd)
The process to select a line and further select what is after the sign = is called "text... | Save the output of a command to a variable |
1,658,510,518,000 |
I have a data file which a part of it looks like this:
4 1
5 2
1 2
3 1
1 1
1 2
1 1
1 1
2 1
2 1
I want to count similar rows and put my counts in a third column like this:
4 1 1
5 2 1
1 2 2
3 1 1
1 1 3
2 1 2
Any suggestion please?
|
Using Miller:
$ mlr --nidx uniq -g 1,2 -c file
4 1 1
5 2 1
1 2 2
3 1 1
1 1 3
2 1 2
or, equivalently
mlr --nidx count-distinct -f 1,2 file
Unlike awk arrays or perl hashes, Miller appears to preserve the "seen order" of the keys - but I don't know if that's guaranteed.
| counting number of unique rows within 2 columns |
1,658,510,518,000 |
I use the following command to find a file and copy it somewhere else,
find /search/ -name file.txt -exec cp -Rp {} /destination \;
How can I copy all files and subdirectories in the parent directory of file.txt?
Example,
/search/test/sub
/search/test/sub2
/search/test/file.txt
/search/test/file.doc
They should be c... |
With -execdir (not a standard predicate, but often implemented), the given utility would execute in the directory where the file was found.
This means that you could do
find /search -name file.txt -execdir cp -Rp . /destination \;
Without -execdir:
find /search -name file.txt -exec sh -c 'cp -Rp "${1%/*}/." /destinat... | How to find a file and copy its directory? |
1,658,510,518,000 |
I am using Cygwin as Linux shell, I have following contents in my current working directory:
Files :
Abc.dat
123.dat
456.dat
Directories:
W_Abc_w
W_123_w
W_456_w
Now I want to copy files as below:
Abc.dat -> W_Abc_w
123.dat -> W_123_w
456.dat -> W_456_w
How to achieve this in a single line linux command? ... |
In one command (line):
cp Abc.dat W_Abc_w/; cp 123.dat W_123_w/; cp 456.dat W_456_w/
The trailing slashes are not required, but a habit to indicate that the intention is to put the file into a destination directory not as a new file.
As a generic loop with a pattern:
for f in ???.dat
do
[ -d W_"${f%.dat}"_w ] && cp... | Copy files such that individual files gets copied to the folder having file name as a string within complete folder name |
1,658,510,518,000 |
When I run the command head -n 445 /etc/snort/snort.conf | nl I expect lines 1-445 to be returned. However, only up to line 371 is returned:
[snip]
370 preprocessor dcerpc2_server: default, policy WinXP, \
371 detect [smb [139, 445], tcp 35, udp 135, rpc-over-http-server 593], \
What is happening?
|
The nl utility does not number blank lines by default (and you have blank lines in the input file).
| head not returning n lines |
1,658,510,518,000 |
What is the difference between cp fileA fileB and cp -- fileA fileB in Linux?
|
-- specifies the end of options. In your specific example this shouldn't make a difference but if you were using filename globbing such as: cp * fileB to find a file and you had a file in your directory named -R for example your command could potentially be:
cp -R dirA fileB
Which obviously wouldn't be the desired o... | Bash: what is the difference between `cp fileA fileB` and `cp -- fileA fileB` [duplicate] |
1,658,510,518,000 |
I'm trying to get my terminal to alert me with a simple bell once my domain registration has finished (is resolvable).
From watch --help:
Options:
-b, --beep beep if command has a non-zero exit
How can I invert this option, so it beeps if the command has a zero exit?
I also tried variations of the foll... |
Since watch runs the command with sh by default (-x says not to run with sh), you can invert the return code with !:
watch -b ! nslookup foo.bar
Depending on your shell and config, you may need to quote !.
| How to invert 'watch -b'? |
1,658,510,518,000 |
I'm trying to create a simple script that uses a list of months like this:
(Jan Feb)
To generate and execute this command:
python ExpenseManager.py -p Inputs/Jan\ 2019\ Debit.CSV Inputs/Jan\
2019\ Credit.CSV -p Inputs/Feb\ 2019\ Debit.CSV Inputs/Feb\ 2019\
Credit.CSV
This is the program I've written to that e... |
Don't use echo to see what command is being executed. It prints the command after parsing, that is after quotes and escapes have been applied and removed); therefore, if the output of echo includes quotes and/or escapes like you'd expect to see in a raw command line (i.e. before parsing), it indicates that something i... | How to procedurally generate command in bash script using string interpolation with spaces? |
1,658,510,518,000 |
I'm looking for a tool for displaying inline menus in the shell which can be navigated with arrow-keys and enter. By "inline", I mean that the menu is displayed within the normal flow of stdout text, not in a pop-up dialog on top of everything.
I only found that post trying to address that, but it only mentions either... |
I used to use iselect for this, many years ago.
A very basic example:
$ sel="$(iselect -a 'foo' 'bar')"
$ echo $sel
foo
From man iselect:
iSelect is an interactive line selection tool for ASCII files,
operating via a full-screen Curses-based terminal session. It can be
used either as an user interface frontend... | Looking for command line package for showing inline text-based menu selector with arrow keys |
1,658,510,518,000 |
I have a mixed wordlist as an input:
azert12345
a1z2e3r4t5
a1z2e3r455
The command line I have tried to execute:
cat file.txt | grep -E "[[:digit:]]{5}" --color
What do I want to accomplish:
Print only these words: "azert12345" and "a1z2e3r4t5", using grep with a pattern like I said before. Something like grep -E "[[... |
IMHO this would be simpler in awk or perl, for the reasons outlined here: grep with logic operators (in particular, that there is no natural AND operator in grep). For example
awk 'gsub(/[a-z]/,"&") == 5 && gsub(/[0-9]/,"&") == 5' file
or
perl -ne 'print if tr/[a-z]// == 5 && tr/[0-9]// == 5' file
will print lines c... | output mixed alphanumeric input with grep,pipe and cat |
1,658,510,518,000 |
I have a tar file. That's what its structure looks like:
-images.tar.gz
-folder_0_image_1.jpg
-folder_0_image_2.jpg
-folder_0_image_3.png
-...
-folder_1
-folder_1_image_1.jpg
-folder_1_image_2.jpg
-...
-folder_2
-folder_2_image_1.jpg
-folder_2_image_2.jpg
-...
-f... |
You need to exclude files in subfolders like this:
tar --wildcards --exclude='*/*' -xvzf images.tar.gz '*.jpg'
Explanation:
--wildcards
means we specify files to extract by a wildcard, i.e. *.jpg - specified later
--exclude='*/*'
an option to exclude (from being selected for extraction) all entries with a / in the... | How can I extract files with specific extension from a tar file's root directory? |
1,658,510,518,000 |
System: Linux Mint 19.1 Tessa, edition: Cinnamon
Got a problem with a locate command. I created test.txt file on a desktop. After that I did:
sudo updatedb
However
locate test.txt -i
still doesn't show anything.
Permissions to mlocate.db: -rw-r----
Working on normal user, not root (that's why I was using sudo comm... |
The updatedb command will scan the filesystems on your system and create an index of the names of the available files and directories. This indexing is performed as a non-privileged user. This means that the index will only ever contain the names of files that are accessible by all the system's users.
Since your hom... | Locate doesn't work |
1,658,510,518,000 |
I have a table as below:
1 10 15
2 2 25
1 10 26
I like to merge them and make a new column in linux, like below:
1 10 15 1:10-15
2 2 25 2:2-25
1 10 26 1:10-26
|
Try this,
awk '{print $0" "$1":"$2"-"$3}' file
1 10 15 1:10-15
2 2 25 2:2-25
1 10 26 1:10-26
| how can I merge multiple column in one column and separated by '-'? |
1,658,510,518,000 |
I am looking for files, since I added a backup external HD. I want to continue working elsewhere, while find/grep/locate find a file. As a match is found, I'd like to be alerted so that i can stop the search, in case it was the one i intended to find.
Can there be an audible alert per match?
|
At least with GNU find, the -printf action supports a \a (terminal bell) escape char - so at its simplest you could do something like
find . -name foo -printf '\a' -print
I'm not aware of an equivalent with grep or locate.
| how can i make grep/find/locate beep as it finds each match |
1,658,510,518,000 |
When running the following command
tcpdump -i deviceName 'host 1.2.3.4' -q -w /mypath/dump.pcap
the dump file contains a huge amount of data because there's a lot of traffic. However, I only need to save the header details of each packet, not the entire contents. I tried using the -q switch (for "quiet") but that's ... |
I was in the same situation and I solved it by adding -s 96
| How to record only the header info when using `tcpdump` |
1,658,510,518,000 |
I have a hosted zone and record set that route to multiple addresses. I'd like to update the record set with adding or removing one IP address in the list. Unfortunately, AWS CLI doesn't provide the option of deleting/adding the value of resource record in route53
{
"Comment": "Update the A record set",
"C... |
Adding, using jq
$ jq '.Changes[0].ResourceRecordSet.ResourceRecords += [{"Value": "foobar"}]' file.json
{
"Comment": "Update the A record set",
"Changes": [
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "mydomain.com",
"Type": "A",
"TTL": 300,
"ResourceRecord... | Update file with multiple values automatically |
1,543,536,286,000 |
I install Ubuntu into a SSD drive and when I insert the SSD into different computer I have to change manually the disk number. I would like to get the home directory of all the disks until I found the one in the SSD.
In order to do that I need to know how to save the output of commands into variables (specially 'ls') ... |
You don't need to capture the output of ls, you need to look up the search command in grub.
Search devices by file ('-f', '--file'), filesystem label ('-l', '--label'), or filesystem UUID ('-u', '--fs-uuid').
Basically it allows you to search for your SSD either by some file present on the SSD or by filesystem label... | How can I get the 'ls' output to a variable in grub2? |
1,543,536,286,000 |
I recently did a fresh Ubuntu 18 install and copied over my home directory from my previous Ubuntu 16 setup. However this seems to have broken the copy paste functionality I had previously with xclip (0.12 installed).
My previous tmux.conf method:
setw -g mode-keys vi
bind -t vi-copy y copy-pipe "xclip -sel clip -i"
... |
As of tmux 2.6, bind-key no longer takes a mode-table option (-t). Instead, there is a a key-table (-T) for each mode.
Additionally, commands can't be used directly in copy-mode bindings. They have to be sent with send-keys -X.
From comments on tmux issue 754:
replace -t with -T
replace vi-<name> with <name>-mode-... | Ubuntu 18 Tmux 2.6-3 copy paste functionality with xclip non functional |
1,543,536,286,000 |
I am trying to open 2 separate windows/instances of emacs from the terminal in a single command. I have tried:
emacs &; emacs &
(error: bash:syntax error near unexpected token ; and
emacs & && emacs &
(error: bash:syntax error near unexpected token && but both ways produce errors. How can I produce in a single comma... |
You need only single separator between commands: ; or & or && etc, so try
emacs & emacs &
If you run emacs &; emacs & then you start emacs in the background, and then run ; without any command so bash claims it doesn't expect this separator there (syntax error near unexpected token ;).
Similar error you will get by j... | How to produce from the terminal in a single command 2 emacs windows? |
1,543,536,286,000 |
I need to search (on the whole disk) and replace (where there are matches) one file with another (both in the same path).
Example:
Folder 1
x*.txt (good) (e.g.: xFile.txt)
*.txt (bad) (e.g.: File.txt)
If there is a match of both files in the same path, i need to delete: *.txt (e.g.: File.txt) and rename: x... |
With GNU tools, you could do something like:
(export LC_ALL=C
find . -name '*.txt' -print0 |
sed -Ez 's|/x([^/]*)$|/\1|' |
sort -z |
uniq -zd |
sed -z 'h;s|.*/|&x|;G' |
xargs -r0n2 echo mv)
That assumes there are not files whose name starts with more than one x. For instance, it won't do mv ./xx.txt ./x.t... | replace files in the command line with specific string |
1,543,536,286,000 |
Assume my current path is /home/inp/Documents/Folder
I would like to copy folders /home/inp/Test1/randomName1 and /home/inp/Test1/randomName2 from my current path.
Currently, I use the following command:
cp ~/Test1/randomName1 ~/Test1/randomName2 .
Is it possible to combine randomName1 and randomName2 without using r... |
You can accomplish this with brace expansion:
cp ~Test1/{randomName1,randomName2} .
This will expand to each string in the braces:
$ echo Something{1,2,3,5}
Something1 Something2 Something3 Something5
or
cp ~Test1/randomName{1..2} .
This will expand to each number between the start and end, and can also be used wit... | How to copy several not-subfolders in one shot? |
1,543,536,286,000 |
I have a folder with ~10K XML files. Each of them looks like this:
...
<object>
<name>Cat</name>
</object>
<object>
<name>Cow</name>
</object>
...
The name includes person, cat, dog, cow, ... I want to pick out the only xml files with cat and/or dog. How can I do this?
|
To get all the Cat or Dog values out of the name node in an XML document like yours, you may use xmlstarlet like this:
xmlstarlet sel -t -v '//object/name[text() = "Cat" or text() = "Dog"]' file.xml
This would generate the words Cat and Dog as output if they exist the document as the values of an object node's name c... | Find XML files with specific values |
1,543,536,286,000 |
I don't understan why grep doesn't work in the first example
bla@ble:~/html/example$ grep -r "protected $disallowedBlockNames = array('install/end');" app/
bla@ble:~/html/example$
But
bla@ble:~/html/example$ grep -r 'protected $disallowedBlockNames = array' app/
app/Resource/Block.php: protected $disallowedBlockN... |
You didn't provide sample input but in your first example your double quotes are allowing the disallowedBlockNames variable to be expanded by your shell before it is used by grep. I'm assuming this is a variable set in your php code and does not exist in your shell and therefore it is expanding to nothing. So what y... | grep fails looking for string |
1,543,536,286,000 |
I was learning about Unix file system and learned about pipes. According to GeeksForGeeks,
A pipe holds the output of the first command till it has been read by the second program
So, I was thinking if I could link a C program and a Java Program so as to supply the output of the C code as the command line argument... |
What you want is possible and easy.
Just type
/your/java/program "$(/your/c/program)"
The $(…) notation is called “command substitution”.
$(command1)
runs command1 with output to a pipe,
captures it, and puts it on the command line.
Socommand2 $(command1) runs command2
with command1’s output
as a command-line argu... | Provide output of C program as command line input Java program? |
1,543,536,286,000 |
Say I have several directories of varying length in the form
/tmp/(1) I. First Majuscule Roman Numeral/01. First Arabic Numeral/a. First Grapheme
/tmp/(2) II. Second Majuscule/03. Third Arabic/d. Fourth
that I want to parse so the output is
I.01.a.
II.03.d.
What's the awk and/or sed solution?
|
Assuming those are tho only directories beneath /tmp:
$ find /tmp -mindepth 3 -type d -print | sed -e 's/\.[^/]*/./g' -e 's/^.* //' -e 's#/##g'
I.01.a.
II.03.d.
The find command finds the directories on level 3 and prints out their full path. The result of this step is
/tmp/(1) I. First Majuscule Roman Numeral/01. F... | awk or sed to Parse Elements from Directory Path |
1,543,536,286,000 |
I ran the following Bash function that adds a string with expanded variables, into the end of my bashrc:
alias() {
echo "alias $repo=\"$HOME\"/$repo/$repo.sh" >> "$HOME"/.bashrc
source "$HOME"/.bashrc 2>/dev/null
}
alias
To run it I copied it, pasted in the Bash terminal (there it appeared once) and executed ... |
You defined a function called alias, added a line to .bashrc that calls alias ..., and then sourced .bashrc into your shell (which has the function defined in it already). The alias you sourced calls the function, which adds another line and sources the script again, calling the function again once for each time it's ... | Bash function that creates an alias gets called endlessly |
1,543,536,286,000 |
I have a specific problem that has brought up some general questions.
The specific problem:
I have a sudoers rule applied to a group of somewhat restricted users. The rule in question is %pusers ALL=(ALL) NOPASSWD: /bin/vi /etc/httpd/conf/*. A user would like to cd /etc/httpd/conf and then sudo vi httpd.conf (or sudo... |
Giving regular user sudo access to an editor like vi or vim is risky. See this question for an in-depth explanation.
With a modern version of sudo, you could specify in your sudoers:
%pusers ALL=(ALL) sudoedit /etc/httpd/conf/*
Then, your users could specify their editor of choice using the VISUAL or EDITOR environme... | How do relative execution paths work through sudo |
1,543,536,286,000 |
If I create a file with sudo vim test and then open it up in my account (without sudo) why does the editor complain when I try to modify the file (i.e. read only option is set)?
According to ls -l I am the owner, and the owner has rwx
Why can't I write to the file?
|
If you create a file with sudo vim test the owner will be root, not you, so if later you want to edit the file you either need to change the owner from root to you or change the permissions.
See:
jordim@bucketlist-196008:~/test$ sudo vim test
jordim@bucketlist-196008:~/test$ ls -l
total 8
(...)
-rw-r--r-- 1 root roo... | If I own a file, why do I need to change permission to write to it? |
1,543,536,286,000 |
I was was using gpg --gen-key till I got to enter the passphrase where I get:
┌──────────────────────────────────────────────────────┐
│ Please enter Passphrase, │
│ │
│ Passphrase: ________________________________________ │
│ ... |
With the cursor in the PIN entry area, pressing Enter will activate the “OK” button.
Pressing Tab will highlight the “OK” button and then the “Cancel” button; pressing Enter with a button hightlighted will activate that button.
| how to navigate with pinentry |
1,543,536,286,000 |
I have a csv file in the following format:
0.25,20171225,20:00
3,20171226,23:59
3.5,20171231,00:01
1.75,20180108,05:43
How can I add a value to the first field in the last line from the command line?
So if I wanted to add 1.25 the file would look like this:
0.25,20171225,20:00
3,20171226,23:59
3.5,20171231,00:01
3,20... |
Here's awk solution:
awk -F, -v OFS=, 'l{print l}{l=$0}END{$1+=1.25;print}' file
The idea is to print previous line instead of the current one.
-F, and -v OFS=, set the input and output field separator
l{print l} prints variable l only if it is not zero (numeric) or empty (string) -- that prevents printing first lin... | Add value to a number in the last line of a csv file |
1,543,536,286,000 |
I wish to backup with duplicity (I use it often, usually without issues) /etc and /root. I wish to exclude .cache from the /root directory. I try:
duplicity incremental --full-if-older-than 30W --include /etc \
--include /root --exclude '/root/.cache' --exclude / \
--verbosity info / scp://TARGET
This generally w... |
Tilia,
order matters when excluding in duplicity. the parameters are used in the order given. in your example '/root/.cache' is compared to
--include /etc
--include /root <-- and matches here
--exclude '/root/.cache'
--exclude /
try to move the specific exclusion in front of the more general include eg.
--include /et... | Unable to exclude .cache from duplicity backup |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.