nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Search for the extened regex 'expr' in all files with '.c' and '.h' extension under current directory tree
find . -name '*.[ch]' | xargs grep -E 'expr'
search for the directory "config" in the current folder
find . -name config -type d
find all pdf files in the current folder
find . -name “*.pdf” -print
Find all files named "test2" in the current directory tree
find -name test2
find for the word "dba_2pc_pending" in all the files of current fodler having the word "sql" in their name
find . -print|grep sql|xargs grep -i dba_2pc_pending
find the file "dateiname" in the current folder
find -iname "Dateiname"
Display the last slash-separated part of each filename path in file.txt
rev file.txt | cut -d/ -f1 | rev
Remove all files in and below the current directory whose names begin with "not"
find . -name not\* -print0 | xargs -0 rm
Recursively removes all files named '.svn' in a current folder, and prints messages on each action.
find . -name .svn -exec rm -v {} \;
Find all *text files/directories under current directory
find -name "*text"
Search all .c and .h files in the current directory tree for string "e"
find . -name "*.[ch]" -exec grep --color -aHn "e" {} \;
Display last 100 lines of file-with-line-too-long.txt, waiting for user input after each page.
tail -1000 file-with-line-too-long.txt | more
Find recursively all regular files in the current directory tree ending in .dll or .exe
find . -type f | grep -P "\.dll$|\.exe$"
Copy "source" recursively to "destination" excluding "path1/to/exclude" and "path2/to/exclude"
rsync -av --exclude='path1/to/exclude' --exclude='path2/to/exclude' source destination
Find all the files in the current directory with “linkin park” in their names
find . -maxdepth 1 -iname "*linkin park*"
Find all *.txt files under /foo and delete them
find /foo -name "*.txt" -delete
delete all the mp3 files in the current folder.
find . -type f -name "*.mp3" -exec rm -f {} \;
display all the text files in the home folder
find /home -name "*.txt"
Get domain name from dig reverse lookup.
$dig -x 8.8.8.8 | grep PTR | grep -o google.*
Find all files in the current directory recursively with "linkin park" in their names and copy them to /Users/tommye/Desktop/LP
find . -type f -iname "*linkin park*" -exec cp -r {} /Users/tommye/Desktop/LP \;
find ".flac" files in current folder using regular expressions
find ./ -regex "./cmn-.\.flac"
Print the files in the current directory as a list of comma separated values
ls | sed '$!s/$/,/' | tr -d '\n'
Search for all files in the /home directory tree that have the same inode number
find /home -xdev -inum 2655341
Log into "[email protected]" using identity file "~/path/mykeypair.pem"
ssh -i ~/path/mykeypair.pem [email protected]
search for directories in the folder "test" which end have 5 digits as their name
find ./test -type d -name '[0-9][0-9][0-9][0-9][0-9]'
Search directory tree `MyApp.app' for directories whose name is 'Headers' and delete them
find MyApp.app -name Headers -type d -exec rm -rf "{}" \;
Sort all directory names matching folder_* and go to the last one.
cd $
display the count of all the directories in the current folder
find . -type d –print | wc -l
find all the text files in the folder /home/calvin which are atleast below 2 levels
find /home/calvin/ -mindepth 2 -name “*.txt”
Find and uncompress all files in the current directory tree ending in ".csv.gz"
find . -name '*.csv.gz' -exec gzip -d {} \;
find all the php files in the current folder
find . -name \*.php -type f
Gets back to the foreground a job with number 2.
fg 2
Find all files/directories named orm.properties under current directory
find . -name "orm.properties"
Read a line from standard input into variable "i" with the prompt " Again? Y/n "
read -p " Again? Y/n " i
Find all files/directories named 'filename' that belong to user 'username' and group 'groupname' in the entire filesystem
find / -user username -group groupname -name filename
List all symlinks under current directory and search for targetfile.txt in this list
find . -type l | xargs -I % ls -l % | grep targetfile.txt
Archive "/path/to/copy" to "/path/to/local/storage" on host "host.remoted.from" as user "user" updating files with different checksums, showing human readable progress and statistics, and compressing data during transmission
rsync -chavzP --stats /path/to/copy [email protected]:/path/to/local/storage
Find all files/directories named 'photoA.jpg' under current directory tree
find . -name photoA.jpg
display all text files in current folder
find . -name "*.txt"
Find files/directories named 'sar' under directory trees whose path starts with '/u' or '/b' or '/s' or '/o'
find `ls -d /[ubso]*` -name sar
Find files that are 0 bytes in size in the current directory tree and remove them
find . -size 0 -exec rm {} \;
Convert all DOS files under and below the current directory to the Unix format
find . -type f -exec dos2unix {} {} \;
Find files in entire file system that are writable by group or other
find / -perm /g+w,o+w
Calculate the md5 sum of the contents of "$FILES"
cat $FILES | md5sum
Read a line from standard input with prompt "Continue (y/n)?" and save response in variable "CONT"
read -p "Continue (y/n)?" CONT
Removes 'folderName', and removes all content within if 'folderName' is folder.
rm -rf folderName
Recursively unzip files to stdout in "/some/dir/here" and search for "blah"
zcat -r /some/dir/here | grep "blah"
Find files/directories in entire file system that had their meta information changed more than 3 days ago
find / -ctime +3
Executes 'cd /' in a subshell created by a pipeline of built-in function 'true'.
true | cd /
Find all files/directories that are owned by user 'takuya' under current directory tree
find -user takuya
List all files except for those in directory SCCS
find . -print -o -name SCCS -prune
Saves 'ls' output to 'ls_results' file and time report to 'time_results' file.
> ls_results 2> time_results
Find all files/directories in level 2 down the current directory
find -mindepth 2 -maxdepth 2
Display differences between directories dir1 and dir2.
diff -r dir1/ dir2/
Search the regular files of the current directory tree for string "stuff"
find . -type f -exec grep -n "stuff" {} \; -print
Dump all MySQL databases over an ssh tunnel to "[email protected]" and use it as input to mysql
mysqldump --all-databases | ssh [email protected] mysql
find all the files in the current directory whose size is equal to exactly 126MB.
find . -size 126M
display all text files in the folder /home/you which have been modified in the last 60*24 hours(case insensitive search)
find /home/you -iname "*.txt" -mtime -60 -print
Make 999 folders one inside another where first 998 of them is named as "folderX" where X goes from 1 to 998 and the last folder named as "folder9991000"
mkdir -p folder$( seq -s "/folder" 999 )1000
long list al the files in the current directory which have only read permission to the group
find . -perm 040 -type f -exec ls -l {} \;
Print the directory name of the real full path of "relative/path/to/file" where each symbolic link component must exist
dirname `readlink -e relative/path/to/file`
display all the configuration files in the current folder which are in the current tree structure
find . -path '*/*config'
display all soft links in current folder
find . -type l
Execute the SSH command and kill it after 5 seconds
timeout 5 ssh user@ip
Print the second line of output of "ls -l"
ls -l | head -2 | tail -1
list all the directories in the folder httpdocs
find httpdocs -type d
Count number of A records of domain '$domain' on nameserver '$server' and save value in 'result' variable
result="$"
List all *.txt files in <path> with details about their attributes
find <path> -xdev -type f -name *.txt -exec ls -l {} \;
Print the last space separated word from "a b c d e"
echo "a b c d e" | tr ' ' '\n' | tail -1
find all the php/javascript files in current folder using regular expressions
find . -regex '.+\.\(php|js\)'
Search /public/html/cosi for files whose name is "wiki.phtml"
find /public/html/cosi -name "wiki.phtml"
search for jpg images in folders in the path "cam2/2013" and convert these files to the video Cam2-2013-30fps-19crf.mp4
find Cam2/2013* -name "*.jpg" -print0 | xargs -0 cat | ffmpeg -f image2pipe -framerate 30 -vcodec mjpeg -i - -vcodec libx264 -profile:v baseline -level 3.0 -movflags +faststart -crf 19 -pix_fmt yuv420p -r 30 "Cam2-2013-30fps-19crf.mp4"
find all files under the /etc/sysconfig directory that were accessed in the last 30 minutes
find /etc/sysconfig -amin -30
Finds shell options like 'checkjobs' with their state.
shopt -p | grep checkjobs
Display permissions, user, group, and full path for each file in the current directory tree as a list
tree -p -u -g -f -i
Display the current directory tree except files or directories starting with "3rd"
tree -I '3rd*'
Delete all files named "filename" in the current directory tree, except the one with path ./path/to/filename
find . -name "filename" -and -not -path "./path/to/filename" -delete
Split standard input into files with at most 75 lines each
split --lines=75
find all the files which have been modified in the last 15 minutes excluding hidden files.
find . -mmin -15 \
Search for 'foo=' in all *.png files under current directory without descending into *.gif and *.svn directories
find . -name "*.png" -prune -o -name "*.gif" -prune -o -name "*.svn" -prune -o -print0 | xargs -0 -I FILES grep -IR "foo=" FILES
Get a list of all hidden files from the current directory tree
find . -type f -name '.*'
delete all text files in the entire file system
find / -type f -name "*.txt" -print | xargs rm
Find all symbolic links under '/some/directory' tree
find /some/directory -type l -print
Copy the executable "python2.7" in $PATH to "myenv/bin/python"
cp `which python2.7` myenv/bin/python
Change permissions to 644 for all subdirectories
find . -type d -print0|xargs -0 chmod 644
Subtract all columns in "File2" from "File1" except the first
awk 'FNR==NR { for(i=2;i<=NF;i++) a[$1][i]=$i; next } { for(j=2;j<=NF;j++) $j-=a[$1][j] }1' File2 File1 | rev | column -t | rev
Execute "elinks -dump file.html" every 2 seconds
watch elinks -dump file.html
Report file system containing path to /some/dir disk usage in kilobytes.
df -k /some/dir
Finds the folder where temporary files would be written to.
dirname $(mktemp -u -t tmp.XXXXXXXXXX)
create a compressed archive of a target directory excluding '<dir1>' and '<dir2>'
tar cfvz --exclude='<dir1>' --exclude='<dir2>' target.tgz target_dir
Recursively search for all regular files below directory "dir1" in currentd directory, and output the name of each, without any containing directories.
find ./dir1 -type f -exec basename {} \;
convert all the regular/normal files in the current folder from dos to unix format
find . -name "*" -type f -exec dos2unix {} \;
Save the canonical path of "$dir/$file" in variable "path"
path=`readlink --canonicalize "$dir/$file"`
List all files 2 levels deep in the current directory tree
tree -L 2 -fi
Find all directories whose name is root in / directory
find / -type d -name root
display list of all the files in the current folder which are empty.
find . -size 0 -ls
Find List directory with sub-folder count .
find -maxdepth 1 -type d | sort | while read -r dir; do n=$; let n--; printf "%4d : %s\n" $n "$dir"; done
Display cumulative CPU usage over 5 seconds.
top -b -d 5 -n 2 | awk '$1 == "PID" {block_num++; next} block_num == 2 {sum += $9;} END {print sum}'
change the permissions of all the directories to 755 in the folder "/home/nobody/public_html"
find /home/nobody/public_html -type d -exec chmod 755 {} \;
Calculate md5 checksum of '/etc/localtime' and save the first space separated part in variable 'checksum'
checksum=`md5sum /etc/localtime | cut -d' ' -f1`