nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
display long listing of all the files that have been changed in the last 4 days, daystart is used to compare from the starting of day i.e, at 00:00
find . -daystart -ctime 4 -ls -type f
Print a line of 100 '=' characters
head -c 100 < /dev/zero | tr '\0' '='
List the names of all files under current directory
find . -type f -exec basename {} \;
List all files with name "someFile" and their modification time under the current directory sorted by oldest modified to newest modified
find . -name "someFile" -printf "%p:%T@\n" | sort -t : -k2
Find all the Sticky Bit set files in entire file system whose permission are 551
find / -perm 0551
display all regular/normal files in the current folder ending with the word ummy
find -type f -name *ummy
Finds strings with dot-separated sequence of numbers, and prints part of that sequence before the first dot.
echo "$f" | grep -Eo '[0-9]+[.]+[0-9]+[.]?[0-9]?' | cut -d. -f1
display all the jpg images in current folder
find . -type f -iregex '.*\.jpe?g'
Change the permission to 0644 for all files under current directory
find . -type f -exec chmod 0644 {} +
Find all the files under /home directory with name tecmint.txt
find /home -name tecmint.txt
Print amount of space available on the file system containg path to the current working directory human-readable.
df -Ph $PWD | tail -1 | awk '{ print $3}'
Print summary of files present only in dir1.
diff -rq dir1 dir2 | grep 'Only in dir1/'
Replace all occurrences of 'previousword' with 'newword' in all regular files with '.cpp' extension under '/myprojects' directory tree and modify them in-place
find /myprojects -type f -name '*.cpp' -print0 | xargs -0 -n 1 sed -i 's/previousword/newword/g'
Print the contents of "/tmp/nums" as input to "addnums"
cat /tmp/nums | addnums
Filter contents of 'file' through awk commands written in script.awk, display the result.
awk -f script.awk file
Find all Makefile's in the current directory tree and look for line 235 in each of them
find . -name Makefile -print0 | xargs -0 grep -nH $ | grep :235:
Search the current directory recursively for regular files last changed less than 2 days ago
find . type -f -ctime -2
Move files from $sourcePath to $destPath that have not been modified in the last 10 days
find $sourcePath -type f -mtime +10 -name "*.log" -exec mv {} $destPath \;
Count the number of files/directories named file1 under current directory
find -name file1 | wc -l
Search the current directory tree for *cache, *xml, and *html files
find . -type f \
Print list of missing files in a Subversion repository.
svn status | grep '\!' | cut -d\ -f2-
Make directories "Labs/lab4a/folder1", "Labs/lab4a/myfolder", and "Labs/lab4a/foofolder"
mkdir Labs/lab4a/{folder1,myfolder,foofolder}
search for "specified string" in all the php files in the current folder
find . -name “*.[php|PHP]” -print | xargs grep -HnT “specified string”
Find out all hard links in the /home directory to file1
find /home -xdev -samefile file1
Find all files under current directory and print them appending a null character at the end of each file paths
find . -type f -print0
Ping every address from 192.168.0.1 to 192.168.0.254 with a timeout of 1 second and filter out no responses
echo $ | xargs -P255 -I% -d" " ping -W 1 -c 1 192.168.0.% | grep -E "[0-1].*?:"
Counts lines in each *.php file.
wc -l `find . -name "*.php"`
Find all the files which are modified in last 1 hour
find / -mmin -60
Search the current directory tree for regular files modified within the past 24 hours whose names do not end with ".DS_Store"
find . -mtime -1 ! -name '.DS_Store' -type f -exec basename {} \;
run command 'bash --rcfile myfile' as user root
su -c 'bash --rcfile myfile'
Calculate the md5 sum of all files in the current directory and formatting the output by removing parenthesis
find -maxdepth 1 -type f -exec md5sum {} \; | sed 's/[^(]*(\([^)]*\)) =/\1/'
Find all directories under /home/username/public_html/sites/all/modules and set their permission to 750
find /home/username/public_html/sites/all/modules -type d -exec chmod 750 {} +
find md5sum of string 'hi'
echo -n hi | md5
List all empty files in the current directory tree
find . -type f -empty
List the commands in /usr/bin, pausing for user input after each page.
ls /usr/bin | more
change the group of all the files which belong to the user edwarda to pubs
find / -user edwarda -exec chgrp pubs "{}" \;
find all the normal/regular files in the current directory and search for the word mail and display the file names
find . -type f -exec grep -il mail
Search everywhere for files changed within the last minute
find / -newerct '1 minute ago' -print
Find all files/directories under current directory that were modified exactly 30 minutes ago
find . -mmin 30
wait for a change in "target-directory" before returning
inotifywait -e attrib target-directory
Find directories under maximum 1 level down the directory $dir with 100 permission that are owned by the user $username
find $dir -maxdepth 1 -type d -user $username -perm -100
create directory destdir
mkdir destdir
Print lines that only unique ones in 'set1' and 'set2' files
cat <(grep -vxF -f set1 set2) <(grep -vxF -f set2 set1)
Search directory /Users/david/Desktop/ recursively for regular files
find /Users/david/Desktop/ -type f
Print the current default full path of the "java" executable
echo "The current default java is $"
Find all empty regular files in the current directory tree
find . -size 0c -type f
Print only unique lines of 'file_name' file
cat -n file_name | sort -uk2 | sort -nk1 | cut -f2-
list broken symbolic links under "somedir"
find "somedir" -type l -print0 | xargs -r0 file | grep "broken symbolic" | sed -e 's/^\|: *broken symbolic.*$/"/g'
Count number of users logged in
who | awk -F' ' '{print $1}' | sort -u | wc -l
Find all files/directories under '/abs/path/to/directory' directory non-recursively that match the pattern '.*invalidTemplateName.*' in their names
find /abs/path/to/directory -maxdepth 1 -name '.*invalidTemplateName.*'
Display top 500 mp4 and flv files under current directory along with their timestamps in the sorted order of time
find . -regex ".*\.\(flv\|mp4\)" -type f -printf '%T+ %p\n' | sort | head -n 500
Find all directories under path_to_dir directory
find path_to_dir -type d
Find all directories named "D" in the current directory tree and print their parents
find ./ -type d -name 'D'|sed 's/D$//'
Search all files called "abc" that reside in the current directory tree for string "xyz"
find . -name "abc" -exec grep "xyz" {} \;
Find all files in the /usr directory tree that are owned by group `staff'
find /usr -group staff
display the names without extensions of all the data files in current folder and do not search in sub folders and which have not been changed in the last 60 mins
find . -maxdepth 1 -name '*.dat' -type f -cmin +60 -exec basename {} \;
Print amount of space available on the file system containing path to the current working directory in megabytes.
df . -B MB | tail -1 | awk {'print $4'} | cut -d'%' -f1
create a symbolic link named "link" in directory named as value of the variable $2 to a file that named as result of the command `cd \`dirname $2\`; pwd`/`basename $2`
ln -s `cd \`dirname $2\`; pwd`/`basename $2` $1/link
Find SUID files
find / -perm +4000
Find all *.cgi files/directories under current directory and change their permission to 755
find . -iname '*.cgi' | xargs chmod 755
Finds all php processes running in system.
pstree | grep php
Remove filetype suffix from filename
echo $filename | rev | cut -f 2- -d '.' | rev
Find all *.cgi files/directories under current directory and change their permission to 775
find . -name '*.cgi' -print0 | xargs -0 chmod 775
Find all files inside all directories in maximum 2 levels down the /tmp/test directory and print the number of files in each directory and also print the file/directory paths
find /tmp/test/ -maxdepth 2 -mindepth 1 -type d | while read dir; do printf "%s : " "$dir"; find "$dir" -maxdepth 1 -type f | wc -l; find "$dir" -maxdepth 1 -type f ; done;
search for all the files in the current directory which belong to the user "xuser1" and change the owner ship of them to "user2"
find . -user xuser1 -exec chown -R user2 {} \;
Prints long listing of content in a root folder, including hidden files, with human-readable sizes, and stores output to '/root/test.out' file.
sudo ls -hal /root/ | sudo bash -c "cat > /root/test.out"
Login in 'whatever.com' as user 'whoever' with X11 forwarding to enable GUI programs on remote to be run
find all files ending with "js.compiled" in current folder
find . -type f -name "*.js.compiled"
Print only name and login columns of the currently logged in users
finger -s | awk '{printf;}'
Echo each command before running
set -x
display all the files in the directory modules
find . -name modules
Remove the first 7 characters of every line in the output of "history"
history | cut -c 8-
Look for files with the name 'search' under current directory
find . -name "search"
files all files which expect directories and display count of them
find /usr/share \! -type d wc -l
Find files in entire file system with at least 644 permissions
find / -perm -u+rw,g+r,o+r
Find all files/directories under /path/to/dir/* paths and print the timestamp in YmdHMS format along with their paths and object of symlinks
find /path/to/dir/* -printf "%TY%Tm%Td%TH%TM%TS|%p|%l\n"
Find regular files that are larger than 2GB
find . -type f -size +2G
Gets the groups these users belong to.
groups a b c d
Search for files only that end with .php and look for the string $test inside those files
find . -name \*.php -type f -print0 | xargs -0 -n1 grep -Hn '$test'
Execute "ls -l" every 2 seconds and highlight the differences in runs
watch -d ls -l
Output lines 16224 to 16482 of 'file', not recommended with large files that contain many lines after the ones needed.
awk 'NR==16224, NR==16482' file
Find all files in the home directory with open permissions
find ~ -perm 777
Mathematically sum all numbers in "file.txt"
cat file.txt | xargs | sed -e 's/\ /+/g' | bc
search all jpg,png,jpefg files in the current folder and calculate the total size of them
find . \ -ls | awk '{total += $7} END {print total}'
Search for files/directories which are writable by either their owner or their group
find . -perm /u=w,g=w
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}'
Recursively counts non-blank, non-comment lines in all *.c files in a current folder.
find . -type f -name '*.c' -exec cat {} \; | sed '/^\s*#/d;/^\s*$/d;/^\s*\/\//d' | wc -l
Search for files with "demo" in their names and "sitesearch" in their path names
find . -iname '*demo*' | grep -i sitesearch
Find the sorted and unique parent directory paths appended with : of all the files that are executable by owner under ~/code directory without descending into hidden directories and redirect the output to the file ~/.codepath
find ~/code -name '.*' -prune -o -type f -a -perm /u+x -printf ':%h\n' |sort |uniq |tr -d '\n' > ~/.codepath
Read the first 10 characters from standard input in an interactive shell into variable "VAR"
read -n10 -e VAR
Deletes empty folder 'nonsense_dir'.
rmdir nonsense_dir
Archive "/usr/local/" to "/BackUp/usr/local/" on host "XXX.XXX.XXX.XXX" via ssh and show progress
rsync --progress -avhe ssh /usr/local/ XXX.XXX.XXX.XXX:/BackUp/usr/local/
Generate UUIDs for the files from the current directory tree
find -printf "%P\n"| sort | xargs -I '{}' bash -c 'echo $ {}'
display all normal/regular files in a folder
find teste1 -type f
Delete empty directories
find . -type d -empty -delete
search for *.log files starting from /
find / -name "*.log"
Replace "dummyvalue" with the system IP address in "filename"
sed -i s/'dummyvalue'/$(hostname -I | head -n1 | awk '{print $1;}')/g filename
displays all the files in the current folder
find .
find all the png files in the current folder which begin with the word image
find . -name "image*.png"
find all the regular files in the current folder which have specific word in their name and force delete all these files and save the log to the file log_del.txt
find ./ -type f -name '*.r*' -print0 | xargs -0 rm -rf &> log_del.txt