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
Execute "myscript.rb" with the first argument as the current host name and the second "file.txt"
echo "`hostname -i` file.txt" | xargs myscript.rb
Discard the first letter from every line in $line and calculate the md5 sum of the remaining
echo $line | cut -c2- | md5sum
find all the files ending with .ini in the current directory.
find . -name *.ini
Find all regular files under $DIR/tmp/daily/, sort them in reverse numerical order and copy the first two files to $DIR/tmp/weekly/
find $DIR/tmp/daily/ -type f -printf "%p\n" | sort -rn | head -n 2 | xargs -I{} cp {} $DIR/tmp/weekly/
Archive key.pub to directory .ssh in user's home directory on host specified by first parameter to function or script, using ssh to connect on port specified by second parameter to function or script, compress data during transmission.
rsync -avz --rsh="ssh -p$2" key.pub $1:~/.ssh/key.pub
Move all *.php~ files under current directory to /mydir
find . -iname "*.php~" -exec mv "{}" /mydir +;
Search the current directory and all of its sub-directory for any PDF files.
find . -name "*.pdf" -print
Run a shell in a named screen session
screen -x title
Find files changed in the last 1 day
find . -mtime -1 -type f
Calculate md5 checksum of theDirname
cpio -i -e theDirname | md5sum
Grab a gzipped text file from the web and display its decompressed content, interactively paging through the output.
curl -s 'http://archive.ubuntu.com/ubuntu/pool/universe/s/splint/splint_3.1.2.dfsg1-2.diff.gz' | gunzip -dc | less
find all the files in home folder which have been modified in the last 24 hours
find $HOME -mtime -1
Delete all *txt files under current directory
find . -name "*txt" -type f -print | xargs rm
ask user confirmation and delete all the files in the directory /mydir which have not been accessed in the last 100*24 hours
find /mydir -atime +100 -ok rm {} \;
Delete all files/directories with '.old' extension under current directory tree
find . -name “*.old” -delete
Print a count of duplicate lines in "filename"
sort filename | uniq -c
sort each file in the bills directory, leaving the output in that file name with .sorted appended
find bills -type f -execdir sort -o '{}.sorted' '{}' ';'
find all the files in the entire file system that were modified in the last 10 minutes
find / -mmin -10
tar all the regular java files to myfile.tar
find . -type f -name "*.java" | xargs tar cvf myfile.tar
search for a word in all the php files in the current folder and display the count of all matching lines.
find . -name \*.php -type f -exec grep -Hn '$test' {} \; | wc -l
Send at most 3 ping requests to "8.8.8.8" with a timeout of 3 seconds on interface "eth9"
ping 8.8.8.8 -I eth9 -c 3 -w 3
Gets IP addresses of all active network interfaces.
ifconfig | grep -oP "(?<=inet addr:).*?(?= Bcast)"
Find *.tex files in the current directory tree that contain text "documentclass"
find . -type f -name *.tex -print0 | xargs -0 grep -l 'documentclass'
Search for files "file1" or "file9"
find . -name file1 -or -name file9
Remount subtree "/usr/bin" on "/path/to/chroot/jail/usr/bin" as a bind
mount --bind /usr/bin /path/to/chroot/jail/usr/bin
Find *.o files with permissions 664 in the current directory tree
find . -name *.o -perm 664 -print
display all scala files in the directory "src/main"
find . -type f -path "*src/main/*\.scala"
Find all files/directories that were modified after February 1st under '/usr' directory tree
find /usr -newermt "Feb 1"
Prints all Saturday days of a current month.
cal -h | cut -c19-20
Copy file header.shtml to directories dir1, dir2, dir3, and dir4
find dir1 dir2 dir3 dir4 -type d -exec cp header.shtml {} \;
Search for "ifconfig" in the output of "history" and print 5 lines that precede and follow
history | grep ifconfig -A5 -B5
create directory public_html into home directory
mkdir ~/public_html
Find all empty directories recursively starting from the current one and delete them
find . -type d -empty -delete
Clean up all zombie processes by instantly killing their parent process with SIGKILL signal.
kill -9 $(ps -A -ostat,ppid | grep -e '[zZ]'| awk '{ print $2 }')
Change the owner to "root" and group to "specialusers" of "dir1"
chown root:specialusers dir1
Display file.txt with lines numbered, and page interactively through the result.
cat -n file.txt | less
Show filename and filetype description of all PHP files in all directories contained in current directory whose name or filetype description includes "UTF"
file */*.php | grep UTF
display all the header files and cpp files in the current folder
find . -name \*.h -print -o -name \*.cpp -print
loop over the results of a find command
find . -type f -name '*.*' -print0 | while IFS= read -r -d '' file; do printf '%s\n' "$file" done
store absolute path of executing script
DIR="$( cd "$" && pwd )"
Find file names *blast* in specfied directory
find /usr/local -name "*blast*"
Find all directories under maximum 1 level down the current directory and set their permission to 700 recursively
find . -maxdepth 1 -type d -exec chmod -R 700 {} \;
Force delete all files in the current folder
find . | xargs -i rm -f "{}"
Creates temporary folder, and saves current folder path joined with created temporary folder path in 'tdir' variable.
tdir="$/$"
Print content of all files ending with '*.foo' under the current directory
cat $(find . -name '*.foo')
List the number of occurrences of each unique character in "The quick brown fox jumps over the lazy dog" sorted from most frequent to least frequent
echo "The quick brown fox jumps over the lazy dog" | grep -o . | sort | uniq -c | sort -nr
Archive all files/directories under data/ into archive.tar
find data/ -print0 | tar --null -T - --create -f archive.tar
Write standard input to standard output and to "foobar.txt"
tee foobar.txt
Print whether the sorted contents of "set1" and "set2" differ
diff -q <(sort set1) <(sort set2)
Execute zcat on every file matching "*20120805.gz" in the current directory and subdirectories
find . -name *20120805.gz -exec zcat {} \;
Traverse the filesystem just once, listing setuid files and directories into /root/suid.txt and large files into /root/big.txt.
find / \( -perm -4000 -fprintf /root/suid.txt '%#m %u %p\n' \) , \ \( -size +100M -fprintf /root/big.txt '%-10s %p\n' \)
List in detail regular files from the current directory tree whose names match Perl regular expression '\w+-\d+x\d+\.\w+$'
find -type f | grep -P '\w+-\d+x\d+\.\w+$' | sed -re 's/(\s)/\\\1/g' | xargs ls -l
Find all empty directories in the current one and delete them
find . -type d -maxdepth 1 -empty -print0 | xargs -0 /bin/rmdir
Prints calendar of February, 1900.
cal 2 1900
find all text files in current folder; which have been modified exactly 5 days ago
find . –name "*.txt" –mtime 5
Removes all files from current folder but 5 newest ones, ignoring folders in a files list.
find . -maxdepth 1 -type f | xargs -x ls -t | awk 'NR>5' | xargs -L1 rm
find all php files in the folder /var/www/
find /var/www/ -type f -iname "*.php" -print
Find all files/directories under /path/to/dir/* paths and print the timestamp in YmdHMS format along with their paths and object of symlinks
find /path/to/dir/* -printf "%TY%Tm%Td%TH%TM%TS|%p|%l\n"
list all *.txt files in the user's home directory.
find ~/ -name '*.txt'
Finds IP addresses of all network interfaces.
ifconfig | sed -n 's/.*inet addr:\([0-9.]\+\)\s.*/\1/p'
Find all symbolic links under the current folder and below
find –L –xtype l
Split standard input into files of at most 1000 lines each
split
Find all Read Only files
find / -perm /u=r
Delete all files in the current user's home directory and its sub-directories that have not been accessed for more than 100 days.
find ~ -atime +100 -delete
find list of all files with file permission , link , owner , group , reation time , size , file name
find . -exec ls -ld {} \;
Prevent ssh from reading from standard input and execute "touch /home/user/file_name.txt" on "$R_HOST" as "$R_USER"
ssh -n $R_USER@$R_HOST 'touch /home/user/file_name.txt'
Find regular files named core under /tmp and delete them
find /tmp -name core -type f -print | xargs /bin/rm -f
Search the current directory up to depth level 2 for files and directories
find . -maxdepth 2
Copy a file xyz.c to all the directories below the current one whose names begin with "temp"
find . -type d -name "temp*" | xargs -n1 cp xyz.c
display all the files in the home folder which have read permission to the user
find /home -perm /u=r
Add the execute and read permission for all and the write permission for the user to the dir_data directory and all of its sub-directories.
find ~/dir_data -type d -exec chmod a+xr,u+w {} \;
Find all files in the current directory tree whose size is greater than 1MB
find . -size +1M
Find all socket files in the current directory and its sub-directories.
find . -type s
Print the longest line in "filename"
perl -ne 'print if (length > length);' filename | tail -1
find all files that names are filename and open in nano text editor
find / -name filename -exec nano '{}' \;
Running /path/to/my/script outputs the name of a directory, go into that directory.
cd `/path/to/my/script`
find all the files in current folder which end with a speicifc regular expression and display their count
find ./ -type f -regex ".*\.[JPGjpg]$" | wc -l
Remove all files with '.js' extension from the 'js' directory tree
find ./js/ -type f -name "*.js" | xargs rm -f
display all files in the current folder after pruning those in the current folder ( dot is the output of this command )
find . -prune -print
Delete "\n\r" from "yourfile.txt"
tr -d "\n\r" < yourfile.txt
Convert Unix `cal` output to latex table code.
cal 02 2012|perl -lnE'$.==1||eof||do{$,="\t&";$\="\t\\\\\n";$l=$_;print map{substr}}'
Prints local machine's LAN IP address
ifconfig $ | grep 'inet ' | awk '{print $2}' | grep -Eo '{3}[0-9]*'
List files in "dir1" that are not in "dir2"
comm -23 <(ls dir1 |sort) <(ls dir2|sort)
find all the files in the current directory which are bigger than 1000MB
find . -size +1000M
Find files matching the pattern "./sr*sc" in their paths under current directory
find . -path "./sr*sc"
Remove the last file extension from "filename.gz"
echo "filename.gz" | sed 's/^/./' | rev | cut -d. -f2- | rev | cut -c2-
find all *.csv files which modify within last 2 days in /home directory then zip -
find /home/archive -type f -name "*.csv" -mtime -2 -exec gzip -9f {} \;
Unzip and untar "4.56_release.tar.gz" to standard output
gunzip -c 4.56_release.tar.gz | tar xvf -
List all IPV4 addresses found in all files under /etc directory
find /etc -type f -exec cat '{}' \; | tr -c '.[:digit:]' '\n' | grep '^[^.][^.]*\.[^.][^.]*\.[^.][^.]*\.[^.][^.]*$'
Find all files named 'test' in the current directory tree, not descending into "test" directories
find . -name test -prune
display files in current folder ending with "pdf" or "PDF"
find . -name '*.pdf' -or -name '*.PDF'
Find all .py files in the current directory except "setup.py" and those beginning with "test_"
find . -maxdepth 1 -mindepth 1 \( -name '*.py' -not -name 'test_*' -not -name 'setup.py' \)
Request authority info with comments for 'djzah.com' from name server 'ns1.hosangit.com', and pass it to 'script.awk' awk script.
dig @ns1.hosangit.com djzah.com +noall +authority +comments | awk -f script.awk
Mount "ntfs-3g" filesystem "/dev/mapper/myvolume" on "/media/volume"
mount -t ntfs-3g /dev/mapper/myvolume /media/volume
Print the grand total file system disk space usage with block sizes in units of TiB
df --total -BT | tail -n 1
Prints total count of lines of all *.php files in a current folder and subfolders.
find . -name '*.php' -type f -exec cat -- {} + | wc -l
display the three smallest files by size in a folder.
find /etc/ -type f -exec ls -s {} + | sort -n | head -3
Delete all files/directories under current directory tree excluding '.gitignore' files/directories and files/directories matching the patterns '.git' or '.git/*' in their paths
find . ! -name '.gitignore' ! -path '.git' ! -path '.git/*' -exec rm -rf {} \;
List all directories in maximum 1 level down the current directory
find . -type d -maxdepth 1 -exec ls -dlrt {} \;