nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
find all the normal/regular files in the current directory which have been modified in the last 24 hours
find . -mtime -1 -type f -print
search for a folder junk in the home directory and create files cart1, cart2, cart3 ... cart6 in the folder junk. Discard all the errors.
find ~/junk -exec touch ~/junk/cart{1,2,3,4,5,6} {} \; 2> /dev/null
Display the 5 smallest files in the current directory and its sub-directories ignoring any empty files.
find . -not -empty -type f -exec ls -s {} \; | sort -n | head -5
Find all files/directories under current directory that were modified later than /reference/file
find . -newer /reference/file
Display the number of regular files under current directory tree
find . -type f -exec echo {} \; | wc -l
Prints only first ten characters of each string of file $file.
cat $file | cut -c 1-10
Removes all files but 5 newest ones from current folder.
ls -tp | grep -v '/$' | tail -n +6 | tr '\n' '\0' | xargs -0 rm --
find all the directories in the current folder which have been modified in 24 hours and move them to the folder /path/to/target-dir
find . -type d -mtime -0 -exec mv -t /path/to/target-dir {} +
Extract path and query part from URL
echo "$url" | cut -d'/' -f4-
Print output of script 'trap.sh'
~ $ . trap.sh | cat
Print sorted list of strings from 'ip_addresses' file, with number of occurrences of each string.
sort ip_addresses | uniq -c
Search for first match of the regex 're' in all *.coffee files under current directory and print the file names
find . -name \*.coffee -exec awk '/re/ {print FILENAME ":" $0;exit}' {} \;
list all javascipts file expect files under proc folder
find . -type d -name proc -prune -o -name '*.js'
List all regular files from the current directory tree that were modified less than 60 minutes ago
find . -mmin -60 -type f -ls
Extract any line in "file1" or "file2" which does not appear in the other
comm -3 <(sort file1) <(sort file2)
Recursively search through directory "test" in home directory, displaying names of all directories without full paths, ie. only the name part following the last slash of each directory.
find ~/test -type d -exec basename {} \;
Copy all files below the current directory whose names contain "foobar" to directory foo/bar/ in user's home directory.
find . -iname "*foobar*" -exec cp "{}" ~/foo/bar \;
Measure the disk space taken up by all *.txt files in directory tree /home/d
find /home/d -type f -name "*.txt" -printf "%s\n" | awk '{s+=$0}END{print "total: "s" bytes"}'
Print mount point of the file system containing $filename.
df "$filename" | awk 'NR==1 {next} {print $6; exit}'
Format each line as 3 columns based on extraneous columns
awk '{for(i=3;i<=NF;i++){print $1,$2,$i}}' file | column -t
Find all regular files that reside in the current directory tree and were last modified 1 day ago
find . -type f -mtime 0
Mount "ext4" filesystem "/dev/xvdf1" on "/vol"
sudo mount /dev/xvdf1 /vol -t ext4
List all non-empty files under under current directory
find . -type f ! -size 0
Unzip "file.gz" to stdout
zcat file.gz
Copy all files/directories excluding *.flac files under current directory to /media/wd/network_sync/music directory
find . -type f -iname "*.flac" -o -print0 -iname "*.mp3" -print0 -o -iname "*.wav" -print0 -o -iname "*.aac" -print0 -o -iname "*.wma" -print0 | while read -d $'\0' file; do cp -ruv "$file" "/media/wd/network_sync/music/$file"; done
Print 7 spaces in a row
yes ' ' | head -7 | tr -d '\n'
Interpret backslash sequences and delete whitespace characters in variable $FOO and save the result to variable 'FOO_NO_WHITESPACE'
FOO_NO_WHITESPACE="$"
On host "server_b", connect as ssh user "user" and copy "/my_folder/my_file.xml" to directory "/my_new_folder/", with all transfer data relayed through local host.
scp -3 user@server_b:/my_folder/my_file.xml user@server_b:/my_new_folder/
Make directories a, b, c, ..., z under path2 as needed.
mkdir -p path2/{a..z}
Print the last line of the alphabetically sorted lines in file "set"
tail -1 <
Output the string 'yes' continously until killed
yes
display files in current folder ending with "pdf" or "PDF"
find . -name '*.pdf' -or -name '*.PDF'
search for all regular/normal files in the current folder and display the number of lines in the file
find . -type f -print | xargs -L1 wc -l
Remove files whose names start with `Foo'
find . -type f -name "Foo*" -exec rm {} \;
Recursively removes all files in a current folder but '*txt' files.
find . -type f -not -name '*txt' | xargs rm
Find all hidden files
find /tmp -type f -name ".*"
change permission of all the files in the entire file system which have the permissions 777.
find / -type f -perm 0777 -print -exec chmod 644 {} \;
Print all lines of "seq 1 10" except the last 3
seq 1 10 | perl -e'@x=<>;print@x[0..$#x-3]'
Copy "src" to "dest" if "src" is newer than "dest"
rsync -u src dest
Search for '/usr/bin/perl' in all regular files under current dirctory tree and also show a long listing of them
find . -type f -exec grep "/usr/bin/perl" {} \; -ls
Remove symbolic links and get absolute path of "${the_stuff_you_test}" and save to variable "DIR_PATH"
DIR_PATH=`readlink -f "${the_stuff_you_test}"`
Remove all files from the current directory tree whose names do not end with ".tex" or ".bib"
find . | egrep -v "\.tex|\.bib" | xargs rm
Print the names and sizes of regular files residing in the "tmp" directory tree
find tmp -type f -printf "%s %p\n" | awk '{sub(/^[^ ]+/,sprintf)}1'
Get current hosts's IPv4 address.
host $ | grep "address" | grep -v "IPv6" | head -n 1 | awk '{print $4}'
Create compressed archive of all the files in the current directory tree that have been modified in the last 7 days
find . -type f -mtime -7 -print -exec cat {} \; | tar cf - | gzip -9
Display permissions, user, group, and full path for each file in the current directory tree
tree -p -u -g -f
Search the /usr/bin directory tree for regular files accessed more than 100 days ago
find /usr/bin -type f -atime +100
Print a single line of numbers from "001" to "100"
yes | head -n 100 | awk '{printf}' ##for 001...100
Find files/directories named 'filename' in the entire filesystem
find / -name filename -print
find all the files in the folder /home which are exactly of size 10MB
find /home -size 10M
find all the undo files in the current folder and display the toal lines, words, characters
find ./ -name *.undo | xargs wc
Find all * * regular files under current directory
find . -type f -name "* *"
Count total number of lines in all *txt files in current directory
wc -l `find . -type f -name '*.txt' `
Print a sorted list of the subdirectories of ~/Music
find ~/Music/ -maxdepth 2 -mindepth 2 -type d | sort
Find all files/directories that start with 'onlyme' in their names under maximum 2 levels down the current directory
find . -maxdepth 2 -name 'onlyme*'
Find all executable files under {} and reverse sort them
find {} -type f -depth 1 -perm +0111 | sort -r
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 files in the current directory tree that match pattern "*sub*"
find ./ -name "*sub*"
Generates name for temporary file with 6-letter suffix, and saves path to that new file in 'fn' variable.
fn=$(mktemp -u -t 'XXXXXX')
Find all files in entire file system which are larger than 20000KB
find / -type f -size +20000k
display all files in the current folder
find .
Find files owned by nonexistent users
find / -nouser -print
Disables shell option 'nocasematch'.
shopt -u nocasematch
Find file size in bytes
du -b FILE
Find all directories under and below /home/admin/public_html/, and change their permissions to 755
find /home/admin/public_html/ -type d -exec chmod 755 {} \;
Remove the regular files from the current directory tree that were last modified on November, 21
find -type f -newermt "Nov 21" ! -newermt "Nov 22" -delete
Split "<file_name>" into files of at most 1024 KiB in size
split -b 1024k <file_name>
Save the absolute path of "$path" to variable "fullpath"
fullpath=`readlink -f "$path"`
Prints strings with text "texthere" in all files recursively in a current folder.
grep -r "texthere" .
Print right aligned numbers from 11 to 24
yes '' | nl -ba | sed -n -e 11,24p -e 24q
Print space separated numbers from 1 to 10
seq 10 | xargs echo
Print the current shell
ps | tail -n 4 | sed -E '2,$d;s/.* /\1/'
Print a frequency count of column two for every file in the current directory
awk -F '\t' '{print $2}' * | sort | uniq -c | sort -nr
Find all files/directories with space in their names under current directory
find . -name '* *'
Add prefix "prefix_" to all ".jpg" files in the current directory
for filename in *.jpg; do mv "$filename" "prefix_$filename"; done;
delete all text files in the entire file system
find / -type f -name "*.txt" -print | xargs rm
Find all PNG and JPG files and append them to archive `images.tar'
find . \ -print -exec tar -rf images.tar {} \;
Copy "/new/x/y/z/" over the network to "user@remote:/pre_existing/dir/" preserving the directory hierarchy
rsync -a --relative /new/x/y/z/ user@remote:/pre_existing/dir/
long list al the files in the current directory which have read permission to the group
find . -perm -g=r -type f -exec ls -l {} \;
Archive "/home/path" to "path" on host "server" showing progress and statistics and remove files in the destination not found in the source
rsync -a --stats --progress --delete /home/path server:path
Print unique list of who is logged in and the time of login formatted in columns
who -su | sort | uniq | column
Counts lines in file $file and prints number only.
wc -l $file | awk '{print $1}';
Find all files/directories starting with 'app-' and ending with '.log' in their names and have been modified in the last 5 minutes
find /var/log/crashes -name app-\*\.log -mmin -5
display in a list of all the files that are bigger than 10KB in current folder
find . -size +10k -ls
Find all image.pdf files/directories under ./polkadots with null character as the delimiter
find ./polkadots -name "image.pdf" -print0
List all regular files from the current directory tree that were modified less than 60 minutes ago
find . -type f -mmin -60 -print0 | xargs -r0 ls -l
Search for "CONFIG_64BIT" in gzip compressed file "/proc/config.gz"
zcat /proc/config.gz | grep CONFIG_64BIT
Find all *foo* files/directories under current directory and copy them to /your/dest
find . -name "*foo*" | sed -e "s/'/\\\'/g" -e 's/"/\\"/g' -e 's/ /\\ /g' | xargs cp /your/dest
Show what content owned by root has been modified within the last day
find /etc/ -user root -mtime 1
Compress "hello world" and save to variable "hey"
hey=$(echo "hello world" | gzip -cf)
Print appended data in "file" that match "my_pattern"
tail -f file | grep --line-buffered my_pattern
search for the word "redeem reward" in all the regular/normal files in the current folder and discard all the errors
find . -type f -exec grep -i “redeem reward” {} \; -print 2>/dev/null
Find all files called "file1.txt" that reside under and below /home/wsuNID/
find /home/wsuNID/ -name file1.txt
List all paths to files or directories under "/data/" that start with "command-" and end with "-setup", sort the result by the version number specified between "command-" and "-setup"
find /data/ -name 'command-*-setup' | sort -t - -V -k 2,2
Counts lines of /dir/file.txt file.
cat /dir/file.txt | wc -l
Search all .pdf files from directory tree ~/.personal/tips for "hot"
find ~/.personal/tips -type f -iname "*.pdf" -exec pdftotext '{}' - ';' | grep hot
Get the sizes of all files under dir1 directory
find dir1 ! -type d |xargs wc -c
change the permission of all php files in current folder. Plus symbol at the end is used to give multiple files as input to the chmod command
find . -name "*.php" -exec chmod 755 {} +
find all the links in the current folder and following it to the pointed path
find -L /target -type l
find all the database files in the folder /var/named
find /var/named -type f -name *.db