Simple Find Commands

 http://bencane.com/2012/07/22/cheat-sheet-21-useful-find-commands/ | https://kb.iu.edu/d/admm

Find . – How to list all files in the current directory and sub directory.

find . -name sed.txt – Search for a specific file by name.
Example Output:

./sed/sed.txt

find . -name “*.txt” – find all file that are a certain type.

./awk/awkfile.txt

./awk/lotr.txt

./loops/names.txt

./sed/sed.txt

./grep/names.txt

./find/findmore1/find1.txt

./find/findmore2/find2.txt

./find/findmore3/find3.txt

find . -iname sed.txt – To perform and case insensitive search of a file.

find . ! -name “*.txt” – list the file name that does not match the search pattern. In this case it would be all strings in the file that do not match .txt.

Example Output:

./awk/lotr.txt.bak

./awk/lotro.txt1491756797.bak

./loops

./sed

./sed/awk

./sed/awk/grepnfind

./sed/sed.txts.bak

./php.ini

./grep

./find

./find/findmore1

./find/findmore2

./find/findmore3

find . -maxdepth 2 -name “*.txt” – find all txt files up to a max depth of 2 sub directories.

Example Output:

./awk/awkfile.txt

./awk/lotr.txt

./loops/names.txt

./sed/sed.txt

./grep/names.txt

find . -mindepth 3 -name “*.txt” – find all files in the current directory with a minimum depth of 3.
./find/findmore1/find1.txt

./find/findmore2/find2.txt

./find/findmore3/find3.txt

 

find ~johnno/mail/13th-legion.com/*/{cur,new,.Sent/{cur,new}} -maxdepth 1 -type f = This command looks for all emails that were sent and recevied by checking the cur new and sent folder.

find -type f -name “.htaccess” -exec grep -Hn “AddHandler” {} \;  =Looks and greps for a .htaccess with Addhandler in it.

find ./public_html -maxdepth 1 -name “*php” = find names that end with php and a max depth of 1

find -type f -exec grep -Hi “/home4” -ls {} \; = find and greps out all files that have /home4 in them and then lists them all.