nl
stringlengths 13
387
| bash
stringlengths 1
532
|
|---|---|
Gets state of shell option 'dotglob' and saves it in 'rest_cmd' variable.
|
rest_cmd=$(shopt -p dotglob)
|
Gets string with IP4 address of en0 network interface.
|
ifconfig en0 | grep inet | grep -v inet6
|
Gets string with MAC address of eth0 network interface.
|
ifconfig eth0 | grep HWaddr
|
Gets string with MAC addess of network interface eth0.
|
ifconfig eth0 | grep HWaddr
|
Get the total size of all files under dir1 directory
|
find dir1 ! -type d |xargs wc -c |tail -1
|
get year-month-day from date
|
date +%Y-%m-%d
|
Give a long listing of all the *.pl files (Perl files) beneath the current directory.
|
find . -name "*.pl" -exec ls -ld {} \;
|
Give all directories in the /path/to/base/dir tree read and execute privileges
|
find /path/to/base/dir -type d -exec chmod 755 {} +
|
Give all directories in the /path/to/base/dir tree read and execute privileges
|
find /path/to/base/dir -type d -print0 | xargs -0 chmod 755
|
gives the chars in line 5 and chars 5 to 8 of line 5, in tst.txt
|
head -5 tst.txt | tail -1 |cut -c 5-8
|
Give the location of every hard link to file1 in the /home directory tree
|
find /home -xdev -samefile file1 | xargs ls -l
|
Gives the primary group of $USERNAME.
|
groups $USERNAME | cut -d\ -f 1
|
Give rwx permissions to the user and group of the directory named "files" leaving others without any privileges
|
find . -type d -name files -exec chmod ug=rwx,o= '{}' \;
|
Go back to last directory.
|
cd -
|
Go into the first directory whose name contains 1670
|
cd $(ls -d */ | grep 1670)
|
Go into the first directory whose name contains 1670
|
cd `find . -maxdepth 1 -type d | grep 1670`
|
Go into the first directory whose name contains 1670
|
cd `ls -d */ | grep 1670`
|
Go to /the/project/root//data, which in most filesystems/operating systems will be the same as cd /the/project/root/data
|
cd /the/project/root//data
|
Go to /tmp directory.
|
cd /tmp
|
Go to directory /cygdrive/c/Program Files (x86)/$dollarsign using single quotes to escape special characters, including dollar signs
|
cd '/cygdrive/c/Program Files (x86)/$dollarsign'
|
Go to directory /some/where/long
|
cd /some/where/long
|
Go to directory named "~" (not home directory)
|
cd "~"
|
Go to directory named "~" (not home directory)
|
cd `echo -n "~"`
|
Go to directory pointed by last element of array "dirs" in bash version 4.2
|
cd "${dirs[-1]}"
|
Go to first directory specified in PATH which contains the command 'oracle'
|
cd $(dirname $(which ls))
|
Go to first directory specified in PATH which contains the command 'oracle'
|
cd $(which oracle | xargs dirname)
|
Go to last directory with name starting with a number, useful for timestamped directory names.
|
cd "$(ls -rd [0-9]*/ | tail --lines 1)"
|
Go to previous working directory.
|
cd -
|
Grab the output of "basename" (in this case "stuff") and echo it to stdout, which basename would do by default anyway.
|
echo $(basename /foo/bar/stuff)
|
Grab the output of "basename" (the last slash-separated section of variable "filename") and echo it to stdout, which basename would do by default anyway.
|
echo `basename "$filename"`
|
grep for the last occurrence of text between two tags
|
tac a | grep -m1 -oP '(?<=tag>).*(?=</tag>)'
|
grep from bottom of file
|
tac your.log | grep stuff
|
Gunzip all files matching "file*.gz" and answer "n" to any prompts
|
yes n | gunzip file*.gz
|
Handles shell option 'nullglob' according with flags stored in $NGV variable.
|
shopt "$NGV" nullglob
|
Hash hostnames in user's known hosts file.
|
ssh-keygen -Hf ~/.ssh/known_hosts
|
Hunting down files with at least one banana
|
find . -type f -print0| xargs -0 grep -c banana| grep -v ":0$"
|
Identify CMS version/releases accross all your Drupal websites
|
find /home/*/public_html/ -type f -iwholename "*/modules/system/system.info" -exec grep -H "version = \"" {} \;
|
Identify CMS version/releases accross all your Drupal websites
|
find /var/www/vhosts/*/httpdocs/ -type f -iwholename "*/modules/system/system.info" -exec grep -H "version = \"" {} \;
|
Identify CMS version/releases accross all your PHPBB installations
|
find /home/*/public_html/ -type f -wholename *includes/constants.php -exec grep -H "PHPBB_VERSION" {} \;
|
Identify CMS version/releases accross all your PHPBB installations
|
find /var/www/vhosts/*/httpdocs/ -type f -wholename *includes/constants.php -exec grep -H "PHPBB_VERSION" {} \;
|
Identify CMS version/releases accross all your Wordpress websites
|
find /home/*/public_html/ -type f -iwholename "*/wp-includes/version.php" -exec grep -H "\$wp_version =" {} \;
|
Identify CMS version/releases accross all your Wordpress websites
|
find /var/www/vhosts/*/httpdocs/ -type f -iwholename "*/wp-includes/version.php" -exec grep -H "\$wp_version =" {} \;
|
Identify files that do not have a listing in the /etc/passwd or /etc/group file
|
find / -nouser -o -nogroup
|
If variable "c" is a syntactically correct cron job, erase user's cron jobs and add "c" as the only cron job for user.
|
echo $c | crontab
|
Infinitely ping every host listed in "file-of-ips" with at most 50 processes at once
|
cat file-of-ips | xargs -n 1 -I ^ -P 50 ping ^
|
Infinitely print "no" to the screen
|
yes no
|
Infinitely write "1" with line numbers to the console and "/tmp/to"
|
yes 1 | nl | tee /tmp/to
|
insert "e" when it's pressed
|
bind '"e":self-insert'
|
Instantly kill all processes whose command is 'myprocess'.
|
kill -9 \`pgrep myprocess\`
|
Interpret backslash sequences and delete whitespace characters in variable $FOO and save the result to variable 'FOO_NO_WHITESPACE'
|
FOO_NO_WHITESPACE="$(echo -e "${FOO}" | tr -d '[[:space:]]')"
|
Invoke a trusted X11 forwarding SSH connection with server "192.168.0.14" on port 222 as user "phil"
|
ssh -v -Y phil@192.168.0.14 -p 222
|
Invoke a trusted X11 forwarding SSH connection with the server $ssh_server as user $ssh_user
|
ssh -Y $ssh_user@$ssh_server
|
Join colon-separated information in 3 files LN.txt PH.txt and AD.txt in a cascade fashion: join LN.txt and PH.txt, then join the result with AD.txt
|
join -t':' <(sort LN.txt) <(sort PH.txt) | join -t':' - <(sort AD.txt)
|
Join comma-separated information in 4 files
|
join -t, <(sort test.1) <(sort test.2) | join -t, - <(sort test.3) | join -t, - <(sort test.4)
|
Join comma-separated information in 4 files - files must be sorted.
|
join -t, test.1 test.2 | join -t, - test.3 | join -t, - test.4
|
Join data in "file1" sorted by the second word of each line with data in "file2" sorted by the first word of each line, keeping the same order as it is found in "file1"
|
join -1 2 -2 1 <(sort +1 -2 file1) <(sort +0 -1 file2)
|
Join data in file1 containing one number per line with data in file2 containing a number and other information per line, keeping the same order as it is found in file1.
|
join -1 2 -2 1 -a1 <(cat -n file1.txt | sort -k2,2) <(sort file2.txt) | sort -k2 | cut --complement -d" " -f2
|
Join lines in file "A" with lines in file "B" if the lines share a common first word
|
join <(sort -n A) <(sort -n B)
|
Join lines in file "aa" with lines in file "bb" if the lines share a common first word
|
join <(sort aa) <(sort bb)
|
Join lines in file "aa" with lines in file "bb" if the lines share a common first word and sort the result numerically
|
join <(sort aa) <(sort bb) | sort -k1,1n
|
Join lines of 'file': fields 1 and 2 of lines discarding adjascent lines ignoring first 3 fields, with fields 3 to end of line discarding adjascent lines ignoring 3 last fields.
|
paste <(uniq -f3 file | cut -f1,2) <(tac file | uniq -f3 | tac | cut -f3-)
|
Join strings from 'file1' and 'file2', discarding excessive strings from largest file, and printing first, second and third space-separated field from first file, and third and fourth field from second file as a join result
|
join -o 1.2,1.3,2.4,2.5,1.4 <(cat -n file1) <(cat -n file2)
|
Just find directories and skip file names
|
find / -type d -name "apt" -ls
|
Keep the last 3 components (directories) of $path
|
echo $path | rev | cut -d'/' -f-3 | rev
|
Keep the last 4 ASCII characters (bytes) of a string.
|
echo "0a.00.1 usb controller some text device 4dc9" | rev | cut -b1-4 | rev
|
Keep only the last two hyphen-separated sections of "abc-def-ghi-jkl"
|
echo "abc-def-ghi-jkl" | rev | cut -d- -f-2 | rev
|
kill a number of background jobs
|
jobs -p | tail -n [number of jobs] | xargs kill
|
kill all active jobs
|
jobs -p | xargs kill -9
|
kill all background jobs
|
jobs -p | xargs kill
|
kill all background processes
|
kill -INT $(jobs -p)
|
kill all jobs
|
kill $(jobs -p)
|
Kill all processes which were executed in background by the current shell.
|
jobs -p | xargs kill -9
|
kill group leader
|
kill `jobs -lp`
|
Kill the processes of user `myuser' that have been working more than 7 days
|
find /proc -user myuser -maxdepth 1 -type d -mtime +7 -exec basename {} \; | xargs kill -9
|
Limits the number of results from grep to 2 lines
|
grep -o '1.' yourfile | head -n2
|
lines.txt contains a list of line numbers, one entry per line - output only these lines from text.txt omitting the rest of the file.
|
cat -n text.txt | join -o2.2 lines.txt -
|
List ".java" files that have the same contents
|
md5sum *.java | sort | uniq -d -w32
|
List ".java" files that have the same filename and contents
|
md5sum *.java | sort | uniq -d
|
Lists '/tmp/hashmap.$1' file or folder '/tmp/hashmap.$1' content one file per line.
|
ls -1 /tmp/hashmap.$1
|
list *.pdf, *.bmp and *.txt files under the /home/user/Desktop directory.
|
find /home/user/Desktop -name '*.pdf' -o -name '*.txt' -o -name '*.bmp'
|
list *.pdf files under the /home/user/Desktop directory.
|
find /home/user/Desktop -name '*.pdf'
|
List *.txt files residing in the current directory tree
|
find . -name *.txt -exec ls {} ;\
|
List *.txt files under current directory that have 'mystring' in their name
|
find . -name *.txt | egrep mystring
|
List .conf files residing in the /etc/nginx/ directory tree
|
find /etc/nginx -name '*.conf' -exec echo {} ;
|
List .html files in the current directory tree that contain string "base\-maps" but do NOT contain string "base\-maps\-bot"
|
find . -name "*.html" -exec grep -lR 'base\-maps' {} \; | xargs grep -L 'base\-maps\-bot'
|
List the 10 largest files or directories and their sizes under (and including) "/var"
|
du -a /var | sort -n -r | head -n 10
|
List absolute path of files in the current directory
|
ls -1 | xargs readlink -f
|
list all the ".ksh" files in the current directory
|
find . -ls -name "*.ksh"
|
List all *.bak files in the current directory tree
|
find . -name '*.bak' -ls
|
List all *.c, *.h and *.cpp files under current directory
|
find . -type f \( -name '*.c' -or -name '*.h' -or -name '*.cpp' \) -exec ls {} \;
|
List all *.c files in entire file system
|
find / \! -name "*.c" -print
|
List all *.gif files found in the current directory tree
|
find . -name *.gif -exec ls {} \;
|
List all *.jar files/directories under /usr, /home and /tmp directory
|
find /usr /home /tmp -name "*.jar"
|
List all *.java files/directories under /home/bluher with their full paths
|
find /home/bluher -name \*.java
|
list all *.java files under the src directory
|
find src -name "*.java"
|
List all *.jpg files/directories in entire file system
|
find / -name "*.jpg" -print
|
List all *.ogg files under your home directory along with their size
|
find $HOME -name '*.ogg' -type f -exec du -h '{}' \;
|
List all *.txt files/directories under /etc
|
find /etc -name "*.txt" -exec ls -l {} \;
|
List all *.txt files/directories under /etc
|
find /etc -name "*.txt" -ls
|
List all *.txt files/directories under /etc
|
find /etc -name "*.txt" | xargs -I {} ls -l {}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.