nl_command
stringlengths 14
387
| bash_code
stringlengths 0
532
|
---|---|
Find all directories under '.cache/chromium/Default/Cache' that are bigger than 100 MB in size excluding single letter directory names | find .cache/chromium/Default/Cache/ -type d -print0 | du -h | grep '[0-9]\{3\}M' | cut -f2 | grep -v '^.$' |
find all the files that have been modified today(from the strart of the day) | find . -type f -daystart -mtime 0 |
Set variable "fname" to the basename of path specified in variable "f", that is remove everything up to the last slash if present. | fname=`basename $f` |
change the group of all the files in the folder /u/netinst/ to staff | find /u/netinst -print | xargs chgrp staff |
Find how many directories are in a path (counts current directory) | find . -type d -exec basename {} \; | wc -l |
Set variable "b" to the first word of "a" converted to uppercase. | b=`echo "$a" | awk '{ print toupper($1) }'` |
find all regex ".*/[a-f0-9\-]\{36\}\.jpg" files | find . -regextype sed -regex ".*/[a-f0-9\-]\{36\}\.jpg" |
Find all regular files under and below /home/user/demo/ | find /home/user/demo -type f -print |
remove all the DS_Store files in the current directory | find . -name .DS_Store -exec rm {} \; |
Find ".c" and ".h" files in the current directory tree and print line numbers and lines containing "#include" | tree -if | grep \\.[ch]\\b | xargs -n 1 grep -nH "#include" |
Find all directories under var/ directory and change their permission to 700 | find var/ -type d -exec chmod 700 {} \; |
Update the archive '2009.tar' with the files from the data/ directory tree that match pattern 'filepattern-*2009*' | find data/ -name filepattern-*2009* -print0 | xargs -0 tar uf 2009.tar |
Print the file content of command "[whatever]" | cat `find [whatever]` |
display a long list of all the directories which have files ending with ".todo" | find "$STORAGEFOLDER" -name .todo -printf '%h\n' | xargs ls -l |
Copy file 'src' to 'dest', except if 'dest' already exists. | cp -n src dest |
find all regular/normal files which have execute permission in current folder and copy them to another folder | cp `find -perm -111 -type f` /usr/local/bin |
Change owner of "folder" to "user_name" | chown user_name folder |
Exchanges the top two directories in the dirs stack. | pushd |
Get a recursive file list of directory $dir | find $dir -type f |
Replace all spaces with underscores in directory names under current directory. | find /tmp/ -depth -name "* *" -execdir rename 's/ /_/g' "{}" \; |
Forward port 8000 bound on localhost to port 22 in 'clusternode' via 'user@bridge' | ssh -L localhost:8000:clusternode:22 user@bridge |
Continuously send "y" to all prompts of command "rm" | yes | rm |
Print standard input to standard output line by line, discarding any adjascent duplicate lines. | uniq |
create directory /tmp/new | mkdir /tmp/new |
display all the files in the entire file system which have set uid bit set. | find / -perm -u+s -print |
find all the files in the folder /opt which have been changed in the last 120 minutes | find /opt -cmin -120 |
find all files in and under the current directory that have read, write and execute permissions set for all users. | find . -perm 777 -print |
Find all .gz archives in the current directory tree and check if they are valid | find . -name '*.gz' | xargs gunzip -vt |
find all the header files in /usr/include which have been modified in the last 400 days | find /usr/include -type f -mtime -400 -name "*.h" |
Unset the DISPLAY variable | unset DISPLAY |
List all non-hidden files in ~/junk | find ~/junk -name "*" -exec ls -l {} \; |
find regular files in the current directory, without descending into sub-directories and display as a null separated list. | find -maxdepth 1 -type f -printf '%f\000' |
Find only permission field & file name from long listing with find command . | find -type f -iname "*.txt" -exec ls -lrt {} \;|awk -F' ' '{print $1 $9}' |
display all the files in the current directory and do not search in the sub directories | find . -maxdepth 0 -print |
Change permissions of all directories from the current directory tree to 644 | find . -type d -exec chmod 755 {} + |
Print a sorted list of the extensions of the regular files from the current directory tree | find . -type f | grep -o -E '\.[^\.]+$' | sort -u |
Search for occurrences of string "main(" in the .c files from the current directory tree | find . -type f -name "*.c" -print -exec grep -s "main(" {} \; |
Archive directory "symdir" to "symdir_output" preserving symbolic links. | rsync symdir/ symdir_output/ -a --copy-links -v |
List each file or directory in the current directory prefixed by its filesize in bytes and sorted from smallest to largest | du -a --max-depth=1 | sort -n |
Display information about number of processes in various states. | top -bn1 | grep zombie |
Saves exit statuses of piped commands in a system variable PIPESTATUS='([0]="0" [1]="0" [2]="1" [3]="0" [4]="1")' | true | true | false | true | false |
Find files using file-name | find -iname "MyCProgram.c" |
display the help of find command | find --help |
Find all files in the current directory tree whose names are "file_name", except for those with pathnames matching pattern "./dirt to be Excluded/*" | find ./ -iname file_name ! -path "./dirt to be Excluded/*" |
Save number of lines in 'file.txt' file in 'nbLines' variable | nbLines=$ |
Set the shell option 'errexit' causing bash to exit immediately if one of the commands in a multi-command statement fails. | set -e |
List all files and folders in the current working directory | ls `pwd`/* |
find all the files in the current folder which have been accessed in the last 60 minutes | find . -amin -60 |
Prints first found folder that contains 'ssh' file and has 'bin' in path. | dirname `find / -name ssh | grep bin | head -1` |
Change directory to parent directory and do not resolve any symlinks in the resulting path | cd -L .. |
remove all the files in the current folder which have not been modified in the last 10 days | find . -mtime +10 | xargs rm |
find all the JSON files in the directory "PROD/140725_D0" and send them as input to the python script "/tmp/test.py" | find /PROD -type d -execdir sh -c 'for f in *.json; do /tmp/test.py "$f"; done' \; |
SSH into "hostname" on port 22 as user "myName" | ssh -l myName -p 22 hostname |
list all files under $dir directory except path $dir/prune_me directory | find "$dir" -path "$dir/prune_me" -prune -o -exec bash -c 'echo "$0"' {} \; |
List all .c and .h files in the current directory tree that contain "thing" | find . -name '*.[ch]' -print0 | xargs -r -0 grep -l thing |
find all the normal/regular files in the current folder which have been modified in the last day and display a long listing of them | find . -type f -mtime -1 -daystart -exec ls -l {} \; |
Search for files/directories with the case insensitive pattern anaconda.* in var/log directory and create an archive of all the files found | tar -cvf file.tar `find var/log/ -iname "anaconda.*"` |
Print your/dir if it's empty | find "your/dir" -prune -empty |
Find '*prefs copy' files under /mnt/zip and delete them with confirmation prompt ensuring white space safety | find /mnt/zip -name "*prefs copy" -print0 | xargs -0 -p /bin/rm |
Print relative path of device of disk with UUID "b928a862-6b3c-45a8-82fe-8f1db2863be3" | readlink /dev/disk/by-uuid/b928a862-6b3c-45a8-82fe-8f1db2863be3 |
Find all regular files with '.jpg' (case insensitive) extension, sort them by name, print the output and also save the list to file 'file_list.txt' | find . -type f|grep -i "\.jpg$" |sort| tee file_list.txt |
Print differences between the sorted content of file $1 and file $2, executing 'diff' with options from "${@:3}" array slice | diff "${@:3}" < < |
start from current directory, skip the directory src/emacs and print it then skip all files and directories under it, and print the names of the other files found | find . -wholename './src/emacs' -prune -print -o -print |
Find all file.ext files/directories under current directory with "FooBar" in their paths and copy them into the current directory | find . -name "file.ext"| grep "FooBar" | xargs -i cp -p "{}" . |
start 2 sleep processes in the background | sleep 100 | sleep 200 & |
replace the word foo to bar in the current folder in all the regular/normal files containing the word "baz" in their name | find . -type f -name "*baz*" -exec sed -i 's/foo/bar/g' {} + |
Delete orphan vim undo files under current directory | find . -type f -iname '*.un~' | while read UNDOFILE ; do FILE=$( echo "$UNDOFILE" | sed -r -e 's/.un~$//' -e 's&/\.&/\1&' ) ; [[ -e "$FILE" ]] || rm "$UNDOFILE" ; done |
Save "XXX-" followed by a random 4 byte unsigned integer to variable "tempfile" | tempfile=XXX-$ |
Print the base name of the current working directory | basename `pwd` |
Compress every file in the current directory that matches "*cache.html" and keep the original file | gzip -k *cache.html |
find all the files that have been modified today | find /tmp/test/* -mtime +0 |
delete all the ".bak" or swap files in kat folder | find kat -type f \( -name "*~" -p -name "*.bak" \) -delete |
Copy all *.mp3 files under the current directory to /tmp/MusicFiles/ | find . -type f -name "*.mp3" -exec cp {} /tmp/MusicFiles \; |
Concatenate with a space every other line in "input.txt" | paste -s -d' \n' input.txt |
Find all files whose names begin with 'Makefile' at the /usr/ports directory tree's level 3 and count the number of lines with NOPORTDOCS or NOPORTEXAMPLES in them. | find /usr/ports/ -name Makefile\* -mindepth 3 -maxdepth 3 -exec egrep "NOPORTDOCS|NOPORTEXAMPLES" '{}' '+' | wc -l |
List every directory under current directory with their child executable files | find `pwd` -perm 111 -type f | sort -r | xargs -n1 -I{} sh -c "dirname {};basename {}" | awk '/^\// {dir=$0 ; if {print;lastdir=dir}} !/^\// {print}' |
Print the grand total file system disk space usage with block sizes in units of TiB | df --total -BT | tail -n 1 |
Send SIGTERM signal to all process whose username is "username" and whose command is "your_command". | ps -o uid,pid,cmd|awk '{if print $2}'|xargs kill -15 |
Finds if 'subversion' package is installed in system. | yum list | grep subversion |
Search all files in the current directory tree whose names contain "." for "SearchString" | find . -name '*.*' -exec grep 'SearchString' {} /dev/null \; |
Find all directories under 'test' directory tree whose paths match the regex '.*/course[0-9]\.[0-9]\.[0-9]\.[0-9]$' | find test -type d -regex '.*/course[0-9]\.[0-9]\.[0-9]\.[0-9]$' |
Find all mysong.ogg files/directories under your home directory | find $HOME -name 'mysong.ogg' |
Find all foo.mp4 files in the current directory tree and print the pathnames of their parent directories | find . -name foo.mp4 -printf '%h\n' |
Returns exit code 1 and terminates shell if 'set -e' was applied. | a=$(false) |
Find all *company* (case-insensitive) files/directories under /basedir with null character as the delimiter | find /basedir/ -iname '*company*' -print0 |
find all the text files in current folder and force delete them | find . -name "*.txt" | xargs rm -rf |
Find all regular files with '.jpg' extension, sort them by name, print the output and also save the list to file 'file_list.txt' | find . -type f|grep -i "\.jpg$" |sort| tee file_list.txt |
Copies 'libgtest_main.so' and 'libgtest.so' to '/usr/lib/', preserving all attributes, and copying symlinks as symlinks, without following in source files. | sudo cp -a libgtest_main.so libgtest.so /usr/lib/ |
Search for the case insensitive regex 'STRING_TO_SEARCH_FOR' in all files under current directory | find . -type f -exec grep -n -i STRING_TO_SEARCH_FOR /dev/null {} \; |
Get the total size of all files under dir1 directory | find dir1 ! -type d -printf "%s\n" | awk '{sum += $1} END{print sum}' |
Find all files under current directory and change their permission to 400 | find . -type f -exec chmod 400 {} \; |
Spawn a background screen session running myCommand | screen -d -m sh -c "while :; do ./myCommand; done;" |
Go to directory /cygdrive/c/Program Files using backslashes to escape special characters | cd /cygdrive/c/Program\ Files\ \ |
Execute script do1.sh on each regular file from the /etc directory tree | find /etc -type f | xargs --max-lines=1 -r --max-procs=20 ./do1.sh |
find all files in the file system which are modified after the file /tmp/checkpoint | find / -newer /tmp/checkpoint |
Archive the directory structure under .. directory into dirstructure.tar | find .. -type d -print0 | xargs -0 tar cf dirstructure.tar --no-recursion |
Search for the regex '->get(\|#hyphenate' in all files with '.pl' or '.pm' extension under '/users/tom' directory tree and only show the filenames | find /users/tom -name '*.p[lm]' -exec grep -l -- '->get(\|#hyphenate' {} + |
Generates name for temporary file with 6-letter suffix, and saves path to that new file in 'fn' variable. | fn=$ |
Copy file or folder linked to by "file" to "file" | cp -rf --remove-destination `readlink file` file |
find files which full path name is foo/bar under foo directory and print | find foo -path foo/bar -print |
Subsets and Splits