nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Find files whose pathnames end in "config"
find . -path '*/*config'
display the top 20 biggest files in the current folder which are present in the same partition as that of the current folder
find . -xdev -printf ‘%s %p\n’ |sort -nr|head -20
find all files that do not have read permission to all
find . -type f ! -perm -444
Read a line from standard input with prompt "Enter your choice: ", arrow keys enabled, and "yes" as the default input, and save the response to variable "choice"
read -e -i "yes" -p "Enter your choice: " choice
Find files/directories under current directory without descending into it
find -prune
Search the files under and below /directory/containing/files for "text to search"
find /directory/containing/files -type f -print0 | xargs -0 grep "text to search"
Return the files that are newer than file `myfile'
find / -newer myfile
Send SIGHUP signal to nginx master process, causing it to re-read its configuration and restart child processes if necessary.
kill -HUP $
Find files ending in "*macs"
find -name '*macs'
Make directory "foo" and do not cause an error if it exists
mkdir -p foo
find all files that have been used more than two days since their status was last changed
find -used +2
Find all files under current directory and print them appending a null character at the end of each file paths
find . -type f -print0
List root's regular files with permissions 4000
find / -type f -user root -perm -4000 -exec ls -l {} \;
Search the current user's home directory and below for all .png files and copy those files in the directory imagesdir.
find ~/ -name *.png -exec cp {} imagesdir \;
Find all regular files under $DIR directory tree with ".$TYPE" extension where $TYPE expands in the current shell
find $DIR -type f -iname "*.$TYPE"
display the name and size of all the regular/normal files in the var/log folder which are bigger than 100MB
find /var/log -type f -size +100000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
Display file status for all regular files in the current directory tree
find . -type f -exec stat {} + > /dev/null
Find all files/directories whose names start with 'readme' under '/usr/share/doc' directory tree
find /usr/share/doc -iname readme\*
look for the largest 200 files over 1,000,000 bytes in the filesystem mounted at "/usr/pcapps"
find /usr/pcapps/ -mount -type f -size +1000000c | perl -lpe ' s{ }{\\ }g ' | xargs ls -l | sort +4nr | head -200
Log in as "middleuser" with key "./middle_id.pem" and forward port 22 on host "middle.example.org" to port 2222 on localhost
ssh -i ./middle_id.pem -R 22:localhost:2222 [email protected]
Find all symlinks under current directory
find ./ -type l
Set the environment variable "DISPLAY" to the system host name followed by ":0 skype"
DISPLAY=`hostname`:0 skype
display all the files in the file system excluding all the ".c" files
find / \! -name "*.c" -print
find all directories in the current directory which have the name foo and do not have the extension "bar"
find . -name '*foo*' ! -name '*.bar' -type d -print
Gets IP addresses of all network interfaces.
ifconfig | grep -E "{3}[0-9]{1,3}" | grep -v 127.0.0.1 | awk '{ print $2 }' | cut -f2 -d:
Search the current directory tree for regular .mkv files
find . -type f -name "*.mkv"
Search for files which have read and write permission for their owner and group, and which other users can read, without regard to the presence of any extra permission bits
find . -perm -664
Print IP addresses of the host name
hostname -i
find all the files that have been changed today
find . -ctime 0 -type f
Print either "one" or "two" randomly three times
yes $'one\ntwo' | head -10 | nl | sort -R | cut -f2- | head -3
remove all the permissions for others to all the files in the current folder which have read,write,execute access to users,group and others.
find * -perm 777 -exec chmod 770 {} \;
find all the core files in the temp folder and force delete them
find /tmp -name core -type f -print | xargs /bin/rm -f
Find all *.ogg files under the home directory ignoring the case
find $HOME -iname '*.ogg'
Get the directory with least access time under current directory
find . -type d -printf "%A@ %p\n" | sort -n | tail -n 1 | cut -d " " -f 2-
Remove regular files changed more than 15 days ago from the /tmp directory tree
find /tmp/ -ctime +15 -type f -exec rm {} \;
Find all files on the system that have been modified in the last 10 minutes
find / -mmin -10
Format the filename and modification time of files starting with t as a table on OSX
stat -f 'File: %N Modified: %t%Sm' t* |column -t
Find all files matching pattern '.#*' in the current directory tree and execute "foobar" for each of them with the file name as an argument
find . -iname '.#*' -print | while read -r i; do foobar "$i"; done
Reverse the space separated words in "35 53 102 342"
echo 35 53 102 342|tr ' ' '\n'|tac|tr '\n' ' '
Prints long listing of directories '/tmp', '/tnt' themselves bordered with '<--' and '--->'.
ls -ld /tmp /tnt | sed 's/^.*$/<-- & --->/'
search for all the files which have not been modified in the last 6 months (180 days) in current folder and display the disk usage of them
find . -mtime +180 -exec du -sh {} \;
sort and display top 11 files along with the last access date for all the files in the file system ( sort based on the timestamp )
find / -type f -printf "\n%AD %AT %p" | head -n 11 | sort -k1.8n -k1.1nr -k1
Return the list of files named "filename" that are 50 megabytes or larger
find / -size +50M -iname "filename"
Find all Subscription.java files/directories under current directory and enter into the parent directory of the first one found
cd $(find . -name Subscription.java -printf '%h\n')
Apply script 'script.ksh' to all files matching pattern 'image\*.jpg' under the directory tree 'dir'
find dir -name image\*.jpg -exec /bin/ksh script.ksh {} \;
Force create a symbolic link without dereferencing named "mylink" to "dir2"
ln -nsf dir2 mylink
Create script filesPermissions.sh that restores the original permissions of the regular files in the current directory tree
find . -type f |xargs ls -la| awk '{print "chmod "$1" "$NF}'>./filesPermissions.sh
Print the file system disk space usage for "/dev/disk0s2" if exists
df | grep /dev/disk0s2
Print a list of all duplicate case insensitive filenames in the current directory tree
find . -type f | awk -F/ '{print $NF}' | sort -f | uniq -i -d
Find all files named 'foo' under current directory tree without descending into directories named 'foo'
find . -name foo -type d -prune -o -name foo -print
Change permissions to 644 for all files in the current directory tree
find . -type f | xargs chmod -v 644
Find all regular files under current directory tree that were accessed $FTIME days ago
find . -type f -atime $FTIME
Search the current directory recursively for files last modified within the past 24 hours ignoring .swp files and paths ./es* and ./en*
find . -mtime 0 -not \
Find all .sh files in the current directory tree and remove them
find . -name "*.sh" -exec rm -rf '{}' \
Print numbers from 1 to 10 with 2 values per line
seq 10 | awk 'NR%2{printf; next}1'
Remove all *.mp3 files in tmp directory but not in it's subdirectories
rm `find tmp -maxdepth 1 -name '*.mp3'`
Print and split the output of "my_program" into files of at most 100000 bytes each and use numeric suffixes
my_program | tee >
Recursively changes group ownership of everything in 'files' to 'my_group'.
chgrp -R my_group files
Count all the lines of all '*.c' files in current directory recursively
find . -name "*.c" -print0 | xargs -0 cat | wc -l
Mount the "vboxsf" filesystem "D:\share_folder_vm" on "\share_folder"
sudo mount -t vboxsf D:\share_folder_vm \share_folder
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]'
Print the first line of output after alphabetically sorting the file "set"
head -1 <
Remove all empty regular files under the current directory and below
find ./ -type f -size 0c -print | xargs rm
Fetch 'stackoverflow.com' domain IP addresses from dig DNS lookup
dig stackoverflow.com | grep -e "^[^;]" | tr -s " \t" " " | cut -d" " -f5
List all *.jpg files/directories in entire file system
find / -name "*.jpg" -print
Find all *.txt files/directories under your home directory
find ~/ -name '*.txt'
display the number of lines in all the ".c" files in the current folder
find . -name "*.c" -exec wc -l {} \;
Search the .VER files from the current directory tree for string "Test_Version='
find . -name "*.VER" -exec grep 'Test_Version=' '{}' ';' -print;
list files in the directory "$directory" with permissions "$permissions"
find "$directory" -perm "$permissions"
Delete all the files found in the current directory tree whose names begin with "heapdump"
find . -name heapdump* -exec rm {} \ ;
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 {} \;
Find all the files/directories in the current directory tree which have been modified between 2014-08-25 and 2014-08-26
find ./ -newermt 2014-08-25 ! -newermt 2014-08-26 -print
Search for the case insensitive pattern 'search for me' in all files with '.p', '.w' and '.i' extension under current directory tree without descending into '.svn' and 'pdv' directories
find . \( \ -type d -prune \) -o \
find all regular/normal files in the current folder
find -type f
Gets IP address of 'eth0' network interface.
ifconfig eth0 | grep inet | cut -d: -f2 | cut -d' ' -f1
Prints top ten of most memory using processes in system.
ps aux | awk '{print $2, $4, $11}' | sort -k2rn | head -n 10
List all .jpg files in the home directory tree in a fast way
find . -name "*.jpg" -exec ls {} +
Close the master SSH control socket "my-ctrl-socket" to "[email protected]"
ssh -S my-ctrl-socket -O exit [email protected]
Unzip every ".gz" file in the current directory tree
find . -name '*.gz' -exec gunzip '{}' \;
Show directory sizes in KB and sort to give the largest at the end
find . -type d -exec du -sk {} \; | sort -n -k 1
find all the normal files in the home directory which have been accesed in the last 30 days with the size greater than or equal to 100k.
find $HOME -type f -atime +30 -size 100k
Look for "testfile.txt" in the "/" directory and 1 level below
find / -maxdepth 2 -name testfile.txt
Write output and error of "command" to standard output and to "/path/to/logfile"
command 2>&1 | tee /path/to/logfile
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"
Determine if /full/path exists on a mounted file system.
df /full/path | grep -q /full/path
Find all regular files named 'Waldo' under 'Books' directory tree that is located in user's home directory
find ~/Books -type f -name Waldo
Find all $2 files in $1 path excluding /proc and search for the regex expanded by $3 in those files
find $1 -path /proc -prune -o -name "$2" -print -exec grep -Hn "$3" {} \;
Find all directories in maximum 1 level down the $front_element directory, sort them according to modification time and list them excluding the $front_element path from the list
find "$front_element" -maxdepth 1 -type d -not -path "$front_element" -printf '%T@ %p\n' | sort | awk '{print $2}'
List all files that are between 10000 and 32000 bytes in size
find . -size +10000c -size -32000c -print
Remount "/dev/shm" with a maximum size of "40G"
mount -o remount,size=40G /dev/shm
Use the output of "ping google.com" as input to awk script "packet_loss.awk"
ping google.com | awk -f packet_loss.awk
Append *.java files from the current directory tree to tar archive `myfile.tar'
find . -type f -name "*.java" | xargs tar rvf myfile.tar
Enables shell options 'extglob' and 'progcomp'
shopt -s extglob progcomp
Find all files with the SUID bit set, starting from /
find / -perm -u+s
Search for "whatever" in all files under /dir directory ensuring white space safety in filenames
find /dir -type f -print0 | xargs -0i cat {} | grep whatever
find all the files in the present directory which have the group staff and check if is a symbolic link and display it.
find `pwd` -group staff -exec find {} -type l -print ;
display list of all the hidden regular/normal files in the directory "/dir/to/search/"
find /dir/to/search/ -type f -iname ".*" -ls
Starts new detached tmux session and runs command $CMD within.
tmux new -d "bash -c \"$CMD\""
find md5sum of 'string to be hashed'
echo 'string to be hashed' | md5
Extract the second-to-last slash-separated path component, ie. "90_2a5" in this case.
echo 'test/90_2a5/Windows' | xargs dirname | xargs basename