nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
display all the files in the current folder
find . | awk '{ print "FILE:" $0 }'
Find all files/directories under '/usr' directory tree that have not been modified in the last 356 days counting days from today
find /usr -mtime +356 -daystart
Search /some/directory for files that are owned by the user "joebob"
find /some/directory -user joebob -print
Find all directories named 'mydir' under 'local' and '/tmp' directory tree
find local /tmp -name mydir -type d -print
Search all *.txt files under ~/documents for the word "DOGS"
find ~/documents -type f -name '*.txt' -exec grep -s DOGS {} \; -print
Find every file under the directory /home owned by the user joe.
find /home -user joe
display all files in the folder /usr/src excluding those ending with ",v"
find /usr/src ! \ '{}' \; -print
Display top 500 mp4 and flv files under current directory along with their timestamps in the sorted order of time
find . -regex ".*\.\" -type f -printf '%T+ %p\n' | sort | head -n 500
Give all directories in the /path/to/base/dir tree read and execute privileges
find /path/to/base/dir -type d -exec chmod 755 {} +
remove all core dump files from user's home directory
find ~/ -name 'core*' -exec rm {} \;
Kill all processes which were executed in background by the current shell.
jobs -p | xargs kill -9
Print a line of 99 '=' characters
seq -s= 100|tr -d '[:digit:]'
Find all files starting from the current directory that contain '.java' in their pathnames
find . -print | grep '\.java'
Find all files under ./lib/app and sort them, then print their contents to myFile
find ./lib/app -type f | sort | xargs awk 'ENDFILE {print ""} {print}' > myFile
Find all files more than 700 megabytes
find / -size +700M
Save the directory name of the canonical path to the current script in variable "MY_DIR"
MY_DIR=$(dirname $)
find all normal/regular files in current folder and display the total lines in them
find . -type f -print0 | xargs -0 wc -l
Copy all *.mp3 files under the current directory to /tmp/MusicFiles/
find . -type f -name "*.mp3" -exec cp {} /tmp/MusicFiles \;
Dump the character output of 'echo `echo "Ho ho ho"`'
echo `echo "Ho ho ho"` | od -c
Find *.conf files/directories only upto 1 level down under /etc directory and show a few lines of output from the end
find /etc -maxdepth 1 -name "*.conf" | tail
Find all files/directories named $something under current directory
find -name "$something"
Find all files/directories named 'FindCommandExamples.txt' that belong to the user 'root' in the entire filesystem
find / -user root -name FindCommandExamples.txt
Search the current directory recursively for regular files last modified less than 2 days ago
find . type -f -mtime -2
find all the regular/normal files in the folder /travelphotos which are bigger than 200KB and which do not have the word "2015" in their name
find /travelphotos -type f -size +200k -not -iname "*2015*"
Get the disk space used by all *.txt files under /home/d directory
find /home/d -type f -name "*.txt" -printf "%s\n" | awk '{s+=$0}END{print "total: "s" bytes"}'
Search all files in the current directory tree whose names contain "." for "SearchString"
find . -name '*.*' -exec grep 'SearchString' {} /dev/null \;
remove all the ".core" files in the file system
find / -name "*.core" | xargs rm
Update the timestamp of 'filename', or create an empty file if it doesn't exist.
touch filename
Print a count of each unique line from standard input sorted from least frequent to most frequent
sort | uniq -c | sort -n
display all files in the entire file system excluding the directories /proc,/sys,/dev and those files which are writable and which are not symbolic links and which are not sockets and which do not have the sticky bit set
find / -noleaf -wholename '/proc' -prune -o -wholename '/sys' -prune -o -wholename '/dev' -prune -o -perm -2 ! -type l ! -type s ! \( -type d -perm -1000 \) -print
Find all files in the /home/ directory tree that were last modified less than 7 days ago
find /home -mtime -7
save all aliases to the variable $oldalias
oldalias=$;
display all the files in the home folder
find $HOME -print
display all mp3 files in the file system which have not been accessed in the last 24 hours
find / -name “*.mp3” -atime +01 -type f
Continuously send "Yes" plus newline to the program "./ittp-update.sh"
yes Yes | ./ittp-update.sh
archive all files in a current directory modified in the last 30 days
tar czvf mytarfile.tgz `find . -mtime -30`
Delete all .svn files/directories under current directory
find . -name .svn -exec rm -v {} \;
find files in /tmp directory that named are core and deletes them, single or double quotes, spaces or newlines are correctly handled
find /tmp -name core -type f -print0 | xargs -0 /bin/rm -f
find all text files in current folder and display all files that have the alphabet a in their name
find . -name ".txt" | grep a
Delete all files/directories with inode number 117672808 under current directory tree
find -inum 117672808 -exec rm {} \;
Prints calendar of April of 2012, and redirects output to 't' file and 'more' pager tool.
cal April 2012 | tee t | more
Search the current directory recursively for regular files modified 2 days ago
find . type -f -mtime 2
find all PDFs owned by user “seamstress”
find / -user seamstress -iname “*.pdf”
Greps domain $domain IP name from long dig listing.
dig $domain | grep $domain | grep -v ';' | awk '{ print $5 }'
Creates temporary file in a current folder with name formatted like 'templateXXXXXX', and saves path to it in 'tempfile' variable.
tempfile=$(mktemp $/templateXXXXXX)
Find recursively all regular files in the current directory whose names contain "."
find . -type f -a -name '*.*'
create directory log into home directory
mkdir ~/log
Remove trailing whitespaces from all regular non-hidden files in the current directory tree
find . -type f -name '*' -exec sed --in-place 's/[[:space:]]\+$//' {} \+
find all the text files in the current folder
find . -type f -name '*.txt' -print
Make hidden directory ".hiddendir"
mkdir .hiddendir
Represent time string $MOD_DATE as seconds since epoch and save to variable 'MOD_DATE1'
MOD_DATE1=$(date -d "$MOD_DATE" +%s)
Remove all directories in and below the current directory
find \! -name . -type d -print0 | xargs -0 rmdir
find all the files ending with "rb" and display the first 10000 lines from these files.
find . -name "*rb" -print0 | xargs -0 head -10000
Give the location of every hard link to file1 in the /home directory tree
find /home -xdev -samefile file1 | xargs ls -l
search all files in the current folder which match the regular expression
find . -regex ".*/my.*p.$" -a -not -regex ".*test.*"
Display 'file.txt' all occurrences of "foo" replaced by "bar", letting the user interactively page through the result.
cat file.txt | perl -ne 's/foo/bar/g;' | less
Print whether the unique contents of "set1" and "set2" differ
diff -q <(sort set1 | uniq) <(sort set2 | uniq)
Add execute permission to all files ending in ".sh"
chmod +x *.sh
Change permissions of directory "/home/sshtunnel/" to 555
chmod 555 /home/sshtunnel/
Print DISPLAY of "orschiro" user
who | awk -F '[]' '/orschiro/{print $}' | grep -v orschiro | uniq
Save long listing of all files listed in file 'filenames.txt' to 'listing' variable
listing=$(ls -l $(cat filenames.txt))
display the version of find
find --version
find all the files in the current directory which end with orig
find . -name '*.orig' -exec echo {} \ ;
Recursively changes group ownership on every file in the ${WP_ROOT}/wp-content directory to ${WS_GROUP} group.
find ${WP_ROOT}/wp-content -exec chgrp ${WS_GROUP} {} \;
Search the directory given as variable $d for empty subdirectories
find "$d" -mindepth 1 -prune -empty
Recursively removes all files and folders named '.svn' in a current folder, handling content of removed folder before folder inself.
find . -depth -name .svn -exec rm -fr {} \;
Create intermediate directories as required and directory project/{lib/ext,bin,src,doc/{html,info,pdf},demo/stat/a}
mkdir -p project/{lib/ext,bin,src,doc/{html,info,pdf},demo/stat/a}
Convert the content of variable 'CLEAN' to small letters
CLEAN=`echo -n $CLEAN | tr A-Z a-z`
Find all files/directories with '.in' extension in the directory $directory and its subdirectories
du -a $directory | awk '{print $2}' | grep '\.in$'
Find recursively all regular files in the current directory tree not ending in .dll or .exe
find . -type f | grep -vP "\.dll$|\.exe$"
Filter the contents of 'file' through sed commands written in 'commandfile', displaying the result.
sed -f commandfile file
display all the files in the directory modules
find . -name modules
Find all files/directories named 'vimrc' in the entire filesystem
find / -name vimrc
display all the directories in the current folder excluding those that are present in the aa directory tree
find . -type d -name aa -prune
Find all files/directories named 'fprintf.c' under '/usr/src' directory tree
find /usr/src -name fprintf.c
Filters only directories from long file listing of a current directory, and prints their names.
ls -l | grep "^d" | awk -F" " '{print $9}'
Print numbers from 1 to 30 with a leading 0
seq -w 30
Enables shell option 'lastpipe'.
shopt -s lastpipe
Make directory "/etc/cron.5minute"
mkdir /etc/cron.5minute
find files which full path name like '*f' at current directory and print
find . -path '*f'
Print all group names known to the system.
getent group | cut -d: -f1
forcibly and verbosely create a symbolic link named "target" to file "source"
ln -sfvn source target
Find all the files on the system that have been changed within the last hour
find / -cmin -60
Print the files in the current directory as a list of comma separated values
ls -1 | tr '\n' ',' | sed 's/,$/\n/'
Save a comma separated list of all $MY_DIRECTORY/*/ directories to variable 'FOLDER'
FOLDERS=`ls -dm $MY_DIRECTORY/*/ | tr -d ' '`
Count the number of equal lines in "file1.txt" and "file2.txt"
comm -12 < < | wc -l
Finds all files like "mylog*.log" newer than $2 and archives them with bzip2.
find . -type f -ctime -$2 -name "mylog*.log" | xargs bzip2
find all the text files in the folder /tmp/1 and display only those files which have spaces in their names
find "/tmp/1/" -iname "*.txt" | sed 's/[0-9A-Za-z]*\.txt//g
Get virtual private memory use of process
top -l 1 -s 0 -i 1 -stats vprvt -pid PID
find all files in the current folder which have not been modified today and whose file name is of length 1
find . -name \? -mtime +0
Display differences between /tmp/test1 and /tmp/test2 side-by-side.
diff -y /tmp/test1 /tmp/test2
Find files/directories named 'somename.txt' under current directory tree
find ./ -name "somename.txt"
Find all *.mp4 files under /working
find /working -type f -name '*.mp4'
Generates temporary file name with full path by template 'fifo.XXXXXX' and saves it to variable 'fifo_name'
fifo_name=$
Find directories that are directly under /home/user/workspace directory (no-subdirectories) and were modified more than 30 days ago and print a message saying that the directory wasn't modified during last 30 days
find /home/user/workspace -mindepth 1 -maxdepth 1 -type d -mtime +30 -execdir echo "It seems that {} wasn't modified during last 30 days" ';'
Remove all regular files from the current directory tree that were modified a day ago
find . -type f -mtime 1 -exec rm {} +
Compress and display the gzip compression ratio 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 -v {} \;
Display the contents of "file" formatted into a table, removing duplicate lines where the first 12 characters are duplicates, and display the number of occurrences at the beginning of each line.
column -t file | uniq -w12 -c
Uses the time utility to report only real execution time of 'ls' command.
/usr/bin/time -f%e ls >/dev/null
Open gcc info manual and select "option index" menu entry.
info gcc "option index"