nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Find all files under current directory and make them read-only for owner, read & writable by group and remove read-write-execute permission
find . -type f -exec chmod u+r-wx,g+rw-x,o-rwx {} \;
Save full path of command "mktemp" to variable "MKTEMP"
MKTEMP=`which mktemp`
Search for all non-hidden files
find . -name '*'
change the permission of all the regular files in the folder /home to 700
find /home -type f -perm 0777 -print -exec chmod 700 {} \;
Recursively removes 'classes' folder, prompting user on each deletion.
rm -r classes
find all the files in the folder /opt which have been modified exactly 20 days ago
find /opt -mtime 20
List characters from standard input showing backslash escapes for non-displayables
od -cvAnone -w1
List all files without descending into subdirectories
find * -type f -print -o -type d -prune
Remove junk files modified more than 31 days ago recursively
find /path/to/junk/files -type f -mtime +31 -exec rm -f {} \;
Find all or single file called tecmint.txt under the / directory of owner root
find / -user root -name tecmint.txt
Send one ping request to host whose name or IP address is specified by variable "ip", using network interface eth9.
ping ${ip} -I eth9 -c 1
Lists content of all subfolder in a current folder.
ls -d -1 $PWD/**/*
Recursively removes 'classes' folder, prompting user on each deletion.
rm -r classes
Fint all *.txt files/directories under /mnt/msdos and without error reporting
find /mnt/msdos -name "*.txt" 2> /dev/null
Mount "/path/to/device" on "/path/to/mount/location" as a loop back device
mount /path/to/device /path/to/mount/location -o loop
Search the 'tmp' directory for .mp3 files
find tmp -maxdepth 1 -name '*.mp3'
Calculate the md5sum of all the files with name "MyCProgram.c", ignoring case
find -iname "MyCProgram.c" -exec md5sum {} \;
Print the files under current directory twice per line
find . -type f -exec echo {} {} \;
replaces the last occurrence of 'a' with 'c' in file
tac file | awk '/a/ && !seen {sub(/a/, "c"); seen=1} 1' | tac
Find all directories by the name `httpdocs' on the system
find / -type d -name httpdocs
Recursively search current directory for all files with name ending with ".t1", change this to .t2
find . -name "*.t1" -exec rename 's/\.t1$/.t2/' '{}' \;
Print three lines of "some line " followed by a random number
seq -f 'some line %g' 500 | nl | sort -R | cut -f2- | head -3
Find all files/directories under 'my key phrase' directory
find 'my key phrase'
Find the top 5 big files
find . -type f -exec ls -s {} \; | sort -n -r | head -5
Gets MAC address of eth0 network interface.
ifconfig | grep -i hwaddr | cut -d ' ' -f9
Wrap standard input to fit in 10 characters per line
fold -w 10
Print unique lines of sorted "File 1" compared with sorted "File 2"
comm -23 "File 1" "File 2"
Print the list of all files except files named BBB
find . \! -name BBB -print
Set the read bit for "other" on all *rc.conf files in the current directory tree
find . -name "*rc.conf" -exec chmod o+r '{}' \;
Save the FQDN host name of the system in variable "fhost"
fhost=`hostname -f`
Make directory and parents as needed for each unique mime type in the current directory
mkdir -p `file -b --mime-type *|uniq`
find all files in the current directory that are less than 1 byte size
find . -size -1c -print
Send SIGTERM signal to entire process tree starting from ID 24901 and below.
kill `pstree -p 24901 | sed 's/(/\n(/g' | grep '(' | sed 's/(\(.*\)).*/\1/' | tr "\n" " "`
Replace each newline in input "1\n2\n3\n4\n5" with a comma
echo "1\n2\n3\n4\n5" | paste -s -d, /dev/stdin
search for all the regular/normal mp3 files in the file system and move them to the folder /mnt/mp3
find / -iname "*.mp3" -type f -exec /bin/mv {} /mnt/mp3 \;
Change the owner of all files in the directory tree "dir_to_start" excluding directory "dir_to_exclude" to "owner"
find dir_to_start -name dir_to_exclude -prune -o -print0 | xargs -0 chown owner
Sort strings of 'test.txt' file by second from the end field
rev test.txt | sort -k2 | rev
delete all the text files in the current folder
find . -type f -name "*.txt" -delete
search for all the log files in the folder /apps which have not been modified in the last 60 days and which are present in the same file system as that of /apps and delete them
find /apps -xdev -name "*.log" -type f -mtime +60 | xargs rm
display all the files in the home folder which begin with "arrow"
find ~ -name 'arrow*'
Recursively list all the files and directories that are only in directory /dir1 with their full paths.
diff -rq /dir1 /dir2 | grep -E "^Only in /dir1.*" | sed -n 's/://p' | awk '{print $3"/"$4}'
find all the zip files in the current folder and create a tar ball of these zip files
find . -type f -name '*.zip' -print0 | xargs -0 tar -xzf
show all the mp3 files in the folder /home
find /home -type f -name '*.mp3'
Remove all files whose names end with "~" in the /home/peter directory tree
find /home/peter -name *~ -print0 |xargs -0 rm
Output "stuff", removing "/foo/bar/" from the specified path.
basename /foo/bar/stuff
Find recursively all empty directories in the current directory
find . -type d -empty
Finds all strings with parent folder of path '$path' in 'file', and saves result in 'x' variable.
x=$(grep "$(dirname "$path")" file)
Add read and execute permission to every directory under the current directory
find . -type d -exec chmod +rx {} \;
Scan every file in /etc for IPV4 addresses while trying to elminate false positives.
find /etc -type f -exec cat '{}' \; | tr -c '.[:digit:]' '\n' | grep '^[^.][^.]*\.[^.][^.]*\.[^.][^.]*\.[^.][^.]*$'
Find all *.foo files under current directory and print their contents
find . -name '*.foo' -exec cat {} +
Find all *.so files/directories under current directory and run myCommand with the file/directory paths as its argument, then search for ExpectedResult in the output
find . -name *.so -print0 | xargs -0 myCommand | grep ExpectedResult
Finds users with X session in system and puts the result in USERS variable.
USERS=$
Remove the "^M" characters from all *.ext files under /home directory
find /home -type f -name "*.ext" -exec sed -i -e 's/^M$//' {} \;
list all the sqlite files in the current folder
find ./ -name "*.sqlite" -ls
Print the file content of command "[whatever]"
cat `find [whatever]`
Creates temporary folder and saves path to it in 'other' variable.
other="$"
Make directories a, b, c, ..., z under path2 as needed.
mkdir -p path2/{a..z}
Read a line from standard input with prompt "Continue ?" and save response in variable "CONT"
read -p "Continue ?" CONT
Prints lines count of each *.php file in a current folder and subfolders, and prints total count.
find . -name '*.php' -print0 | xargs -0 wc -l
Find all .sh files in or below the current directory and move them to folder ~/back.scripts
find . -name "*.sh" -print0 | xargs -0 -I {} mv {} ~/back.scripts
Find all files under path_to_dir
find path_to_dir -type f
Find files with the extension .conf in the /etc directory
find /etc -name '*.conf'
Find all files under current directory that match the case insensitive regex .\|./.git and replace the text matching the regex expanded by $lower1 with $lower2 in these files
find . -type f \! -iregex '.\|./.git' -exec perl -i'' -pe "s/$lower1/$lower2/g" {} +
get the count of all the files that have been accessed in the last 30 days
find . -atime +30 -exec ls \; | wc -l
Write "foo" to the real path of the current command's standard input
echo foo | readlink /proc/self/fd/1
Show manual of the find utility
man find
Show long listing of current directory by deleting all digits from the output
ls -lt | tr -d 0-9
Get a recursive file list of directory $dir
find $dir -type f
Prefix all files and directories in the current directory with "unix_"
ls | xargs -i mv {} unix_{}
Sets 'extglob' shell variable.
shopt -s extglob
finda ll the files in the current folder that are modified today.
find ~ -type f -mtime 0 -ls
Count the number of lines in "/dir/file.txt"
cat /dir/file.txt | wc -l
Find files/directories named 'document' in the entire filesystem and in the directory tree '/usr' even if it's in a different partition without traversing to other devices/partitions
find / /usr -xdev -name document -print
Find writable regular files in the current directory
find -type f -maxdepth 1 -writable
Find all files/directories under /proc and run ls command on each.
find /proc -exec ls '{}' \;
Counts lines in each of *.php files in a current folder and subfolders and prints total count.
find . -name '*.php' | awk '{gsub;print $0}' |xargs wc -l
Find all *.log files under path/
find path/ -name "*.log"
Save Java home in variable "JAVA_HOME"
JAVA_HOME="$( readlink -f "$( which java )" | sed "s:bin/.*$::" )"
display all the files in the file system which belong to the user "wnj" or which are modified after the file "ttt"
find / \ -print
Get domain name with 'google' from address $1
dig -x "$1" | grep PTR | cut -d ' ' -f 2 | grep google | cut -f 5
Display the contents of "text"
cat text
Find files under current directory that are not newer than $date_time in regards of modification time
find . -type f -not -newermt "$date_time"
Variable PID contains a process ID, send SIGTERM to this process if it exists.
kill $PID
display the directory name along with the modified time for all the files /var
find /var -maxdepth 2 -type d -printf "%p %TY-%Tm-%Td %TH:%TM:%TS %Tz\n"
Finds more than 5 days old files in two directories and compresses them.
find /home/folder1 /home/folder2 -type f -mtime +5 -exec compress {} \;
Forcibly create symlink named as '/cygdrive/c/Users/Mic/mypics' to the directory '/cygdrive/c/Users/Mic/Desktop/PENDING - Pics/'
ln -sf '/cygdrive/c/Users/Mic/Desktop/PENDING - Pics/' '/cygdrive/c/Users/Mic/mypics'
List first 5 files named 'something' that are found under current directory
find . -name something -print | head -n 5
Find all or single file called FindCommandExamples.txt under / directory of owner root
find / -user root -name FindCommandExamples.txt
delete all empty files in the current directory ( empty file = size 0 bytes )
find . -empty -exec rm '{}' \;
Print every two lines in "file" on a single line separated by a space
cat file | paste -d\ - - -
create a symbolic link in current directory named "my_db" to file "/media/public/xampp/mysql/data/my_db"
ln /media/public/xampp/mysql/data/my_db -s
Write current directory listing to standard output and to "files.txt"
ls |& tee files.txt
Execute script /path/to/filecopy.sh passing all JPG files found under the "$SOURCE" directory and below as arguments
find "$SOURCE" -type f -iname '*.jpg' -exec /path/to/filecopy.sh {} +
Print all user names and terminals of users who are logged in
who | awk '{ print $1, $2 }'
Set up a remote port forward from port 10022 on host "server" to port 22 on localhost
ssh -R 10022:localhost:22 device@server
Find all files/directories under directory '.cache/chromium/Default/Cache/' which are bigger than 100MB and which are atleast 1 level deep and delete them
find .cache/chromium/Default/Cache/ -mindepth 1 -size +100M -delete
Count the *.html files residing in the /usr/src directory tree and containing string "foo"
find /usr/src -name "*.html" | xargs grep -l foo | wc -l
delete a hard link and create a symbolic link to file named "$link"
ln -sf "$(readlink -f "$link")" "$link"
Print the list of files and directories of the current directory including "."
find . \
create a symbolic link in current directory named "environments" to file "../config/environments"
ln -s "../config/environments"