nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Search /usr/bin for regular files that have been modified within the last 10 days
find /usr/bin -type f -mtime -10
Compare files in "/tmp/dir1" and "/tmp/dir2", treating absent files as empty and all files as text
diff -Nar /tmp/dir1 /tmp/dir2/
Make directories and parents as needed for each file path in "a.txt" excluding the basename for each path
cat a.txt | grep / | sed 's|/[^/]*$||' | sort -u | xargs -d $'\n' mkdir -p
Search the entire file hierarchy for files larger than 100 megabytes and delete them.
find / -size +100M -exec /bin/rm {} \;
Remove all files with names like "vmware-*.log" from the current directory tree
find . -name "vmware-*.log" -exec rm '{}' \;
Find all thumb.png files in the temps/ directory tree
find temps/ -name "thumb.png"
List all regular files under current directory
find . -type f -print | xargs -n 1
Look for any instance of "ds1337" in the modules.alias file matching current kernel release
grep ds1337 /lib/modules/`uname -r`/modules.alias
Print each line in "set1" and "set2" that does not exist in the other
sort set1 set2 | uniq
Make directories "es/LC_MESSAGES" as needed and do not error if it exists
mkdir -p es/LC_MESSAGES
Search for files with "sitesearch" in their names and "demo" in their path names
find . -iname '*sitesearch*' | grep demo
Find all *.jpg files under current directory and print only unique names
find . -name \*.jpg -exec basename {} \; | uniq -u
show all the files in the current folder which has the word "ITM"
find . -name ‘*ITM*’
display the directory name along with the modified time for all the files /var
find /var -maxdepth 2 -type d -exec stat -c "%n %y" {} \;
Numerically sort file "file.dat" by the second word of each line and output from greatest value to least value
sort -nk 2,2 file.dat | tac
Find files in $DIR_TO_CLEAN that are older than $DAYS_TO_SAVE days and print them with null character appended to their paths
find "${DIR_TO_CLEAN?}" -type f -mtime +${DAYS_TO_SAVE?} -print0
For each .def file under the current directory, create an empty .def.out file with current timestamp.
find . -name '*.def' | sed 's/\(.*\)/\1.out/' | xargs touch
Finds PIDs of all running processes, gets executable binary of each process, and prints containing folder of each binary.
ps -A -o pid | xargs -I pid readlink "/proc/pid/exe" | xargs -I file dirname "file"
Find all the regular files under current directory tree that have not been modified in the last 31 days and delete them
find . -type f -mtime +31 -print0 | xargs -0 -r rm -f
find all the ".c" files in the folder /home/david which have been modified in the last 48 hours
find /home/david -mtime -2 -name '*.c'
Look for files whose names begin with letters a-j
find / -name "[a-j]*" -print
Find all files under /path/to/dir and change their permission to 644
find /path/to/dir -type f -exec chmod 644 {} +
List all files under and below the directory given as variable $ARCH1
find $ARCH1 -ls
Prints process tree of a current process with id numbers and parent processes.
pstree -sp $$
Store content of uncompressed file "$file.fastq" in variable "reads"
reads=$
Find all files in the current directory and its sub-directories that have not been assessed in more than 30 days.
find . -atime +30 -print
Find all files newer than httpd.conf under and below the current directory
find . -newer httpd.conf
Find user daniel's files of type jpeg without `autumn' in the name
find . -user daniel -type f -name *.jpg ! -name autumn*
Print the names and sizes of regular files residing in the "dir" directory tree
find dir -type f -printf "f %s %p\n"
replaces the last occurrence of 'a' with 'c'
tac infile.txt | sed "s/a/c/; ta ; b ; :a ; N ; ba" | tac
Print each line in parallel in files "tmp/sample-XXX.tim" and "tmp/sample-XXX.log"
paste tmp/sample-XXXX.{tim,log}
Display bash function definition of "foobar"
set | grep -A999 '^foobar ()' | grep -m1 -B999 '^}'
Search the /etc/apache-perl directory tree for files newer than /etc/apache-perl/httpd.conf
find /etc/apache-perl -newer /etc/apache-perl/httpd.conf
Look in /home/dm and below for files with 'uniform' in their names
find /home/dm -name "*uniform*"
Highlights current day in a month calendar with color.
cal -h | sed "s/\<$\>/"$'\033\[94m&\033\[0m/g'
Pops the top directory of dirs stack and changes to it.
popd
Search the current directory tree for regular files whose names end in ".shtml" or ".css"
find -type f -regex ".*/.*\.\(shtml\|css\)"
Print line, word and byte count for each file recursively and also show the total counts
wc `find`
Print symlink resolved script file name
echo $(basename $)
find all the files that have been modified in the last 1 day ago
find -mtime -1
Prints calendar for a current month, replacing current data with asterisk.
cal -h|sed -r "s/\b$(date|cut -d' ' -f3)\b/*/"
Find all *.m4a files under /home/family/Music directory and convert them to ogg
find /home/family/Music -name '*.m4a' -print0 | xargs -0 -i ffmpeg -i {} -acodec libvorbis -aq 6 -vn -ac 2 {}.ogg
Starts new detached tmux session 'vims' with new windows 'vim0' and opens file 'foo' within.
tmux new-session -s vims -n vim0 -d "vim foo"
Prints information about user $euids currently on machine and its processes, without printing header.
w -h $euids
display all the text files in the current folder and discard all the errors.
find -name "*.txt" 2>>/dev/null
Query about which keys invoke the named function
bind -q complete
Print the list of all regular files on the system using "echo"
find / -type f -exec echo {} \;
Find files/directories named blah under current directory
find ./ -iname blah
find all the text files in the file system and search only in the disk partition of the root.
find / -mount -name "*.txt"
Print only strings from file 'file2' that not found in 'file1'
comm -1 -3 file1 file2
Runs programs and prints formatted summary of system resource usage.
command time -f "%E real,%U user,%s sys" ls -Fs
Set the exit code to '0'.
true
search for the directory "uploads" in current folder and change the permission of the folder and all the files to 755
find . -type d -name 'uploads' -print0 | xargs -0 chmod -R 755
Display what flags mount points are mounted with
mount -l
Find all directories under media/ directory and change their permission to 700
find media/ -type d -exec chmod 700 {} \;
Find files/directories named 'foo.bar' under './dir1' and './dir2' directory tree
find ./dir1 ./dir2 -name foo.bar -print
find all executable files in /home directory.
find /home -type f -perm /a=x
Add group write permission to all files matching "*" or "...*"
chmod g+w * ...*
Replace all sequence of 'blank' characters in file 'log' with a single occurence of such symbol and print space-separated fields of each string but first two fields
cat log | tr -s [:blank:] |cut -d' ' -f 3-
Sort the lines of the file 'inputfile', keep only the uniq lines and change it in-place
sort inputfile | uniq | sort -o inputfile
Find command will display top 5 small files from curent directory . most probably you will get ZERO bytes files .
find . -type f -exec ls -s {} \; sort -n |head -5
find all the files in current folder which have been updated in the last 60 minutes
find . -mmin -60
Find any files in the current directory and its sub-directories that were last accessed more than 7 days or are larger than 20480 blocks in size.
find . -atime +7 -o -size +20480 -print
split content all files file1..40000 into pieces per 1445 lines named as outputprefixNNN as digital prefix
cat file1 file2 ... file40000 | split -n r/1445 -d - outputprefix
Remove the regular files from the current directory that were last modified on November, 22
find -maxdepth 1 -type f -newermt "Nov 22" \! -newermt "Nov 23" -delete
Find all *foo files/directories under current directory
find . -name '*foo'
Remove trailing whitespaces in .txt files from the current directory tree
find . -type f -name '*.txt' -exec sed --in-place 's/[[:space:]]\+$//' {} \+
Print a summary of the command-line usage of find
find --help
find all files that do not have read permission to all
find . -type f ! -perm -444
Find all SUID files in entire file system
find / -perm +u=s
find all the text files in the current folder and display their Permissions and size along with their name
find . -name "*.txt" -printf "%M %f \t %s bytes \t%y\n"
find all normal/regular files in the current directory
find . -type f -print
List all environment variables (name and value) whose name starts with GOROOT
env | grep '^GOROOT'
Finds string with text "string to be searched" in any cased files like "*.cs" recursively in a current folder.
find ./ -type f -iname "*.cs" -print0 | xargs -0 grep "content pattern"
Find all the files called FindCommandExamples.txt of owner root
find / -user root -name FindCommandExamples.txt
Archive "user@remoteip:/path/to/files/" to "/local/path" via ssh on port "$portNumber" and compressing data during transmission
rsync -avz -e "ssh -p $portNumber" user@remoteip:/path/to/files/ /local/path/
Find files under /usr that are the same age or older than file `FirstFile'
find /usr ! -newer /FirstFile -print
Takes path list from '.exportfiles.text' file, cuts off first two path segments and last one.
cut -d / -f 4- .exportfiles.text | xargs -n 1 dirname
Search the /home/sdt5z/tmp directory tree for files named "accepted_hits.bam"
find /home/sdt5z/tmp -name "accepted_hits.bam"
Find all hidden files in the current directory
find . -type f -name ".*"
Archive "/path/to/sfolder" to "name@remote.server:/path/to/remote/dfolder" preserving hard links and compressing the data during transmission
rsync -aHvz /path/to/sfolder name@remote.server:/path/to/remote/dfolder
Find recursively the latest modified file in the current directory
find . -type f | sed 's/.*/"&"/' | xargs ls -E | awk '{ print $6," ",$7," ",$9 }' | sort | tail -1
Print comma separated gaps in file "file" that contains new line separated ordered numbers
seq $(tail -1 file)|diff - file|grep -Po '.*(?=d)'
Copy all ".xml" files in the current directory tree to "/new/parent/dir" preserving the directory hierarchy
find . -name \*.xml -print0 | cpio -pamvd0 /new/parent/dir
Creates temporary file in $appdir variable with name formatted like expression in variable ${template}, and saves path to it in 'launcherfile' variable.
launcherfile=$
find all jpg files in current folder
find . -type f -name "*.JPG"
display all regular/normal files in the current folder ending with the word ummy
find -type f -name *ummy
Print first column of every line in every *.txt separated by a space
paste -d':' *.txt | sed 's/ [^:]*$//;s/ [^:]*:*/ /g;s/://g'
Read a line from standard input into variable "ENTERED_PASSWORD" without echoing the input
read -s ENTERED_PASSWORD
display the base name of all the ".NEF" files in the current folder
find . -name "*.NEF" -exec basename \{\} .NEF \;
count amount of jobs running
jobs | wc -l
Search the current directory recursively for files containing "needle text"
find . -type f -print0 | xargs -0 grep -I "needle text"
Change string "searc" to "replace" in all files in directory hierarchy
find . -type f -exec sed -i 's/searc/replace/g' {} \;
Creates temporary file and saves path to it in a 'tmpfile' variable.
tmpfile=$(mktemp)
find all the files in the current folder that have been modified exactly 24*3 hours ago
find ./ -mtime 3
Gets all IP addresses from host network configuration and prints first one.
ifconfig | grep "inet addr:" | grep -v "127.0.0.1" | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | head -1
Close the current screen session
screen -X quit
Search for lines that have zero or more whitespace characters before "http://" and number the uniquely sorted output
grep '^[[:space:]]*http://' | sort -u | nl
Search the current directory tree for hidden files
find .*
display all the regular files in the current folder that are bigger than 10KB
find . -type f -size +10k