nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Show file type information for all regular files under '/home' directory tree
find /home -type f -exec file {} \;
Search directories /res/values-en-rUS and /res/xml for XML files
find /res/values-en-rUS /res/xml -iname '*.xml'
Find all *.plist files/directories under current directory
find ./ -name "*.plist"
Find all directories under /directory-path and change their permission to 2755
find /directory-path -type d -exec sudo chmod 2775 {} +
Find directories in the /path directory tree whose names are 33 characters in length
find /path -type d -printf "%f\n" | awk 'length==33'
find all the directories in current folder and do not search in sub directories
find . -maxdepth 1 -type d -print0
Find files/directories that does not have write permssion for group
find /path ! -perm /020
Find all SUID files .
find / -perm /u=s
Archive all *html files using tar.
find . -type f -name "*html" | xargs tar cvf htmlfiles.tar -
Sort all directories under current directory placing the file with least modification time at first
find -type d -printf '%T+ %p\n' | sort
Find the first file/directory named 'something' under current directory and quit
find . -name something -print -quit
Delete all files in the /myDir directory tree that were last modfied 7 days ago
find /myDir -mindepth 1 -mtime 7 -delete
display all file names in current folder
find . -printf '%p '
Search the /root directory recursively for files named "FindCommandExamples.txt"
find /root -name FindCommandExamples.txt
find all the files ending with ".sh" in the folder /dir excluding those wth the name node_modules and search for a pattern in these files
find /dir \ -o -name "*.sh" -exec grep --color -Hn "your text to find" {} 2>/dev/null \;
find all the directories in the current folder and create the same directory structure in a remote machine using ssh
find -type d | ssh server-B 'xargs -I% mkdir -p "/path/to/dir/%"'
Save the "Pictures" directory in the current user's home directory on the directory stack
pushd /home/`whoami`/Pictures
Delete files in /var/tmp/stuff and below that have not been modified in over 90 days
find /var/tmp/stuff -mtime +90 -exec /bin/rm {} \;
Remove duplicate phrases and keep the original order of lines in "$infile"
nl -w 8 "$infile" | sort -k2 -u | sort -n | cut -f2
Converts all windows line endings to unix line endings
find $ -type f | xargs -I xxx sed -i 's/\r//g' xxx
Search for all .html files in directory "www" and output only the basename of each.
find www -name \*.html -type f -exec basename {} \;
Copy all .txt files from the dir/ directory tree along with their parent directories hierarchy
find dir/ -name '*.txt' | xargs cp -a --target-directory=dir_txt/ --parents
Find all the files in file system which are modified in last 1 hour
find / -mmin -60
change the group of all the files in the file system which belong to the group with the gid 999
find / -group 999 -exec chgrp NEWGROUP {} \;
List all files under current directory
find . -type f | xargs ls
Use the PHP interpreter to output an endless stream of "a" characters to "nohup.out" in the current directory, or in the home directory if that is not possible. The PHP process will not receive or respond to SIGHUP which are sent to it.
nohup php -r 'while { echo "a";}' &
Creates temporary folder relative to directory '/path/to/dir'.
mktemp -d -p /path/to/dir
Find files newer than main.css in ~/src
find ~/src -newer main.css
Delete all __temp__* files/directories under current directory tree
find . -name __temp__* -exec rm -rf '{}' \;
Find all *.py files under current directory
find . -type f -name "*.py"
Split "bigfile" into files of at most 1000 lines each with prefix "/lots/of/little/files/here"
split bigfile /lots/of/little/files/here
Display the content of file "f" in home directory if it exists and is executable
cat `which ~/f`
Search the file system for regular files whose names are shorter than 25 characters
find / -type f| egrep -o "/[^/]{0,24}$" | cut -c 2-
search for the word "nameserver" in all the regular/normal files in the /etc directory and display the name of the file along with the matched line
find /etc/ -iname "*" -type f -print0 | xargs -0 grep -H "nameserver"
Convert "/usr/share/man/man1/man.1.gz" to html
zcat /usr/share/man/man1/man.1.gz | groff -mandoc -Thtml
Overwirte file '/path/to/your/file' with zeroes and remove, showing progress while execution.
shred -v -n 0 -z -u /path/to/your/file #overwriting with zeroes and remove the file
Find all files which are accessed after modifying /etc/passwd files.
find -newer /etc/passwd
Print 'echo 'hello, world'
echo 'hello, world' | cat
search for a word in all the regular/normal files in the entire filesystem. ( + is used to give more than one file as input to the grep command.
find / -type f -exec grep -i 'the brown dog' {} +;
Find all the files/directories under '/var/adm' directory tree that have not been modified in the last 3 days
find /var/adm -mtime +3 -print
Find all files under current directory and pipe their contents to the wordfrequency command and then search for 'yourword' in the output
find . -type f | xargs cat | wordfrequency | grep yourword
Remove all files except the ones listed in "MANIFEST"
find -type f -printf %P\\n | sort | comm -3 MANIFEST - | xargs rm
Read a line of standard input in an interactive shell
read -e
Set permissions to 600 for regular files under var/
find var/ -type f -exec chmod 600 {} \;
Find all files/directories under current directory that match the case insensitive regex ./\_.*
find . -iregex './\_.*'
Print local files without descending non-local directories
find . ! -local -prune -o -print
Find all files in the current directory recursively with "linkin park" in their names and copy them to /Users/tommye/Desktop/LP
find . -type f -iname "*linkin park*" -exec cp -r {} /Users/tommye/Desktop/LP \;
Abort the shell or script on the first failed command
set -e
Remove trailing white spaces from all *.rb, *.html, *.js, *.coffee, *.css, *.scss, *.erb, *.yml, *.ru files under current directory
find . \ -print0 | xargs -0 sed -i '' -E "s/[[:space:]]*$//"
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
Reports count of characters in the value of ${FOO_NO_EXTERNAL_SPACE} variable as follows: "length==<counted number of characters>"
echo -e "length==$"
Find StringBuffer in all *.java files
find . -type f -name "*.java" -exec grep -l StringBuffer {} \;
Find and show all files on the system that are larger than 900 MB
find / -size +900M
Run 'join' with the number-sorted output of file1 and file2, without modifying file1 or file2: for each line with a common first field in file1 and file2, output the common field followed by the extra fields in both files.
join <(sort -n file1) <(sort -n file2)
Find all files/directories under whatever and ... directory and copy them to /var/tmp
find whatever ... | xargs -d "\n" cp -t /var/tmp
Puts working directory into clipboard, stripping newlines
pwd | tr -d '\n' | pbcopy
Print the first word followed by the rest of the line formatted to fit in 100 characters for every line in "input"
sed 's/\([^ ]*\) /\1\n/' input | fold -w 100
Sort all directories under current directory placing the file with least modification time at first
find -type d -printf '%T+ %p\n' | sort
Find files matching pattern $2 in the $1 directory recursively and search them for text $3, where $1, $2, $3 are the command line arguments to the Bash script
find $1 -path /proc -prune -o -name "$2" -print -exec grep -Hn "$3" {} \;
search all undo files(ending with .undo) in the current folder and calculate the total size of them
find -name '*.undo' -exec wc -c {} + | tail -n 1
Find all files/directories with '.pdf' extension excluding 'pdfs' directory and all of its contents
find . -name "*.pdf" -print | grep -v "^\./pdfs/"
Find all the files in file system which are accessed in last 1 hour
find / -amin -60
Find all ES* and FS_* files under current directory
find . -type f \( -iname "ES*" -o -iname "FS_*" \)
prune all the files in the current directory, only current directory is the output
find . -prune
Find all .mp3 files with more than 10MB and delete them
find / -type f -name *.mp3 -size +10M -exec rm {} \;
Create archive "backup1.tar" of all subdirectories of the current directory
find . -mindepth 1 -maxdepth 1 -type d | awk 'BEGIN {FS="./"}; {print $2}' | xargs -d '\n' tar czf backup1.tar
Output all lines in 'file' which contain a tab character.
awk -F"\t" 'NF>1' file
List files under $CURR_DIR which were modified, accessed or whose status were changed $FTIME ago replacing the $CURR_DIR path string to './'
find ${CURR_DIR} -type f \ -printf "./%P\n"
Find all files named 'new' under current directory tree and display their contents
find . -name new -print -exec cat {} \;
Archive all filepattern-*2009* files/directories under data/ into 2009.tar
find data/ -name filepattern-*2009* -print0 | xargs -0 tar uf 2009.tar
Display only mimetype of myfile.txt, without the filename.
file -bi myfile.txt
display all the files in the usr folder and those that are in the path local
find /usr/ -path "*local*"
Split file 'afile' into parts as of two lines per each and compress each part with 'bzip2'
cat afile | split -l 2 --filter='bzip2 > "$FILE.bz2"'
Delete all .svn files/directories under current directory
find . -name .svn -exec rm -v {} \;
Find all *stat files/directories under /usr
find /usr -name *stat
Read a single character from standard input with prompt "Are you sure? "
read -p "Are you sure? " -n 1 -r
List all leaf directories of the current directory tree
find . -type d -execdir sh -c 'test -z "$" && echo $PWD/{}' \;
Find all files/directories under current directory with the null character as the delimiter
find -print0
Sort file "a.csv" by the first comma separated value of each line and print only unique entries
tac a.csv | sort -u -t, -r -k1,1 |tac
Extract five digits sequence from a filename with x number of alphanumeric characters followed by the five digit sequence surrounded by a single underscore on either side then another set of x number of alphanumeric characters.
echo 'someletters_12345_moreleters.ext' | cut -d'_' -f 2
Counts all files in a current folder and in subfolders one-level lower, sorts result and pipes to the less pager.
find . -maxdepth 1 -type d -print0 | xargs -0 -I {} sh -c 'echo $ \\t {}' | sort -rn | less
Lists all paths to all subfolders in a current folder.
ls -mR * | sed -n 's/://p'
Check whether "$path_in_question" is a mount point
df $path_in_question | grep " $path_in_question$"
Find files/directories named 'filename' in the entire filesystem
find / -name filename -print
Find files matching the regex 'myregex' in their contents and append the list of these files to outfile.txt
find . -exec grep -l -e 'myregex' {} \; >> outfile.txt
set MyVariable to the value of VARIABLE_NAME
myVariable=$(env | grep VARIABLE_NAME | grep -oe '[^=]*$');
Find files with inode number 199053
find / -inum 199053
Rename all files in current directory whose name starts with 'F0000', trimming a zero from any sequence of four zeroes in the name.
rename s/0000/000/ F0000*
Returns exit status 0 and prints exit status of previous command.
false | echo "${PIPESTATUS[0]}"
Find files named 'core' in or below the directory /tmp and delete them
find /tmp -name core -type f -print0 | xargs -0 /bin/rm -f
Print a count of all unique lines in "ports.txt" sorted from most frequent to least frequent
sort ports.txt | uniq -c | sort -r
find all files in the current directory whose size is 24 or 25 bytes.
find . -size -26c -size +23c -print
Append the date and command ran to "/tmp/trace" after every command
PROMPT_COMMAND='echo "$(date +"%Y/%m/%d (%H:%M)") $(history 1 |cut -c 7-)" >> /tmp/trace'
Remove all files from the current directory tree whose names do not end with ".tex" or ".bib"
find . | egrep -v "\.tex|\.bib" | xargs rm
Counts number of lines with 'OK' in file 'filename'.
grep "OK" <filename> | wc -l
Prints help on 'cp' utility.
cp --help
Continuously send "y" as input to "./MyScript.sh" and ignore standard error
yes 2>/dev/null | ./MyScript.sh
display all files in current folder and follow the symbolic links and display the pointed file
find -L .
Find all .java files under and below the current directory
find . -name '*.java'
Calculate the md5 sum of all files in "/your/dir" including content and filenames and following symbolic links
grep -aR -e . /your/dir | md5sum | cut -c-32