nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
show all regular/normal the files in the current folder whose size is bigger than 0 bytes excluding everything
find * -prune -type f -size +0c -print
Extract any line in "set1" which does not appear in "set2"
comm -23 <(sort set1) <(sort set2)
Find all empty files in /tmp
find /tmp -type f -empty
find all the log files in the file system which are present in the current partition
find / -xdev -name "*.log"
Find all files in entire file system which are larger than 20000KB
find / -type f -size +20000k
display all the files in the folder "/Users/Me/Desktop" which belong to the user "popo" and which have the permission 777
find /Users/Me/Desktop -user popo -perm 777
find all the files ending with ".foo" in the folder /usr
find /usr -name '*.foo' -print
Find all *.md files in entire file system and convert them to HTML files
find / -name "*.md" -type f -exec markdown -o {}.html {} \;
Remove gitlab.site.org from root's known hosts file.
ssh-keygen -f "/root/.ssh/known_hosts" -R gitlab.site.org
Concatenate with a space every other line in "input.txt"
paste -s -d' \n' input.txt
find all the video files in the home folder
find ~ -type f -exec file -i {} + | grep video
Find all MP3s in the /home directory tree
find /home -type f -name '*.mp3'
Count total number of lines in all *.txt file in cuuent directory .
find . -type f -name '*.txt' -exec wc -l {} \; | awk '{total += $1} END{print total}'
Find all files larger than 100M and delete them
find / -size +100M -exec rm -rf {} \;
Find x* files/directories under /tmp directory whose status was changed less than 1 day ago and move them to ~/play
find /tmp/ -ctime -1 -name "x*" -exec mv '{}' ~/play/
Change the owner to "owner" and group to "nobody" of "public_html"
chown owner:nobody public_html
Creates temporary file with name formatted like 'emacs-manager.XXXXXX' in '/tmp/' folder and saves path to it in 'tmp_file' variable.
tmp_file=`mktemp --tmpdir=/tmp emacs-manager.XXXXXX`
Search for all files not newer than file /tmp/t
find / -not -newer /tmp/t
SSH using parameters in $@ in master mode in the background without executing any commands and set the ControlPath to "$MASTERSOCK"
ssh -o ControlPath="$MASTERSOCK" -MNf "$@"
find all files in the file system which belong to no user or which have no user
find / -nouser
Recursively copy everything in /source/path whose name doesn't begin with a period, to /destination/path, without overwriting existing files, and outputting a line for each file copied or skipped.
cp -Rvn /source/path/* /destination/path/
Search all files called "abc" that reside in the current directory tree for string "xyz"
find . -name abc | xargs grep xyz
find all the files in the current folder which end with .o or with the name a.out and display them.
find . ( -name a.out -o -name *.o ) -print
Display all lines containing "IP_MROUTE" in the current kernel's compile-time config file.
cat /boot/config-`uname -r` | grep IP_MROUTE
List all environment variables whose name starts with GOROOT
env | grep '^GOROOT'
search for a word in all the fies in the current folder
find . -type f -exec grep some_string {} \;
Create a rsa key of 2048 bits with comment "michael" and store it in file "key".
ssh-keygen -b 2048 -t rsa -f key -C michael
Prints ten latest modified files within the current directory.
find . -type f -printf '%T@ %p\n' | sort -n -r | head -${numl} | cut -f2- -d" " | sed -e 's,^\./,,' | xargs ls -U -l
Find files in the current directory tree whose size is greater than 24000 bytes
find . -size +24000c
Find *.java files in the current directory and replace foo with bar in those files
find . -name "*.java" -exec sed -i '' s/foo/bar/g \;
Sort and remove duplicate lines in the output of "finger"
finger | sort -u
Move *wp-admin/index.php files under /var/www/ to ./index_disabled
find /var/www/ -path '*wp-admin/index.php' -exec mv {} $/index_disabled
Create a full path symbolic link "$newlink" from a relative path symbolic link "$origlink"
ln -s $ $newlink
Display an infinite number of lines consisting of "y", until the user presses the Q key.
yes | more
find all ".flac" files starting with "cmn-" and search for files having CJK characters using unicodes
find . -name 'cmn-*\.flac' -print | grep -P './cmn-[\x4e00-\x9fa5]\.flac'
Copy all regular files from the current directory tree to directory `TARGET'
find . -type f -exec cp -t TARGET {} \+
Set permissions to 500 for directories under the current directory
find . -type d -exec chmod 500 {} \;
find all files that names are game
find / -name game
Filters unique lines by matching against the first column of a .csv file
tac a.csv | sort -u -t, -r -k1,1 |tac
Remount "/system" with read and write permission
mount -o rw,remount /system
Force create a symbolc link named "softlink_name" to "source_file_or_directory_name" without dereferencing "softlink_name"
ln -sfn source_file_or_directory_name softlink_name
find all PDFs owned by user “seamstress”
find / -user seamstress -iname “*.pdf”
Remove trailing white spaces from all *.rb files under current directory
find . -name '*.rb' | xargs -I{} sed -i '' 's/[[:space:]]*$//g' {}
Pair side-by-side content of the 'file' and its side-mirrored content
paste -d ' ' file <(rev file)
Find all files/directories with 644 permission in entire file system
find / -perm 644
Removes resursively all files and folders named "Thumbs.db", ignoring case distincts.
find . -iname "Thumbs.db" -print0 | xargs -0 rm -rf
Delete the commands 1006 through 1008 from history
for h in $; do history -d $h; done
display all executable files in the folder /home
find /home -perm /a=x
Find all regular .mp3 files larger than 10M and delete them
find / -type f -name *.mp3 -size +10M -exec rm {} \;
Read a line from standard input in an interactive shell with prompt in variable "myprompt" interpreted as PS1 is interpreted
read -e -p "${myprompt@P}"
Copy all files and directories under the current directory into "../new" preserving relative paths
find -print0 | sort -z | cpio -pdv0 ../new
Delete all __temp__* directories under maximum 1 level down the current directory tree
find . -maxdepth 1 -type d -name '__temp__*' -print0 | xargs -0 rm -rf
Output two lines of "-tcp"
yes -- "-tcp" | head -n 2
Find files that end in ".gz" and execute "awk -F, '$1 ~ /F$/'" on their unzipped contents
find . -maxdepth 1 -name \*.gz -print0 | xargs -0 zcat | awk -F, '$1 ~ /F$/'
find all the directories in the current folder excluding search in the sub directories and create these directories in another path
find . -maxdepth 1 -type d | xargs -I X mkdir '/new/directory/X'
Copies all files under the current directory like any-cased '*foobar*' to the '~/foo/bar' directory.
find . -iname "*foobar*" -exec cp "{}" ~/foo/bar \;
Search non-recursively directory tree `MyApp.app' for directories whose name is 'Headers' and delete them in an optimized way
find MyApp.app -name Headers -type d -prune -exec rm -rf {} +
remote copy all text files from one location to another
find . -name '*.txt' -exec rsync -R {} path/to/dext \;
Search PATH for utilities called "rename", display the type of file (script, executable, ...) for each match found.
which -a rename | xargs file -L
Find all *.gz files in the current directory and decompress them using gunzip
find . -name '*.gz' -print0 | xargs -0 gunzip
find files in /dir/path/look/up directory that names are dir-name-here
find /dir/path/look/up -name "dir-name-here" -print
find symbolic links with pattern` '*sysdep.c'
find . -lname '*sysdep.c'
Search the current directory tree for files whose names end in "rb" or "js"
find . -regextype posix-egrep -regex ".*$"
List all files and directories residing in the current directory and below
find -print0 | xargs -0 ls
find all the php files
find -name '*.php'
Print sorted list of unique users logged in followed by a total count
who | awk '{ print $1; }' | sort -u | awk '{print $1; u++} END{ print "users: " u}'
search for text files in the folders /home/hobbes/ /home/calvin/
find /home/hobbes/ /home/calvin/ -name “*.txt”
Change the permission of all regular files under current directory tree to 644
find . -type f -exec chmod 644 {} \;
Find List of directory with non-zero file count
find -maxdepth 1 -type d | sort | while read -r dir; do n=$; if [ $n -gt 0 ]; then printf "%4d : %s\n" $n "$dir"; fi; done
Find all files in /home/kos and below whose names end in ".tmp"
find /home/kos -name *.tmp -print
delete a hard link and create a symbolic link to file named "$link"
ln -sf "$" "$link"
Give all files in the /path/to/base/dir tree read privileges
find /path/to/base/dir -type f -exec chmod 644 {} +
Split "/usr/bin/firefox" into 1000 files of about equal size
split -n 1000 /usr/bin/firefox
display a long listing of all regular files in current folder which have been modified in the last 60 minutes
find . -mmin -60 -type f -ls
Remove all files from the system whose path names contain "GUI"
find / -type f -print0 | xargs -0 grep -liwZ GUI | xargs -0 rm -f
Calculate md5 sum of file ${my_iso_file} and save it to variable 'md5'
md5=`md5sum ${my_iso_file} | cut -b-32`
Send each byte in "/home/cscape/Desktop/file" to awk script "x.awk"
fold -1 /home/cscape/Desktop/file | awk -f x.awk
Add a date time stamp to every line of output in "ping google.com"
ping google.com | xargs -L 1 -I '{}' date '+%c: {}'
Force pseudo-terminal allocation to run "sudo <cmd>" on "remotehost"
ssh -t remotehost "sudo <cmd>"
Print the empty directories and files under current directory
find -empty
Search the current directory tree for files whose names match regular expression '.*packet.*', ignoring the case
find . -iregex ".*packet.*"
Compress regular files in the current directory tree that were last modified more than 7 days ago
find . -type f -mtime +7 | tee compressedP.list | xargs compress
View lines 116 through 120 of history
history | head -n 120 | tail -n 5
Search directory tree `MyApp.app' for directories whose name is 'Headers' and delete them
find -d MyApp.app -name Headers -type d -exec rm -rf "{}" \;
Find text files modified less than 5 days ago
find . –name "*.txt" –mtime 5
Connect to host "$USER_AT_HOST" in master mode in the background without executing any commands and set the ControlPath to "$SSHSOCKET"
ssh -M -f -N -o ControlPath="$SSHSOCKET" "$USER_AT_HOST"
Find all files/directories under current directory tree that belong to the user 'tom'
find ./ -user tom
Print the names of the directories from the paths expanded by the glob pattern /path/to/directory/*
find /path/to/directory/* -maxdepth 0 -type d -exec basename -a {} +
Create a symbolic link named ".bash_profile" to ".bashrc"
ln -s .bashrc .bash_profile
Delete and count files in $DIR_TO_CLEAN that are older than $DAYS_TO_SAVE days
find "$DIR_TO_CLEAN" -type -f -mtime "+$DAYS_TO_SAVE" -exec rm {} \; -exec printf '.' \; | wc -c
Search for all files with either "sitesearch" or "demo" in their path names
find . | grep -i demo | grep -i sitesearch
List all hidden regular files from the current directory separating them with zeroes
find . -maxdepth 1 -type f -name '.*' -printf '%f\0'
Find all *.rb (regular) files under current directory and count their line numbers
find . -name "*.rb" -type f | xargs wc -l
find StringBuffer in all *.java files, ignoring case
find . -type f -name "*.java" -exec grep -il string {} \;
Show logged in users with idle time of each one
w | tr -s " " | cut -d" " -f1,5 | tail -n+3
Determine the user associated with stdin
who -m
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' \;
Execute "./my_script.sh" every 3 seconds and highlight the differences in successive runs
watch -n 3 -d ./my_script.sh
Move all *foo* directories under current directory to new paths obtained by replacing all occurrences of 'foo' with 'Bar' in their paths
find . -type d -iname '*foo*' -exec bash -O nocasematch -c '[[ $1 =~ ]] && mv "$1" "${1//${BASH_REMATCH[1]}/Bar}"' -- {} \;
Find all l files in the 'foo' folder but ones with name like '*Music*' to the 'bar' folder.
find foo -type f ! -name '*Music*' -exec cp {} bar \;