nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Make directory "/tmp/imaginary/" on remote host before archiving "file" to "user@remote:/tmp/imaginary/"
rsync -aq --rsync-path='mkdir -p /tmp/imaginary/ && rsync' file user@remote:/tmp/imaginary/
Remove all .txt files in and below the current directory
find . -name "*.txt" -exec rm {} \;
Delete all files under and below the current directory
find -mindepth 1 -delete
Find all files under current directory matching the pattern '[error,access,error_log,access_log,mod_jk.log]*.[0-9]*' in their names
find -name '[error,access,error_log,access_log,mod_jk.log]*.[0-9]*' -type f
Change permission to 755 for all directories under $d directory tree
find "$d/" -type d -print0 | xargs -0 chmod 755
Convert all *.ps files under $STARTDIR directory to *.pdf files
find $STARTDIR -name '*.ps' -print | sed -e 's/.ps$//' | xargs -l -i ps2pdf '{}.ps' '{}.pdf'
simulate a full login of user root
su -
Exclude directory from find . command
find build -not \( -path build/external -prune \) -name \*.js
View line 500 to line 1000 in gzipped file "bigfile.z"
zcat bigfile.z | sed -ne '500,1000 p'
Find files with 002 permission in entire file system
find / -type f -perm -002
Run "command" on server "host" as user "user"
echo "command" | ssh user@host
delete all the files in the current folder which do not belong to any user
find . -nouser | xargs rm
Cut all remote paths from HTTP URLs received from standard input keeping only the protocol identifier and host name, of the form http://example.com
sed -n 's;\/.*;\1;p'
Recursively add read and execute permissions to all files and folders in "directory"
chmod -R +xr directory
Finds file 'Subscription.java' and changes to containing folder.
cd `find . -name Subscription.java | xargs dirname`
Prints the file path composed from the path where symlink target file is located, and name of the symbolic link itself.
echo "$(dirname $)/$"
search for all the files in the folder /data/images which have been modified after /tmp/start and before /tmp/end
find /data/images -type f -newer /tmp/start -not -newer /tmp/end
Apply script rename.sh to all files from the current directory tree whose names match regular expression "xxx-xxx_[a-zA-Z]+_[0-9]+_[0-9]+\.jpg$"
find . -regex "xxx-xxx_[a-zA-Z]+_[0-9]+_[0-9]+\.jpg$" -exec ./rename.sh "{}" ";"
Find all files in the current directory tree whose size is greater than 1MB, and move them to the "files" folder with confirmation
find . -size +1M -ok mv {} files \+
Find empty files/directories under test directory
find test -empty
display all the files in the folder /home which do not belong to the group test
find /home -not -group test
Save first one of space separated parts of each line in $LOCKFILE file to the 'CURRENT_PID_FROM_LOCKFILE' variable
CURRENT_PID_FROM_LOCKFILE=`cat $LOCKFILE | cut -f 1 -d " "`
display all the hidden directories in the directory "/dir/to/search/"
find /dir/to/search -path '*/.*' -print
Delete all files/directories taken by the glob pattern * except the ones with the name 'b'
find * -maxdepth 0 -name 'b' -prune -o -exec rm -rf {} \;
Exclude directory from find . command
find ! -path "dir1" -iname "*.mp3"
Prints logged in users in sorted order.
w | sort
Search the current directory recursively for regular files last accessed less than 2 days ago
find . type -f -atime -2
Search regular files from the /path/to/dir directory tree for lines that contain "_START" and are enclosed in lines "@GROUP" and "@END_GROUP"
find /path/to/dir -type f -exec sed '/@GROUP/,/@END_GROUP/!d' {} + | grep '_START'
Remove all *.txt files under the given directory modified more than 5 minutes ago
find /home/u20806/public_html -maxdepth 1 -mmin +5 -type f -name "*.txt" -delete
Replace all newlines from standard input except the last with spaces
sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/ /g'
search for all the file sin the current folder which are bigger than 10KB and display them smallest file
find . -size +10k -exec ls -lS {} \+ | head -1
Copy all files with '.png' (case insensitive) extension under '/home/mine' directory tree to '/home/mine/pngcoppies/copy.' directory
find /home/mine -iname "*.png" -execdir cp {} /home/mine/pngcoppies/copy{} \;
Saves logged in users names in 'tmp' variable.
tmp=$
List only the non-hidden empty files only in the current directory.
find . -maxdepth 1 -empty -not -name ".*"
Compare *.csv files in the current directory tree with their analogs stored in /some/other/path/ prompting before running `diff'
find . -okdir diff {} /some/other/path/{} ";"
Numerically sort each line in file "out" and print the result to console
sort -n out
Print the contents of "$FILE" starting from line 2
tail -n +2 "$FILE"
Recursively finds 'pattern' in files from current folder, and prints matched string with number only if matching whole word.
grep -rnw "pattern"
search for regular/normal file with the name "myfile" in the entire file system
find / -name myfile -type f -print
Print all file/directory names with white space safety under the /proc directory
find /proc -print0 | xargs -0
Print summary of new/missing files, and which files differ between dir1 and dir2.
diff -q dir1 dir2
find all the directories in the current folder
find -type d
Replace all occurrence of "subdomainA.example.com" with "subdomainB.example.com" in all files under the current directory and below ignoring SVN files
find . \( ! -regex '.*/\..*' \) -type f -print0 | xargs -0 sed -i 's/subdomainA.example.com/subdomainB.example.com/g'
find files which have all permissions to all the users in the current directory
find . -type f -perm 0777 -print
List files and directories recursively
find . -print | xargs ls -gilds
Find files/directories under current directory and print them as null terminated strings.
find -print0
display all the regular/normal files in the current folder excluding the files "bbb" and "yyy"
find . \( -name bbb -o -name yyy \) -prune -o -type f -print
Search the current directory recursively for text files containing at least one character
find -type f -exec grep -Iq . {} \; -and -print
Find all files in the /etc folder that have been modified within the last 30 days and copy them to /a/path/.
find /etc/ -mtime -30 | xargs -0 cp /a/path
Find all directories under media/ directory and change their permission to 700
find media/ -type d -exec chmod 700 {} \;
Find all directories named "0" in the current directory tree and create a single tar archive of their RS* subdirectories
find . -type d -name "0" -execdir tar -cvf ~/home/directoryForTransfer/filename.tar RS* \;
display all jpg files in the current folder
find -iname "*.jpg"
only get md5sum of a file
md5 -q file
Search the entire file hierarchy for any file that begins with zsh and exists on the ext3 file systems.
find / -fstype ext3 -name zsh*
Lists all files in a current folder, separating names with comma.
ls -1 | tr '\n' ',' | sed 's/,$/\n/'
Search for the files that are owned by user rooter or by user www-data
find -user root -o -user www-data
Prints server name from SOA record for domain yahoo.com
dig +noall +answer soa yahoo.com | awk '{sub(/.$/,"",$5);print $5}'
set alias "j7" for command 'JAVA_HOME=`/usr/libexec/java_home -v 1.7`'
alias j7='JAVA_HOME=`/usr/libexec/java_home -v 1.7`'
Find all files whose names begin with 'Makefile' in the /usr/ports directory tree and count how many of them contain 'QMAKESPEC'
find /usr/ports/ -name Makefile\* -exec grep -l QMAKESPEC '{}' '+' | wc -l
Find all the regular files under '/your/dir' directory tree which are bigger than 5 MB and display them in decreasing order of their sizes
find /your/dir -type f -size +5M -exec du -h '{}' + | sort -hr
Search for 'It took' in all $srch1* files under current directory and run the sed script 'N;s/\n/\2 \1/' on the output and redirect the final output to temp1 file
find . -iname "$srch1*" -exec grep "It took" {} \; -print |sed -r 'N;s/\n/\2 \1/' > temp1
display the contents of all the files in the current folder which have the name "dummy" and discard all the errors while searching and save the output to the file tesst.txt
find / -type f -name dummy 2>/dev/null -exec cat {} \; >tesst.txt
Execute script 'truncate.sh' on all files in the /path/to/files directory tree
find /path/to/files -exec truncate.sh {} \;
find all the files that have been modified in the last 4 days ( daystart is used to check files according to date i.e, all files modified from currentDay-4 00:00:00 to current day) and copy them to folder.
find . -mtime 4 -daystart -exec cp -a {} /home/devnet/fileshare\$ on\ X.X.X.X/RECOVER/ \;
find md5sum of 401
yosemite$ echo -n 401 | md5
Find all files/directories under '/usr/share/doc' directory tree that contain 'readme' at the beginning of their names
find /usr/share/doc -iname readme\*
Prints week day of a 31 day in a current month.
cal | awk -v date=31 'NR == 2 { split($0, header) } NR > 2 { for (i = 1; i <= NF; ++i) if ($i == date) { print header[NR == 3 ? i + 7 - NF : i]; exit } }'
check if myfile has 0644 permissions
find myfile -perm 0644 -print
Shows status of a shell option 'compat31'.
shopt compat31
List all regular files in and below the home directory that have been modified in the last 90 minutes
find ~ -type f -mmin -90 | xargs ls -l
Find all symbolic links containing 'vim' in their names uder '/usr/bin' directory tree
find /usr/bin -name '*vim*' -type l
Find all *conf* files recursively under current directory, search for any lines matching the string 'matching_text' in those files and redirect the output to matching_text.conf.list
find . -name *conf* -exec grep -Hni 'matching_text' {} \; > matching_text.conf.list
find all of the executable files on your computer
find / -executable
test if the 2nd column in file A is in the reverse order of the second column of file B
diff --brief < <
List all active cron jobs, displaying only the command.
crontab -l | grep -v "^#" | awk '{print $6}'
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'
Remove the line matching "pattern to match" in "./infile" and print to standard output
sed '/pattern to match/d' ./infile
Find files/directories named 'foo.bar' in the root filesystem partition
find / -name foo.bar -print -xdev
Merge colon-separated information from standard input and file1.txt where the first field of both files matches, print unpairable lines from both files, replace missing fields with "no-match", and output the second field from standard input and the second and third field from file1.txt
join -t, -o 1.2,2.2,2.3 -a 1 -a 2 -e 'no-match' - <
Find recursively the latest modified file in the current directory
find . -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" " | sed 's/.*/"&"/' | xargs ls -l
Remove all empty regular files under the current directory and below
find ./ -type f -empty -print0 | xargs -0 rm
Read a single character from standard input with delimeter '' and no echo
read -d'' -s -n1
Find all the regular files under $DIR directory tree which have been modified before the file $a excluding the file $a and delete them
find "$DIR" -type f \! -newer "$a" \! -samefile "$a" -exec rm {} +
Find 10 largest files in the current directory and its subdirectories
du -hsx * | sort -rh | head -10
List all files from the current directory tree that were modified less than 60 minutes ago
find . -mmin -60 | xargs -r ls -l
Recursively finds all files with whole word "pattern" in a current folder, and precedes found string with its number in file.
grep -rnw `pwd` -e "pattern"
Print newline, word, and byte counts of each '*.java' file within current directory, and total newline, word, and byte counts
find . -name \*.java | tr '\n' '\0' | xargs -0 wc
Remove adjascent duplicate lines from file 'input' comparing all but last space-separated fields
rev input | uniq -f1 | rev
replace the word apple with orange in all the files in the current folder
find ./ -exec sed -i 's/apple/orange/g' {} \;
Tmux configuration to enable mouse support within tmux
set -g mouse on
Convert multiple *.jpg files from JPEG to PDF format
find /path/to/files -iname '*.jpg' -exec mogrify -format pdf {} +
Read a line from standard input into variable "response" without backslash escapes using the prompt "About to delete all items from history that match \"$param\". Are you sure? [y/N] "
read -r -p "About to delete all items from history that match \"$param\". Are you sure? [y/N] " response
Search the regular files from directory tree 'folder_name' for "your_text"
find folder_name -type f -exec grep your_text {} \;
Check if the contents of file "subset" is a subset of file "set"
comm -23 <(sort subset | uniq) <(sort set | uniq) | head -1
Find files/directories in entire file system that were modified a day ago
find / -mtime 1
Prints git log message with a custom time format string
date -d @$ +%Y%m%d%H%M
Count the number of characters in the list of regular files from the current directory tree
find . -type f | xargs | wc -c
Save a comma separated list of all directories under current directory tree to variable 'FOLDER'
FOLDERS=$
display all the text files in the current folder except readme files
find . -type f -name "*.txt" ! -name README.txt -print
Find regular non-hidden files containing `some text' in their names with hidden directories optimization
find . -type d -path '*/\.*' -prune -o -not -name '.*' -type f -name '*some text*' -print