nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Create a symbolc link named "public_html" to "current/app/webroot" under the current working directory
ln -s `pwd`/current/app/webroot public_html
delete all the php files in the folder /var/www
find /var/www/*.php -type f -exec rm {} \;
Prints path to folder that contains file "/path/to/vm.vmwarevm/vm.vmx".
echo /path/to/vm.vmwarevm/vm.vmx | xargs dirname
Find all directories under /path whose names are 33 characters long
find /path -type d -printf "%f\n" | awk 'length==33'
Look for files that have SUID or SGID set
find / -perm +6000 -type f
Remove regular files changed more than 15 days ago from the /tmp directory tree
find /tmp/ -ctime +15 -type f -exec rm {} \;
Find and delete all core files in the user's home directory and below.
find ~/ -name 'core*' -exec rm {} \
List all files/directories with spaces in their names under ~/Library directory
find ~/Library -name '* *' -exec ls {} \;
Search for 'DOGS' in all files with '.txt' extension under ~/documents and also print the file names
find ~/documents -type f -name '*.txt' -exec grep -s DOGS {} \; -print
Get the total size of all files under dir1 directory
find dir1 ! -type d -printf "%s\n" | awk '{sum += $1} END{printf "%f\n", sum}'
display all the files in the current folder which have been modified in the last 5*24 hours
find . -mtime -5
Find the top level directories that contain a 'bin' directory in it or in one of it's sub-directories and print a sorted list to file b
find . -type d -name bin | cut -d/ -f1,2 | sort > b
Print list of all user names who are logged in
who | awk '{ print $1 }'
Find files/directories in entire file system that have been modified in the last minute
find / -mmin -1
Search for files that were accessed less than 5 days ago.
find -atime -5
Runs 'mpv' command for each *.mpv and *.flv file in a current folder.
mpv --no-audio \`ls ~/Down/other/*.{mp4,flv} --color=never\`
get all files in a current directory modified in the last day and a half
find . -mtime -1.5 | xargs tar --no-recursion -czf myfile.tgz
Find recursively the latest modified file in the current directory
find . -type f -print0 | xargs -0 stat -f "%m %N" | sort -rn | head -1 | cut -f2- -d" "
List all regular files residing in the current directory tree and containing string "/bin/ksh"
find . -type f -print | xargs grep -li 'bin/ksh'
Change permissions to 644 for all regular files under and below /path/to/someDirectory/
find /path/to/someDirectory -type f -print0 | xargs -0 sudo chmod 644
Find all build* directories under /var/www/html/ and reverse sort them
find /var/www/html/ -type d -name "build*" | sort -r
Replace the occurrences of "HOGE" with "MOGA" once per each line of the files from the current directory tree, keeping a backup copy of every touched file
find . -type f -print0 | xargs -0 sed -i.bak -e "s/HOGE/MOGA/"
Find all files under $dir
find $dir -type f
Search the /mnt/raid/upload directory tree for files that have been modified within the last 7 days
find /mnt/raid/upload -mtime -7 -print
Find all broken symlinks under current directory
find -L . -type l
find the oldest normal file in the current directory
find . -type f -print0 | xargs -0 ls -ltr | head -n 1
Delete the oldest file with '.tgz' or '.gz' extension under '/home/backups' directory tree
ls -tr $(find /home/backups -name '*.gz' -o -name '*.tgz')|head -1|xargs rm -f
Send email in "mail.tmp" from "noreply@hostname" with subject "Config done!"
cat mail.tmp | mail -r "noreply@$" -s "Config done!" "${MAIL}"
find all the files in the current directory which have been accessed in the last 1 day and move them to TMP folder.
find . -atime +1 -type f -exec mv {} TMP \;
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 the files whose name is tecmint.txt and contains both capital and small letters in /home directory
find /home -iname tecmint.txt
Archive the list of 1st level subdirectories in /fss/fin to /fss/fi/outfile.tar.gz
tar -czf /fss/fi/outfile.tar.gz `find /fss/fin -d 1 -type d -name "*" -print`
Find files with a question mark in their names
find . -name \*\\?\*
Search for all files with the same inode number 41525360
find . -follow -inum 41525360
Search all *.c files from the current directory tree for "hogehoge"
find . -name \*.c -print0 | xargs -0 grep hogehoge /dev/null
display all the files in the current folder excluding those which are present in "./src/emacs" folder
find . -path './src/emacs' -prune -o -print
Find all .java files whose name contains "Message"
find . -print | grep '.*Message.*\.java'
Count the total number of lines in all HTML files under /usr/src that contain string "foo"
find /usr/src -name "*.html" -execdir /usr/bin/grep -H "foo" {} ';' | wc -l
resize all the jpg images in the current folder to the size 300x300
find . -iname '*.jpg' -print0 | xargs -I{} -0 -r convert -resize 300x300 {} $outdir/{}
List all files/directories under $dir_name with size $sizeFile and print them according to the format string '%M %n %u %g %s %Tb %Td %Tk:%TM %p\n'
find $dir_name -size $sizeFile -printf '%M %n %u %g %s %Tb %Td %Tk:%TM %p\n'
Counts lines in each *.php file.
wc -l $
set alias "vimrc" for command "$EDITOR ~/.vimrc"
alias vimrc='$EDITOR ~/.vimrc'
Change directory to the directory containing the "oracle" executable
cd $(dirname $)
Find all files/directories named 'apt' in the entrie filesystem
find / -name "apt"
List files/directories at least three levels down the directory tree
find / -mindepth 3 -name "*log"
Find files/directories under current directory that matches 'projects/insanewebproject' in their paths
find -ipath 'projects/insanewebproject'
Delete files older than 31 days
find ./ -mtime +31 -delete
find all files in current folder which are bigger than 1 MB and move them to another folder
find . -size +1M -exec mv {} files \+
Find all files in the /home/ directory tree that are owned by bob
find /home -user bob
Find all *.py files under current directory
find . -type f -name "*.py"
find all the backup files in the current folder and delete them
find . -type f -name "*.bak" -exec rm -f {} \;
Change permissions to 0755 for all directories in the /path directory tree
find /path -type d | xargs chmod 0755
Find all files/directories under $TARGET_DIR directory tree matching the posix extended regular expression \".*/$now.*\" (where $now is a variable) and save the output in file $FILE_LIST
find $TARGET_DIR -regextype posix-extended -regex \".*/$now.*\" -fprint $FILE_LIST
Search for all files not newer than file /tmp/t
find / -not -newer /tmp/t
Log into "[email protected]" using identity file "~/path/mykeypair.pem"
ssh -i ~/path/mykeypair.pem [email protected]
Exit the shell immediately if an error is encountered
set -o errexit
Create a variable CDATE in the current shell that contains the date in '%Y-%m-%d %H:%M:%S' format , and a variable EPOCH that contains the seconds since epoch
source <(date +"CDATE='%Y-%m-%d %H:%M:%S' EPOCH='%s'")
Find all files under current directory whose file type description contains "image", display only path to each file.
find . -type f -exec file {} \; | grep -o -P '^.+: \w+ image'
display long listing of all the files in the root folder which are bigger than 3KB
find / -dev -size +3000 -exec ls -l {} ;
Search for case insensitive pattern 'search for me' in all files that match the name pattern '*.[!r]*' under current directory tree
find . -name "*.[!r]*" -exec grep -i -l "search for me" {} \;
Remount "/system" as read only
mount -o remount,ro /system
display all the hidden files in the folder /home
find /home -name ".*"
Use metaflac to extract the artist field from myfile.flac, and set the variable ARTIST to the value of that field.
source <
Export variable "JAVA_HOME" as symlink resolved absolute path of the 2nd parent directory name of "java"
export JAVA_HOME=$(readlink -f $(dirname $(readlink -f $ ))/../)
Silently read a line into variable "passwd" with prompt "Enter your password: "
read -s -p "Enter your password: " passwd
Find all files residing in /home/dm/Video or below that were changed less than 7 days ago
find /home/dm/Video -mtime -7
Find files/directories in entire file system that have been modified in the last minute
find / -mmin -1
find all the backup files in the current folder and delete them
find . -type f -name "*.bak" -exec rm -f {} \;
Recursively removes all folders named '.svn' in a current folder.
find . -type d -name .svn -print0|xargs -0 rm -rf
Prints process tree of a process having id $ID with parent processes.
pstree -s $ID
Change directory to the basename of "$1" with ".tar.gz" removed
cd $
display a list of all the files in the file system which do not belong to any group and search only in jfs and jfs2 file systems
find / -nogroup \( -fstype jfs -o -fstype jfs2 \) -ls
Search directories called ' backup ' from /usr directory downwards and print them.
find /usr -type d -name backup -print
force delete all the files which have not been accessed in the last 240 hours in the temp folder
find /tmp/* -atime +10 -exec rm -f {} \;
Find all 1.txt, 2.txt and 3.txt files under current directory and change the permission to 444
find . \( -name 1.txt -o -name 2.txt -o -name 3.txt \) -print|xargs chmod 444
Save the user name in upper case of the current user in variable "v"
v=$
Find all regular files in the entire filesystem that belong to the group 'users'
find / -type f -group users
Recursively copy all files and folders in the current directory excluding "exclude_pattern" to "/to/where/"
rsync -r --verbose --exclude 'exclude_pattern' ./* /to/where/
search for multiple files in the current folder
find . -name photoA.jpg photoB.jpg photoC.jpg
Search the current directory tree for files whose name is ".note", case insensitive
find . -iname '.note' | sort -r
Count the number of files in the current directory and below
find . -type d -exec basename {} \; | wc –l
Remove all .txt files in and below the current directory
find . -name "*.txt" | xargs rm
Change permission to 000 of all directories named '.texturedata' under '/path/to/look/in/' directory tree
find /path/to/look/in/ -type d -name '.texturedata' -prune -print0 | xargs -0 chmod 000
find all files in the home folder that are modified in the last 7 days
find $HOME -mtime -7
Find regular files modified less than 14 days ago stripping ./ from each file name
find . -type f -mtime -14 | cut -b 3- > deploy.txt
Find all .svn directories under current directory and delete them
find . -type d -name ".svn" -print | parallel rm -rf
Find all directories in the current directory tree with "music_files" in their names
find . -type d -iname \*music_files\*
Report file system containing /example disk usage in kilobytes.
df -k /example
Gets MAC address of p2p0 network interface.
ifconfig p2p0 | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'
Find all files/directories in directories/files taken from the glob pattern '/folder/path/*' recursively that have not been modified in the last 2 hours and delete them
find /folder/path/* -mmin +120 -delete
search for a word in all the files with the extension "ch" in the current folder
find -name '*.[ch]' | xargs grep -E 'expr'
Creates temporary folder in a $temp_dir folder with name pattern defined by $template, and stores path to created folder in 'my_temp' variable.
$ my_temp_dir=$(mktemp -d --tmpdir=$temp_dir -t $template)
Print the list of files in the home directory tree whose names begin with "Foto"
find ~ -name 'Foto*'
Search the bla directory recursively for *.so files
find bla -name "*.so"
Find all the files whose name is tecmint.txt in the current directory
find . -name tecmint.txt
Locate all .txt files in and below the current directory
find . -name "*.txt"
Recursively lists all *.py and *.html files in a current folder.
ls **/*.py **/*.html
Report file system containing the current directory disk usage in kilobytes.
df -k .
Print a count of each unique line in "ip_addresses.txt" sorted numerically
sort -n ip_addresses.txt | uniq -c
Search for occurrences of string "main(" in the .c files from the current directory tree
find . -name "*.c" -print | xargs grep "main("