Find: Difference between revisions

249 bytes removed ,  6 years ago
no edit summary
No edit summary
Line 4:
 
 
= General Usage =
 
Find Text Files
find ~/test -name *.txt
 
Find empty folders
find ~/test -type d -empty
 
Find all empty files (zero byte file)
Line 20 ⟶ 21:
find . -maxdepth 1 -empty -not -name ".*"
 
 
Find Files Using Name
find -name "MyCProgram.c"
 
Find Files Using Name and Ignoring Case
find -iname "MyCProgram.c"
 
Limit Search To Specific Directory
find / -name passwd
 
Find the passwd file under root and one level down
find -maxdepth 2 -name passwd
 
Find only the socket files
find . -type s
 
Find all directories
Line 49 ⟶ 41:
find -type d -name ".*"
 
 
List and Export only files recursively without Directory name
find . -maxdepth 10 -type f -printf '%f\n' > fileslist.txt
 
= Time based Sort =
Line 86 ⟶ 77:
find -mmin -60 -exec ls -l {} \;
 
Restricting the find output only to files
find /etc/sysconfig -amin -30 -type f
 
Do not display hidden files in find output
find . -mmin -15 \( ! -regex ".*/\..*" \)
 
= Delete Files =
Line 107 ⟶ 103:
Move Specific files to another location
find ./* -name *.jpg -exec mv {} ~/Public/ \;
 
 
 
 
 
 
Search all jpg images in the system and archive it
find ~/test -name *.jpg -type f -print | xargs tar -cvzf images.tar.gz
 
 
Inverting the match
find -maxdepth 1 -not -iname "MyCProgram.c"
 
 
Line 146 ⟶ 130:
find / -type f -name *.zip -size +100M -exec rm -i {} \;"
 
 
 
 
Restricting the find output only to files
find /etc/sysconfig -amin -30 -type f
 
Do not display hidden files in find output
find . -mmin -15 \( ! -regex ".*/\..*" \)
 
 
 
If multiple partitions mounted under /, this command will NOT search all mounted partitions
find / -xdev -name "*.log"
 
If you don’t want to see the errors and would like to redirect it to null
find -name "*.txt" 2>>/dev/null
 
 
Line 195 ⟶ 163:
Executing Commands on the Files Found by the Find Command
find -iname "MyCProgram.c" -exec md5sum {} \;
 
 
= Advanced Options =
 
List and Export only files recursively without Directory name
find . -maxdepth 10 -type f -printf '%f\n' > fileslist.txt
 
If you don’t want to see the errors and would like to redirect it to null
find -name "*.txt" 2>>/dev/null
 
Search all jpg images in the system and archive it
find ~/test -name *.jpg -type f -print | xargs tar -cvzf images.tar.gz
 
Inverting the match
find -namemaxdepth 1 -not -iname "MyCProgram.c"
 
 
<br />