sangkrit

Linux: Find Command


The find command can be very useful at the start of a pipe to search for files. Here are some examples. You might want to add 2>/dev/null to the command lines to avoid cluttering your screen with error messages.
Find all files in /etc and put the list in etcfiles.txt
find /etc > etcfiles.txt
Find all files of the entire system and put the list in allfiles.txt
find / > allfiles.txt
Find files that end in .conf in the current directory (and all subdirs).
find . -name “*.conf”
Find files of type file (not directory, pipe or etc.) that end in .conf.
find . -type f -name “*.conf”
Find files of type directory that end in .bak .
find /data -type d -name “*.bak”
Find files that are newer than file42.txt
find . -newer file42.txt
Find can also execute another command on every file found. This example will look
for *.odf files and copy them to /backup/.
find /data -name “*.odf” -exec cp {} /backup/ ;
Find can also execute, after your confirmation, another command on every file found. This example will remove *.odf files if you approve of it for every file found.
find /data -name “*.odf” -ok rm {} ;

 

 

 

 

 

 

 


Leave a Reply