nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
find all the files in the current folder which have been accessed in the last 24 hours
find . -type f -atime 1
search for the file, filename.txt in the current folder
find . -iname filename.txt
Find files that have a modification time of a day ago
find / -mtime 1
Moves file '$2' to the folder where '$1' file is located.
mv "$2" "`dirname $1`"
Calculate the md5 sum of the contents of the sorted list of files "$FILES"
cat $(echo $FILES | sort) | md5sum
Get domain name with 'google' from dig reverse lookup.
dig -x 8.8.8.8| awk '/PTR[[:space:]]/ && /google/ {print $NF}'
find all files in current folder which are less than 300MB
find . -size -300M
List the files matching 'my key phrase' either in their names or contents
find | xargs -I {} bash -c '( || )'
Non-recursively finds all '*.pdf' files in a current folder and removes them.
find . -maxdepth 1 -name "*.pdf" -print0 | xargs -0 rm
Search for the string 'git' in all the files under current directory tree without traversing into '.git' folder and excluding files that have 'git' in their names
find . -path ./.git -prune -o -not -name '*git*' -print |grep git
find all the video files which are bigger than 10 MB which have not been modified in the last 60 days but have been changed in the last 100 days in /tmp and /var/tmp folder home folders
find /tmp /var/tmp ~ -type f -size +10M -mtime +60 -ctime -100 -exec file -N -i -- {} + | sed -n 's!: video/[^:]*$!!p'
find all files under the current directory, filtering the output through a regular expression to find any lines that contain the word foo or bar.
find ./ | grep -E 'foo|bar'
Recursively finds all files in root folder and prints all strings with 'text-to-find-here' from that files, ignoring binary files.
find / -type f -exec grep -l "text-to-find-here" {} \;
Gets IP address of 'en0' network interface.
ifconfig en0 | awk '/inet addr/{print substr($2,6)}'
Find and remove all .txt regular files under the current directory and below
find . -type f -name "*.txt" -exec rm -f {} \;
Look for file `Chapter1' under /usr and /home
find /usr /home -name Chapter1 -type f
search for a file in a directory and pass it as an input to the script getLine
find $dir -type f -name $1 -exec getLine {} \;
Find and delete the file with inode number 1316256
find ./ -inum 1316256 -delete
display the count of number of files in the current folder
find | wc -l
Find all read-only files
find / -perm /u=r
List all zero-length files
find . -empty -exec ls {} \;
Display all files in the current directory tree that match "*foo"
tree -P "*foo"
Count the number of differing lines in "file1" and "file2" with 0 lines of unified context
diff -U 0 file1 file2 | grep -v ^@ | wc -l
List each unique case insensitive character in "file" prefixed by number of occurrences and sorted from most frequent to least frequent
grep -o . filename | tr '[:upper:]' '[:lower:]' | sort | uniq -c | sort -nr
Find all files/directories under current directory and print them twice in each line
find | xargs -i sh -c "echo {} {}"
Redirects content of extracted file to a pipe
bunzip2 -c compressedfile.bz2 | yourfilterprogram
Copy all *.data files under /source_path to /target_path
find /source_path -name *.data -exec cp {} /target_path \;
find all files in the file system whose size is exactly 2KB
find / -size 2048c
Count the number of files in the directory trees whose pathnames match pattern '/dev/sd*[a-z]'
find /dev/sd*[a-z] | wc -l
Find all directories under current directory excluding those which match the regex /\. in their names
find . -type d | grep -v '/\.'
Find the top 5 small files
find . -type f -exec ls -s {} \; | sort -n | head -5
Display the last slash-separated part of each filename path in file.txt
rev file.txt | cut -d/ -f1 | rev
Recursively finds all files in a current folder excluding already compressed files and compresses them with level 9.
find . -type f | egrep -v '\.bz2' | xargs bzip2 -9 &
Show all values (without the names) of variables whose name or value contains "VARIABLE_NAME"
myVariable=$(env | grep VARIABLE_NAME | grep -oe '[^=]*$');
Remove all *.log files from the current directory tree
find -name '*.log' -delete
delete all the broken symbolic links from the folder /usr/ports/packages
find -L /usr/ports/packages -type l -exec rm -- {} +
Search for the literal string 'v$process' in all files under current directory
find . -print|xargs grep v\$process
Read a line from standard input into variable "prompt" with the prompt "Are you sure you want to continue? <y/N> "
read -p "Are you sure you want to continue? <y/N> " prompt
Find all regular files under '/usr/bin' directory tree that are less than 50 bytes in size
find /usr/bin -type f -size -50c
find all files in the current folder which have been modified in the last 24 hours
find . -mtime -1 -print
Recursively change owner to "www-data" of "/var/www/.gnome2", "/var/www/.config", and "/var/www/.config/inkscape"
chown -R www-data /var/www/.gnome2 /var/www/.config /var/www/.config/inkscape
search for all xml files in current folder and display the copy command to copy them to another folder
find . -name "*.xml" -exec sh -c 'echo "cp $0 someWhereElse/$0"' {} \;
Find all files that were modified later than ordinary_file in the current directory and its sub-directories.
find -newer ordinary_file
display all text files in current folder
find . -name ".txt"
Search directory foo for files containing "/tmp/foo/bar" in their full names
find foo -path /tmp/foo/bar -print
Display differences between /destination/dir/1 and /destination/dir/2 excluding files that match any pattern in file "exclude.pats".
diff /destination/dir/1 /destination/dir/2 -r -X exclude.pats
List jobs and their process ids and print them by replacing newline with '^'
joblist=$
Find all files that are exactly 50 bytes
find / -size 50c
find all files in the current folder that are not modified in the last 240 hours
find . -mtime +10 -print
Search the home directory tree for files modified less than a day ago
find $HOME -mtime -1
Clears terminal screen.
echo `clear`
Search the current directory tree for regular files changed on the 10th of September
find ./ -type f -ls |grep '10 Sep'
Remove all regular files with extensions php, css, ini, txt from directory tree /old/WordPress/
find /old/WordPress/ -type f -regex ".*\.\(php\|css\|ini\|txt\)" -exec rm {} \;
Search the files from the current directory tree for "foo"
find . -exec grep -l foo {} +
Print the current date in '%H:%M:%S' format followed by the string ': done waiting. both jobs terminated on their own or via timeout; resuming script'
echo "$: done waiting. both jobs terminated on their own or via timeout; resuming script"
Find all files in entire file system which are larger than 20000KB and show file name/path followed by its size
find / -type f -size +20000k -exec ls -lh {} \; | awk '{ print $8 ": " $5 }'
Locate all *.csv files under the current directory tree
find . -name "*.csv" -print
Opens gawk info manual and goes to command-line options node.
info -O gawk
SSH into "hostname" on port 22 as user "myName"
ssh -l myName -p 22 hostname
Append the current date to variable 'LBUFFER'
LBUFFER+="$(date)"
Make a directory in the current working directory with a random 32 alphanumeric character name
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1 | xargs mkdir
Search file aaa from current direcoty downwards and print it .
find . -name aaa -print
display all the regular files in the current folder that are bigger than 10KB
find . -type f -size +10k
Save the percentage of packets lost of the 5 packets sent to "$host" in variable "packet_loss"
packet_loss=$(ping -c 5 -q $host | grep -oP '\d+(?=% packet loss)')
Locate all files in the current directory and below that have "testfile" in their names
find -name "*testfile*"
Show the list of files larger than 100 MB
find / -size +100M -print
Redirects time output to file.
{ time find / 2>/dev/null; } 2>time.txt
Find all *.texi files in /usr/local/doc
find /usr/local/doc -name '*.texi'
Compares two listings 'ls' and 'ls *Music*', showing only strings that unique for first listing.
comm -23 <(ls) <(ls *Music*)
Show manual page of find utility
man find
Find all sample*_1.txt files/directories under current directory
find . -name "sample*_1.txt"
find any files or directories called ".svn" under the current directory and run a long list on each one, displaying a line count of the resultant output.
find . -iname .svn -exec bash -c 'ls -l "{}" | wc -l' \;
Find files that are writable by the user, the group, or both
find plsql -type f -perm /ug=rw -exec ls -l {} \; 2>/dev/null
print the line containing TERMINATE and everything after in 'file'
tail -n "+$(grep -n 'TERMINATE' file | head -n 1 | cut -d ":" -f 1)" file
Remount "extX" filesystem "/dev/hdaX" on "/" without writing in "/etc/mtab"
mount -n -o remount -t extX /dev/hdaX /
change the permission of all the php files in the folder /var/www/ to 700
find /var/www/ -type f -iname "*.php" -exec chmod 700 {} \;
Find files in and below the current directory whose names begin with "not" and remove one of them
find . -name not\* | tail -1 | xargs rm
List and remove all regular files named "core" under /prog that are larger than 500k
find /prog -type f -size +1000 -print -name core -exec rm {} \;
Save the system host name into variable "HOST"
HOST=$
Print position number of day '9' in fourth line of calendar output for September, 2009.
cal 09 2009 | awk 'NR==4{day="9"; col=index($0,day); print col }'
Check if a drive is mounted to nfs
mount |grep nfs
Print the last file extension from standard input
sed 's/^/./' | rev | cut -d. -f1 | rev
find all the files in the entire file system whose size is greater than 20MB
find / -type f -size +20000k
finds all files modified within a certain time frame recursively
find . -type f -newermt "2013-06-01" \! -newermt "2013-06-20"
find the count of all the regular files in a directory
find /usr -type f | wc -l
Find all /home/folder1/*.txt files and create symlinks appending '_CUSTOM_TEXT.txt' in their names
find /home/folder1/*.txt -type f | awk -F '.txt' '{printf "ln -s %s %s_CUSTOM_TEXT.txt\n", $0, $1}' | sh
Use the contents of compressed files "input1.txt.gz" and "input2.txt" as arguments to "command"
command $ $
find all the zip files in the current folder
find . -type f -name '*.zip'
Prints process tree for each process owned by user 'username'.
ps -aux | awk '/^username/{print $2}' | xargs pstree
Find regular files that are bigger than 500 MB in size under current directoryt tree
find . -type f -size +500M
Find all files that are set group ID to staff
find . -group staff -perm -2000 -print
find all the png files in current folder which are present in the pattern list file "search.txt"
find . -name '*.png' | grep -f <
Find all files/directories with 'my key phrase' in their names under current directory
find . -name '*my key phrase*'
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 ! \ -print
display all files expect directories in the current folder
find . ! — type d -print
Time stamp every ping request to 8.8.8.8 in Unix epoch format
ping -D -n -O -i1 -W1 8.8.8.8
Find all files/directories under current directory tree excluding files/directories with name 'query_to_avoid'
find -not -name "query_to_avoid"
Find all files in the `sourceDir' directory
find sourceDir -mindepth 1 -maxdepth 1
Counts lines in each *.cpp, *.c, *.h file.
wc -l `find . -type f \ -print`
find all files in the current directory which are bigger than 2MB
find -size +2M