nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Find all CDC* files under current directory that were accessed less than 1 day ago and delete the first and last lines from those files
find . -type f -name "CDC*" -ctime -1 -exec sed -i'' -e '1d' -e '$d' '{}' \;
Find all files that were last accessed more than 7 days ago under /home
find /home -atime +7
Find the largest original ".gz" file in the current directory tree
find . -name '*.gz' | xargs gzip -l | tail -n +2 | head -n -1 | sort -k 2 | tail -n 1 | awk '{print $NF}'
Finds all files like "mylog*.log" newer than $2 and archives them with bzip2.
find . -type f -ctime -$2 -name "mylog*.log" | xargs bzip2
Remove all files in the $backup_path directory recursively that were last modified more than 30 days ago
find $backup_path/* -mtime +30 -exec rm {} \;
compare each C header file in or below the current directory with the file /tmp/master
find . -name '*.h' -execdir diff -u '{}' /tmp/master ';'
Find all .jpg files in the current directory and below.
find . -name “*.jpg”
Find all files in /dir1 and print only the filenames
find ./dir1 -type f -exec basename {} \;
Prints groups list that user 'el' belongs to.
groups el //see that el is part of www-data
Search the current directory recursively for files containing "needle text"
find . -type f -print0 | xargs -0 grep -IZl . | xargs -0 grep "needle text"
find all files with pattern` '*.mp3'
find / -name *.mp3
Find all regular files in /usr/bin modified less than within the last 10 days
find /usr/bin -type f -mtime -10
Find all files/directories with '.log' extension that belong to the group 'adm' under '/var/log' directory tree
find /var/log -group adm -name "*.log"
get the jenkins user access
sudo su - jenkins
when using vi-insert keymap bind command "\C-v{}\ei" to key "{"
bind -m vi-insert '"{" "\C-v{}\ei"'
Find the string 'joomla' case insensitively in all the php and html files under current directory tree and display the matched lines along with the file names and line numbers
find . \ -print0 | xargs -0 grep -Hin "joomla"
search for all the files which have not been modified in the last 6 months (180 days) in current folder and display the total disk usage of them
find . -mtime +180 -exec du -ks {} \; | cut -f1 | awk '{total=total+$1}END{print total/1024}'
Search the current directory tree for directories
find "$PWD" -type d
calculate the disk usage for all the files which have been modified in the last 24 hours in ~/tmp folder and display the file sizes
find ~/tmp -mtime 0 -exec du -ks {} \; | cut -f1
Find all *.ext files/directories under current directory and print their path and parent directory path
find /path -type f -name "*.ext" -printf "%p:%h\n"
Find all files under /home/feeds/data without descending into *def/incoming* and *456/incoming* paths
find /home/feeds/data -type f -not -path "*def/incoming*" -not -path "*456/incoming*"
Print a line of 100 '=' characters
printf %100s |tr " " "="
Save 'foo' into variable 'bar' in ksh
echo foo | read bar
Remove all files with a txt extension under current directory
find . -type f -name "*.txt" | xargs -i ksh -c "echo deleting {}; rm {}"
Set the 'pipefail' shell variable causing bash to return true only if all commands in a pipeline return true.
set -o pipefail
display the count of all the files in the current folder
find . -print | wc -l
Compress all *.img files using bzip2
find ./ -name "*.img" -exec bzip2 -v {} \;
Find files/directories under /users/tom that matches both the pattern "*.pl" and "*.pm"
find /users/tom -name "*.pl" -name "*.pm"
Find all files/directories under current directory tree with '.old' extension
find . -name ”*.old” -print
Search for 'some string' in all *js files under current directory and show the matched lines with line numbers
find . -name '*js' | grep -n 'some string'
Move all files from the `sourceDir' directory tree to the `destDir' directory
find sourceDir -mindepth 1 -exec mv "{}" --target-directory=destDir \;
Find all files under current directory and print only the filenames
find . -type f -execdir echo '{}' ';'
Find all files whose names end with "macs" in and below the current directory
find -name '*macs'
Search the ~ and `Music' directory trees for .mp3 files
find ~ Music -name '*.mp3'
List all non-hidden files in ~/junk
find ~/junk -name "*" -exec ls -l {} \;
Find all .gz archives in the /path/to/dir directory tree
find /path/to/dir -name "*.gz" -type f
search for a file "file" in current folder and display all instances of this file
find -name file -print
Find all files/directories named 'testfile.txt' under current directory tree
find . -name testfile.txt
download content from "http://search.twitter.com/search.json?q=node.js" and format it as json
curl -s http://search.twitter.com/search.json?q=node.js | json
Print the top 10 commands with their use count
history | awk '{print $2}' | awk 'BEGIN {FS="|"}{print $1}' | sort | uniq -c | sort -nr | head
Rename file ~/junk/cart1 to ~/junk/A
find ~/junk -name 'cart1' -exec mv {} ~/junk/A \;
Search the /path directory tree for files missing g+w or o+w bits
find /path ! -perm -022
Sleep until tomorrow at 21:30
sleep $(($0))
Find all files/directories under current /export/home/someone directory and upload them to ftp://somehost/tmp/
find /export/home/someone -exec curl -u someone:password -vT {} ftp://somehost/tmp/
Print the number of packets sent, received, and the percentage lost for each ping request to "google.com"
ping google.com | awk '{ sent=NR-1; received+=/^.*(time=.+ ms).*$/; loss=0; } { if (sent>0) loss=100-((received/sent)*100) } { printf "sent:%d received:%d loss:%d%%\n", sent, received, loss }'
Gives longest '*.php' files with line count first, and excludes directories with "libs", "tmp", "tests" and "vendor" in their paths.
find . -name '*.php' | xargs wc -l | sort -nr | egrep -v "libs|tmp|tests|vendor" | less
find httpd.conf file in /etc directory
find /etc -name "httpd.conf"
Find all files under /path/to/base/dir and change their permission to 644
chmod 644 $
Find all of the hidden files in the current directory and its sub-directories.
find . -type f -name ".*
Sort tab separated file "file" using a version sort for field 6 and a numeric sort for field 7
sort -t$'\t' -k6V -k7n file
Print three lines of "some line " followed by a random number
seq -f 'some line %g' 500 | nl | sort -R | cut -f2- | head -3
SSH into "111.222.333.444" as user "tunneluser" without a pseudo-terminal and without interpreting bash variables locally
ssh -T [email protected] <<'EOI'
search for text files in the current folder which have write access to others
find . -type f \
delete all the directories empty directories in the current folder
find . -type d -empty -delete
Simulate a full login
su -
Removes resursively all files and folders named "Thumbs.db", ignoring case distincts.
find . -iname "Thumbs.db" -print0 | xargs -0 rm -rf
Counts total lines in PHP and JS files.
find . -name '*.js' -or -name '*.php' | xargs wc -l | grep 'total' | awk '{ SUM += $1; print $1} END { print "Total text lines in PHP and JS",SUM }'
Mount partition with label "WHITE" on "/mnt/WHITE" with read and write permission
mount -L WHITE /mnt/WHITE -o rw
Compare "fastcgi_params" and "fastcgi.conf" line by line, output 3 lines of unified context, and print the C function the change is in
diff -up fastcgi_params fastcgi.conf
Force delete all jpg files in current directory which are less than 50KB and do not search in the sub directories
find . -maxdepth 1 -name "*.jpg" -size -50k | xargs rm -f
Execute python script "test.py" with "LD_PRELOAD=./linebufferedstdout.so" and write the output to console and append to "test.out"
LD_PRELOAD=./linebufferedstdout.so python test.py | tee -a test.out
Unzip all ".gz" files in the current directory tree to their respective directories
find . -name "*.gz" -execdir gunzip '{}' \;
Search the current directory tree for files matching regular expression '.*myfile[0-9][0-9]?'
find . -regex '.*myfile[0-9][0-9]?'
Find all files under current directory that were modified in the last 24 hours and also include the files that were modified in less than 1 day ago
find -mtime +0
Archive "/var/www/test/" to "/var/www/test" on host "231.210.24.48" as user "ubuntu" via ssh using identity file "/home/test/pkey_new.pem"
rsync -rave "ssh -i /home/test/pkey_new.pem" /var/www/test/ [email protected]:/var/www/test
Modify interval to 0.1 seconds for the watch command
watch -n 0.1
Enable history and history expansion within a script
set -o history -o histexpand
remote copy all text files from one location to another
find . -name '*.txt' -exec rsync -R {} path/to/dext \;
Find all broken symlinks under current directory
find . -type l -exec sh -c "file -b {} | grep -q ^broken" \; -print
Rank the usage of libraries for a set of tools "/bin/* /usr/bin/* ..."
ldd /bin/* /usr/bin/* ... | sed -e '/^[^\t]/ d; s/^\t\\?\ (.*/\2/g' | sort | uniq -c
delete all the "wmv" "wma" files in the currnet folder,
find . \( -name '*.wmv' -o -name '*.wma' \) -exec rm {} \;
Print the list of files and directories of the current directory
find . ! -name . -prune
Find files patching "pattern"
find . -name "pattern" -print
Print the file names along with their sizes under current directory tree
find . -type f -printf "%f %s\n"
change the permissions of all regular/normal files in the file system
chmod 640 `find ./ -type f -print`
print all active readline keybindings
bind -P | grep --fixed-strings ' can be found on ' | perl -pe 's/(*)\\C/\1Ctrl/g;s/(*)\\e/\1Esc,/g'
find all files in the current folder which have not been changed in the last 48 hours
find ./ -daystart -ctime +2
Calculate the md5sum of the executable file of command 'c++'
md5sum `which c++`
List subdirectories in the current directory
find . -maxdepth 1 -type d -exec ls -ld "{}" \;
Find files under /etc/apache-perl that are modified more recently than /etc/apache-perl/httpd.conf
find /etc/apache-perl -newer /etc/apache-perl/httpd.conf
Search for files greater than 20MB in the entire file system, sort them according to size in ascending order and display the path and file size
find / -type f -size +20M -exec ls -lh {} \; 2> /dev/null | awk '{ print $NF ": " $5 }' | sort -nk 2,2
List *.txt files under current directory that have 'mystring' in their name
find . -name *.txt | egrep mystring
Change file owner and group of "/path/to/yourapp" to root and print a diagnostic
chown -v root:root /path/to/yourapp
Prints calendar for a current month.
cal
Recursively search through all files in all directories for any lines containing "pattern" and whose second word is not "Binary".
grep -Ri "pattern" * | awk '{if($1 != "Binary") print $0}'
delete all text files in the home folder after user confirmation
find $HOME/. -name "*.txt" -ok rm {} \;
Sets shell option 'nounset'.
shopt -s -o nounset
Remove the files or directories 'bin/node', 'bin/node-waf', 'include/node', 'lib/node', 'lib/pkgconfig/nodejs.pc' and 'share/man/man1/node' with superuser privilege
sudo rm -rf bin/node bin/node-waf include/node lib/node lib/pkgconfig/nodejs.pc share/man/man1/node
Print the names of any differing files in directories "dir1/" and "dir2/"
diff --brief --recursive dir1/ dir2/
Print file system disk space usage of the current directory's file system
df .
Append "<br/>" to the end of each line in "1\n2\n3"
echo -e "1\n2\n3" | sed 's/.*$/&<br\/>/'
Find all foo.mp4 files in the current directory tree and print the pathnames of their parent directories
find . -name foo.mp4 -exec dirname {} \;
Search for the string 'device' in all regular files in the entire filesystem
find / -type f -print | xargs grep "device"
search for the files with the name "temp" and which have not been accessed in the last 7*24 hours in the /usr folder
find /usr -name temp -atime +7 -print
Page through the contents of BIG_FILE.txt, letting the user move around with the arrow keys, the Q key quits.
cat BIG_FILE.txt | less
find all files the current folder which have not been accessed in the last 7 days and which are bigger than 20KB
find . -atime +7 -size +20480 -print
Find and clear UTF-8 files with BOM
find . -type f -exec sed '1s/^\xEF\xBB\xBF//' -i.bak {} \; -exec rm {}.bak \;
Find directories in the current directory tree that were modified within the last 24 hours and move them to /path/to/target-dir
find . -type d -mtime -0 -print0 | xargs -0 mv -t /path/to/target-dir
Print a list of all files/directories under current directory in myfile.sh file
find . -print >myfile.sh
Remove trailing white spaces and replace CRLF with LF in all files under current directory ignoring .git and .svn directories
find . -not \ -type f -exec sed -i 's/[:space:]+$//' \{} \; -exec sed -i 's/\r\n$/\n/' \{} \;