nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
display long listing of first 10 directories in the current folder
find . -type d -ls | head
Search the current directory tree for executable files and searchable directories
find -executable
find all the files in the home folder which have been modified after a file
find $HOME -newer ~joeuser/lastbatch.txt
Print "*Checking Partition Permission* Hostname=$(hostname) LastChecked=" followed by the current date
echo -n *Checking Partition Permission* Hostname=$(hostname) LastChecked=$(date)
Format and print the time string @133986838 according to the default time format
date --date @120024000
Copies all files with "FooBar" in the path under the current directory to the '~/foo/bar' directory.
find . | grep FooBar | xargs -I{} cp {} ~/foo/bar
Search the current directory tree for all files matching either pattern "*.rb" or pattern "*.py"
find . -name "*.rb" -or -name "*.py"
For each line in 'file', print "result = " followed by the line backwards.
awk '{print "result =",$0}' <
Find all files under current directory and count the output line number
find . -type f | wc -l
Print '-okdir is an action so an implicit -print is not applied' for each file/directory found by the name 'file' under current directory tree
find -name file -okdir echo '-okdir is an action so an implicit -print is not applied' \;
Print lines 2960 to 2966 from the output of "history"
history | sed -n '2960,2966p'
Print the paths of all files in the current directory tree that contain "abc" replacing "abc" with "xyz"
find . |xargs grep abc | sed 's/abc/xyz/g'
Delete all files with '.old' extension under current directory tree
find . -name “*.old” -exec rm {} \;
Find all files named 'new' under current directory tree and display their contents
find . -name new -print -exec cat {} +
Rename recursively all files in the current directory tree that are called "article.xml" to "001_article.xml"
find . -name "article.xml" -exec rename 's/article/001_article/;' '{}' \;
find all the files in the current folder that have not been modified in the last 24*3 hours
find ./ -mtime +3
Find all files/directories with inode number 16187430 and move them to 'new-test-file-name'
find -inum 16187430 -exec mv {} new-test-file-name \
Archive "/top/a/b/c/d" to host "remote" using relative path names
rsync -a --relative /top/a/b/c/d remote:/
Format each line as 3 columns based on extraneous columns
awk '{for{print $1,$2,$i}}' file | column -t
Find all directories under current directory whose names are 33 characters long
find . -type d -name "?????????????????????????????????"
Locate files whose status was changed less than 1 day ago
find . -ctime -1 -print
Search for non-empty files
find . ! -size 0k
find all files in the current directory and sub-directories that were modified after the /etc/passwd file was modified
find -newer /etc/passwd
Find all directories under maximum 1 level down the current directory and set their permission to 700
find . -mindepth 1 -type d | xargs chmod 700
Find all hidden regular files under /tmp and below
find /tmp -type f -name ".*"
List all empty files in the current directory tree
find . -empty -exec ls {} \;
Prints day of first Tuesday in a month.
cal | awk 'NR>2 && NF>4 {printf "%02d\n",$;exit}'
display all the files in the current folder which have been modified in one hour ago
find . -newermt "1 hour ago"
Search directory lpi104-6 for files with inode number 1988884
find lpi104-6 -inum 1988884
List all regular files from the current directory tree that were modified less than 60 minutes ago
find . -mmin -60 -type f -ls
Bind mount "/dev/random" on "/tmp/fakerandom"
mount --bind /tmp/fakerandom /dev/random
Search the regular files of the current directory tree for string "whatever"
find . -type f -exec grep -H whatever {} \;
Find all regular files with 755 permission under current directory tree and change their permission to 644
find . -type f -perm 755 -exec chmod 644 {} \;
Find all orm.* files/directories under current directory
find . -name "orm.*"
display a long listing of all the directories in current directory
find . -type d -ls
Find all files/directories with '.mp4' extension and all regular files with '.flv' extension, sort them according to their names and display the first 500 of them
find /storage -name "*.mp4" -o -name "*.flv" -type f | sort | head -n500
Go into the first directory whose name contains 1670
cd `find . -maxdepth 1 -type d | grep 1670`
Remount "/system" with read and write permission
mount -o remount,rw /system
Display differences in "/tmp/ksh-9725.log" when compared to "/tmp/ksh-9781.log"
diff /tmp/ksh-{9725,9781}.log | grep ^\<
Prints only unique strings of those stored in variables $COMMANDS and $ALIASES.
echo "$COMMANDS"$'\n'"$ALIASES" | sort -u
Counts lines in each of *.php files in a current folder and subfolders ignoring 'tests*' folders and prints total count as well.
find . -name "*.php" -not -path "./tests*" | xargs wc -l
Print summary of new/missing files, and which files differ between dir1 and dir2.
diff --brief --recursive dir1/ dir2/
Find all files in your home directory and below that are exactly 100M.
find ~ -size 100M
Find files with 002 permission under /tmp and print them with the string 'Found world write permissions:' printed as the first line of output
find /tmp -type f -perm -002 | sed '1s/^/Found world write permissions:\n/'
Check if current system is running in 64-bit addressing.
uname -m | grep '64'
find all the files ending with jpg in current folder and display their count
find ./ -type f -regex ".*\.[Jj][Pp][gG]$" | wc -l
list in long format all files from / whose filename ends in "jbd", not descending into directories that are not readable while searching.
find / \! -readable -prune -o -name '*.jbd' -ls
Get the total sizes of all files under current directory
find . -type f -printf '%p %s\n' | awk '{ sum+=$2}; END { print sum}'
delete all the normal files in the current directory whcih have the word "gui" in their content.
find / -type f -print0 | xargs -0 grep -liwZ GUI | xargs -0 rm -f
Replace "," with "\r\n" in "a,b"
echo "a,b"|sed 's/,/\r\n/'
get all the files that are exactly 30 days old
find . -mtime 30 -print
Find the largest 10 directories under current directory
find . -type d -print0 | xargs -0 du | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}
List content of 'myfile' in a subshell and returns output to parent shell
$
Search the current directory and its sub-directories for any file that has "bsd" somewhere in its name.
find . -name "*bsd*" -print
find all normal/regular files in the current directory
find . -type f -print
Search for all files with either "sitesearch" or "demo" in their path names
find . -ipath '*sitesearch*' -ipath '*demo*'
display all the directories in the folder /path/to/dest except tmp and cache directories
find /path/to/dest -type d \( ! -name tmp \) -o \( ! -name cache \) -print
Display differences between files "a.txt" and "b.txt" side-by-side and do not output common lines.
diff -a --suppress-common-lines -y a.txt b.txt
Find all "G*.html" files modified more than 7 days ago in the current directory tree and pass them as arguments to script /path/to/script_7zipi
find . -mtime +7 -name "G*.html" -execdir /path/to/script_7zipi {} +
display the base name(name without extension) of all the ".flac" files in the current folder
find . -name "*.flac" -exec basename \{\} .flac \;
Archive showing progress all files in "/media/2TB\ Data/data/music/" to "/media/wd/network_sync/music/" excluding files matching "*.VOB", "*.avi", "*.mkv", "*.ts", "*.mpg", "*.iso", "*ar", "*.vob", "*.BUP", "*.cdi", "*.ISO", "*.shn", "*.MPG", "*.AVI", "*.DAT", "*.img", "*.nrg", "*.cdr", "*.bin", "*.MOV", "*.goutputs*", "*.flv", "*.mov", "*.m2ts", "*.cdg", "*.IFO", "*.asf", and "*.ite"
rsync -av --progress --exclude=*.VOB --exclude=*.avi --exclude=*.mkv --exclude=*.ts --exclude=*.mpg --exclude=*.iso --exclude=*ar --exclude=*.vob --exclude=*.BUP --exclude=*.cdi --exclude=*.ISO --exclude=*.shn --exclude=*.MPG --exclude=*.AVI --exclude=*.DAT --exclude=*.img --exclude=*.nrg --exclude=*.cdr --exclude=*.bin --exclude=*.MOV --exclude=*.goutputs* --exclude=*.flv --exclude=*.mov --exclude=*.m2ts --exclude=*.cdg --exclude=*.IFO --exclude=*.asf --exclude=*.ite /media/2TB\ Data/data/music/* /media/wd/network_sync/music/
Remove all .txt files from the /full/path/dir directory tree
find /full/path/dir -name '*.txt' -print0 | xargs -0 rm
Overwirte file '/path/to/your/file' with random content, showing progress while execution.
shred -v -n 1 /path/to/your/file #overwriting with random data
Mathematically sum each line in the output of "..."
... | paste -sd+ - | bc
Prompt the user with a question "This is the question I want to ask?" and save "y" or "n" in variable "REPLY" in zsh
read REPLY\?"This is the question I want to ask?"
Print all files and directories in the `.' directory tree skipping SCCS directories
find . -name SCCS -prune -o -print
Move "file.txt" to docker container "$CONTAINER_ID" in path "/var/lib/docker/devicemapper/mnt/$CONTAINER_ID/rootfs/root/file.txt"
mv -f file.txt /var/lib/docker/devicemapper/mnt/$CONTAINER_ID/rootfs/root/file.txt
Search the files from the current directory tree for text "documentclass"
find . -type f -print0 | xargs -0 grep -H 'documentclass'
Clears terminal screen.
echo `clear`
Delete all files under root whose status were changed more than 30 minutes ago
find root -type -f -cmin +30 -delete
Copies all files under the current directory but ones with '*/not-from-here/*' in path to the '/dest/' directory.
find . -type f -not -iname '*/not-from-here/*' -exec cp '{}' '/dest/{}' ';'
Find all files/directories under $1 which have at least read permission for their owner and set read permission for group for these files/directories
find $1 -perm -u+r -exec chmod g+r {} \;
Overwrites file 'filename' with random content 35 times, finally writes it with zeros, truncates and deletes.
shred -uzn 35 filename
remove all the log files which have not been modified in the last 5 days
find /logs -type f -mtime +5 -exec rm {} \;
Display differences between directories dir1 and dir2.
diff -r dir1 dir2
Enable history in a script
set -o history
Replace all instances of "STRING_TO_REPLACE" with "STRING_TO_REPLACE_IT" in "index.html" and write the output to standard output and "index.html"
sed s/STRING_TO_REPLACE/STRING_TO_REPLACE_IT/g index.html | tee index.html
Save hexadecimal bytes 7 and 8 in binary file "file.moi" to variable "year"
year=$
find all normal/regular files in current folder and display the total lines in them
find . -type f -print0 | xargs -0 wc -l
Find all .zip files in the current directory tree
find . -depth -name *.zip
Make directory "/tmp/foo"
mkdir /tmp/foo
List all *.txt files under current directory that match 'foo=' in their file information
find . -name "*.txt" -type f -print | xargs file | grep "foo=" | cut -d: -f1
Recursively removes all files and folders named '.svn' in a current folder.
find . -name .svn |xargs rm -rf
Find all files under current directory and append a null character at the end of each of their paths
find -type f -print0
find all the files in the file system that start with "win" and searched only in the mounted file systems
find / -mount -name 'win*'
Convert all characters in standard input to lower case
sed 's/.*/\L&/'
Represent the current time as seconds since epoch and save it to variable 'TODAY'
TODAY=$(date -d "$" +%s)
Remount "yaffs2" filesystem "/dev/block/mtdblk4" to "/system" as read and write only
mount -o rw,remount -t yaffs2 /dev/block/mtdblk4 /system
Find all the files in file system which are modified 50 days back
find / -mtime 50
find all the files in the current folder which have not been modified in the last 90 days and force delete them
find . -mtime +90 -type f -exec rm -f {} \;
Search the current directory tree for files whose names begin with 'my'
find . -name 'my*'
Write "127.0.0.1 ad.doubleclick.net" to the console and append to "/etc/hosts" as root
echo 127.0.0.1 ad.doubleclick.net | sudo tee -a /etc/hosts
Copies ""$project_dir"/iTunesArtwork", to the 'Payload/iTunesArtwork', rewriting files if necessary.
cp -f "$project_dir"/iTunesArtwork Payload/iTunesArtwork
Display info on most CPU-intensive processes once and exit.
top -n 1
display the count of all normal/regular files in current directory
find . -type f | wc -l
find all the files in the file system which have been modified in the last 10 minutes
find / -mmin -10
ERROR - need to add -a or -r for recursive copy
rsync --exclude='B/' --exclude='C/' . anotherhost:/path/to/target/directory
Print the number of regular files found in the current directory tree
find . -type f | wc -l
Make directory "tata"
mkdir tata
Case-insensitive search all existing environment variables and their values for "shell".
env | grep -i shell