Difference between revisions of "Find linux command"

From Knowledge Center
Jump to: navigation, search
(Created page with "a")
 
 
Line 1: Line 1:
a
+
'''Find specific files'''
 +
 
 +
To find only files with .txt extension:
 +
 
 +
<pre>
 +
$ find /home/to/ -type f -name "*.txt"
 +
</pre>
 +
 
 +
To find only directories ending with -bar:
 +
 
 +
<pre>
 +
$ find /home/to/ -type d -name "*-bar"
 +
</pre>
 +
 
 +
'''Find and Delete:'''
 +
 
 +
Find files older than 30 days and delete:
 +
 
 +
<pre>
 +
$ find /var/logs/ -mtime +30 -exec rm -rf {} \;
 +
</pre>
 +
 
 +
[[Category:Linux]]
 +
[[Category:Sysadmin]]
 +
[[Category:All]]

Latest revision as of 09:06, 29 July 2020

Find specific files

To find only files with .txt extension:

$ find /home/to/ -type f -name "*.txt"

To find only directories ending with -bar:

$ find /home/to/ -type d -name "*-bar"

Find and Delete:

Find files older than 30 days and delete:

$ find /var/logs/ -mtime +30 -exec rm -rf {} \;