nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
List environment variables whose name contains "X"
set | grep -oP '^\w*(?==)' | grep X
Find all files on the system that are world writeable
find / -perm -0002
Find all directories named "0" in the current directory tree and create a tar archive of their RS* subdirectories
find . -type d -name "0" -execdir tar -cvf filename.tar RS* \;
Set permission of "file" to read only for the owner
chmod 600 file
search for pattern matched files in the current folder and subfolders exclude "excluded path"
find ./ -type f -name "pattern" ! -path "excluded path" ! -path "excluded path"
Mount the "vboxsf" filesystem "D:\share_folder_vm" on "\share_folder"
sudo mount -t vboxsf D:\share_folder_vm \share_folder
Find all regular files under /home/www and replace every occurrences of 'subdomainA.example.com' with 'subdomainB.example.com' in those files
find /home/www -type f -print0 | xargs -0 sed -i 's/subdomainA\.example\.com/subdomainB.example.com/g'
find all files in the current folder which have been modified after /etc/passwd
find -newer /etc/passwd
Append *.java files from the current directory tree to tar archive `myfile.tar'
find . -type f -name "*.java" | xargs tar rvf myfile.tar
force delete all the regular files with the name "test.txt"
find /home -type f -name test.txt -exec rm -f {} \
Display infinite scroll of random ASCII art
yes 'printf \\u$[2571+RANDOM%2]'|bash
Automatically spell check file "text.txt" using "ispell" command and log the output to "out.txt"
yes 0 | script -c 'ispell text.txt' out.txt
Write summary of files present only in dir1, and which files differ between dir1 and dir2 to file 'difference1.txt'
diff -r dir1 dir2 | grep dir1 | awk '{print $4}' > difference1.txt
Find files which are more than 2 days old under ${userdir}/${i}/incoming directory and remove them
find ${userdir}/${i}/incoming -mtime +2 -type f -exec rm {} \;
Search the current directory tree for *.conf and *.txt files
find . -type f \( -name "*.conf" -or -name "*.txt" \) -print
Keep the last 4 ASCII characters of a string.
echo "0a.00.1 usb controller some text device 4dc9" | rev | cut -b1-4 | rev
Find all *.tex files/directories in maximum 2 levels down the current directory
find . -maxdepth 2 -name '*.tex'
Set permissions for all regular files under /var/www to 755
find /var/www -type f -print0 | xargs -0 chmod 644
Find all *.csv files under /foo/bar and move them to some_dir
find /foot/bar/ -name '*.csv' -print0 | xargs -0 mv -t some_dir
Uses GNU tool 'time' to estimate time consumed by command 'command' and redirects output to file
\time -o time.log command
Find all files/directories under current directory that are greater than 10MB in size
find . -size +10M
display a long ilsting of all the files in the file system which are bigger than 1KB and which have not been modified in the last 30*24 hours
find / -size +1000 -mtime +30 -exec ls -l {} \;
Gets list of IP addresses of all network interfaces.
ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'
Set variable "filename" to only the name of document specified by URL, in this case "pic.jpg"
filename="`basename "http://pics.sitename.com/images/191211/pic.jpg"`"
Move all files from the `sourceDir' directory to the `destDir' directory
find sourceDir -mindepth 1 -maxdepth 1 -print0 | xargs -0 mv --target-directory=destDir
Search the .css files in the /starting/directory tree for ".ExampleClass"
find /starting/directory -type f -name '*.css' | xargs -ti grep '\.ExampleClass' {}
find all the files in the entire file system that start with the word top and have 3 letters next to it.
find / -name 'top???'
display all regular/normal files in the folder Symfony
find Symfony -type f
Find all .sql files in the current directory recursively and print their path names separated by zeroes
find . -name '*.sql' -print0
Print lines in "file1.txt" that do not exist in "file2.txt"
sort <(sort -u file1.txt) file2.txt file2.txt | uniq -u
Locate files not owned by any user or group
find / -path /proc -prune -o -nouser -o -nogroup
find all the files in the current folder which are writable
find . -writable
Creates random file name formatted like expression in variable ${str// /X} and saves it in 'rand_str' variable.
rand_str=$(mktemp --dry-run ${str// /X})
Save the md5 sum hash of "$my_iso_file" to variable "md5"
md5=$
Dump "file" as ASCII characters
od -t c file
create a backup of all the files in the home folder on a partition and save the log to a file
find /home -depth -print | cpio -ov -0 /dev/rmt0 | tee -a tape.log
Recursively set all permissions under "/opt/lampp/htdocs" to 755
sudo chmod 755 -R /opt/lampp/htdocs
display all files in the current folder which end with extension "myfile" followed by one digit or two digits
find . -\( -name "myfile[0-9][0-9]" -o -name "myfile[0-9]" \)
Set 644 permission to all regular files under /path
find /path -type f -exec chmod 644 {} +;
Enables shell option 'nullglob'.
shopt -s execfail
Creates temporary file and saves path to it in 'fif2' variable.
fif2=$
Compress and display the original filename of every file on the system that is greater than 100000 bytes and ends in ".log"
sudo find / -xdev -type f -size +100000 -name "*.log" -exec gzip {} \; -exec echo {} \;
Remount part of the file hierarchy from "olddir" to "newdir"
mount --bind olddir newdir
Print every 4th line from 10 lines of "y" with line numbers
yes | cat -n | head -10 | awk 'NR % 4 == 1'
Search all directories starting from the root directory for "filename"
find / -iname "filename"
Write the standard output and error of "ls" to the console and append it to "/tmp/ls.txt"
ls 2>&1 | tee -a /tmp/ls.txt
Print the last 1000 lines of all files matching "/var/spool/cron/*"
tail -n 1000 /var/spool/cron/*
Read a line of standard input in an interactive shell
read -e
Remove all regular non-hidden files modified more than 7 days ago and residing in the /tmp directory tree
find /tmp -type f -name '*' -mtime +7 -print0 | xargs -0 rm -f
display a long listing of all the regular/normal files in the current folder along with their md5sum
find . -type f -exec sh -c 'printf "%s %s \n" "$" "$"' '' '{}' '{}' \;
prints the name of the current git branch
git status | head -1 | cut -d ' ' -f 3
Find all the SGID files in the current directory tree
find . -perm /g+s
Search directory /Users/david/Desktop/ recursively for regular files
find /Users/david/Desktop/ -type f
find all '*.c' files under $HOME directory which context contains sprintf
find $HOME -name '*.c' -print | xargs grep -l sprintf
find all the files starting with "config" in the folder Symfony
find Symfony -name '*config*';
Calculate md5 sum of the md5 sum of all the sorted files under $path
find "$path" -type f -print0 | sort -z | xargs -r0 md5sum | md5sum
Display all lines containing UTRACE in the current kernel's compile-time config file.
grep UTRACE /boot/config-$(uname -r)
Search for the files/directories that were modified more than an hour ago
find . -mtime +1
Print amount of space available on the file system containing path to the current working directory.
df $PWD | awk '/[0-9]%/{print $(NF-2)}'
Find all files in the level 6 subdirecotries of /usr/src and below, ignoring CVS files
find /usr/src -name CVS -prune -o -mindepth +6 -print
find all the files in the current folder and replace old string with new string
find . | xargs perl -p -i -e ‘s/something/else/g’
search for php files in current directory and search for a word in all these files
find -name '*.php' -exec grep -iq "fincken" {} \; -exec grep -iq "TODO" {} \; -print
Find all files/directories under current directory bypassing file hierarchies in lexicographical order
find -s
find foo, Foo, FOo, FOO, etc., but only dirs
find . -iname foo -type d
display all files ending with "ini" in current folder
find . -type f -name '*.ini'
Print the names and sizes of regular files residing in the "tmp" directory tree
find tmp -type f -printf "f %s %p\n" | awk '{sub(/^[^ ]+ +[^ ]/,sprintf)}1'
find all the configuration files in the file system
find / -name "*.conf"
find all files in the current folder that are not modified in the last 240 hours
find . -mtime +10 -print
Find all files/directories named file in minimum 4 levels down the current directory
find -mindepth 4 -name file
Find files which are more than 2 days old under ${userdir}/${i}/incoming directory
find ${userdir}/${i}/incoming -mtime +2 -type f -ls
Find all files/directories with name pattern $nombre that are at most 2 levels down the $DIR_TEMPORAL and $DIR_DESCARGA directories and show only the file names appended with '.torrent'
find "$DIR_TEMPORAL" "$DIR_DESCARGA" -maxdepth 2 -name "$nombre" -printf '%f.torrent\n'
search for the word "mysql" in all the files in the current containing the word "notes" in their name
find . -iname "*notes*" | xargs grep -i mysql
Find regular files named "expression -and expression" under and below /dir/to/search/
find /dir/to/search/ -type f -name 'expression -and expression' -print
Find all *.txt files of user Tecmint under /home directory
find /home -user tecmint -iname "*.txt"
Delete recursively empty files named 'bad'
find . -name bad -empty -delete
Remove files cart4, cart5, cart6 in directory ~/junk
find ~/junk -name 'cart[4-6]' -exec rm {} \;
find all regular files exclude .o and exclude *.swp and output line number of soc_attach if it has
find . \( ! -path "./output/*" \) -a \( -type f \) -a \( ! -name '*.o' \) -a \( ! -name '*.swp' \) | xargs grep -n soc_attach
find all the files in current directory of size exactly 6MB.
find . -size 6M
Execute awk script "script.awk" that exists in "$PATH" with argument "arg1"
awk -f `which script.awk` arg1
Display in an optimized way file status for all regular files in the current directory tree suppressing error messages
time find . -type f -exec stat {} + > /dev/null
display the number of lines in all the ".c" files in the current folder
find . -name "*.c" -print | xargs wc -l
display all the directories in the current folder which start with processor followed by digit and ends with .1 or .2
find . -type d -regextype posix-egrep -regex '\./processor[[:digit:]]*/10\.'
Find all *.p[lm] files under /users/tom directory that matches both the regex '->get(' and '#hyphenate' in their contents
find /users/tom -name '*.p[lm]' -exec grep -l -- '->get(' {} + | xargs grep -l '#hyphenate'
Print the sorted unique column of usernames of users who are currently logged in without the header
finger | cut -d ' ' -f1 | sort -u | grep -iv login
Search for files specifying the minimum depth of the search
find -mindepth num -name query
Find all *.coffee files under /some/path and run 'perl /path/to/your/program' with all of the file paths as its arguments
find /some/path -name '*.coffee' -print0 | xargs -0 perl /path/to/your/program
Find all files/directories under current directory following symlinks if needed
find -L
Find a 400 permission file under /data directory
find /data -type f -perm 400 -print -quit
change owner of the file process to user root
sudo chown root process
Find all files under current directory with their size and paths, reverse sort them numerically, then print the first 4 entries by removing all matches to the regex [0-9]+\s from each line of the output
find -type f -printf "%s %p\n" | sort -nr | head -n 4 | sed -r 's/[0-9]+\s//g'
Print all filenames in /usr/src except for those that are of the form '*,v' or '.*,v'
find /usr/src -not \( -name "*,v" -o -name ".*,v" \) '{}' \; -print
create an archive using pbzip2 as a compress program
tar -I pbzip2 -cf OUTPUT_FILE.tar.bz2 paths_to_archive
find all the files in the current directory and sub-directories whose status was changed after /etc/fstab was modified
find -cnewer /etc/fstab
Find all *stat files/directories under /usr
find /usr -name *stat
Recursively change the owner and group of all files in "/your/directory/to/fuel/" to "nginx"
chown nginx:nginx /your/directory/to/fuel/ -R
find all the files in the file system which have sticky bit enabled to the user
find / -perm -u+s
explicitly list all files in the current directory
find . -print
Find all files/directories in entire file system with 644 permission
find / -perm 644
Find files modified in the last 5 minutes starting from the current directory
find . -mmin -5
Print a detailed list of all files under and below the two directories given as variables $FULFILLMENT and $ARCH1
find $FULFILLMENT $ARCH1 -exec stat -c '%i,%b,%A,%h,%U,%G,%y,%n' {} \;