linux_wiki:find

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
linux_wiki:find [2015/04/28 09:33]
billdozor [Find folders with the most files]
linux_wiki:find [2019/05/25 23:50] (current)
Line 6: Line 6:
  
 **Checklist** **Checklist**
-  * Distro(s): All+  * Distro(s): Any
  
 ---- ----
  
-===== General Syntax =====+====== General Syntax ======
  
 The general syntax of find is: The general syntax of find is:
Line 26: Line 26:
 ---- ----
  
-===== Find Examples =====+====== Find Examples ======
  
 Some of the useful find commands that have been "tested in production". Some of the useful find commands that have been "tested in production".
Line 32: Line 32:
 ---- ----
  
-==== Find folders with the most files ====+===== Find folders with the most files =====
  
 If you run into a situation in which you have high inode usage as seen by 'df -i', the following syntax will show folders with the most files: If you run into a situation in which you have high inode usage as seen by 'df -i', the following syntax will show folders with the most files:
  
 <code bash> <code bash>
-nice find / -mount -printf '%h\n' | sort | uniq -c | sort -k 1 -n+nice find / -mount -printf '%h\n' | sort | uniq -c | sort -n -k 1
 </code> </code>
  
Line 44: Line 44:
   * find / = start in the "/" directory (change this to the root of a mount point you wish to investigate as identified by 'df -i')   * find / = start in the "/" directory (change this to the root of a mount point you wish to investigate as identified by 'df -i')
   * mount = Do not descend directories on other file systems.   * mount = Do not descend directories on other file systems.
-  * printf '%h\n' = Print the leading directories of a file's name, then a newline+  * printf '%h\n' = Print the leading directories of a file's name (%h), then a newline (\n). (man find, then search for 'printf\ format' to see all available formats)
   * sort = Default sort by starting of line alphabetical   * sort = Default sort by starting of line alphabetical
   * uniq -c = Filter matching adjacent lines, prefix lines with the count of occurrences   * uniq -c = Filter matching adjacent lines, prefix lines with the count of occurrences
-  * sort -k 1 -n = Sort via the "key" starting at 1 (field 1the numbernumerically+  * sort -n -k 1 = Sort numerically (-n) via the "key" (-k) at field 1 (field 1 is the count from 'uniq -c').
  
 This will give output with the first column displaying file count and the second column displaying the folder it is in. This will give output with the first column displaying file count and the second column displaying the folder it is in.
Line 59: Line 59:
    2123 /usr/share/linuxmint/mintinstall/icons    2123 /usr/share/linuxmint/mintinstall/icons
 </code> </code>
 +
 ---- ----
 +
 +===== Find, starting in /, all files (type f) owned by rjones =====
 +
 +<code bash>
 +find / -user rjones -type f
 +</code>
 +
 +----
 +
 +===== Remove all files owned by rjones =====
 +
 +<code bash>
 +find / -user rjones -type f -exec rm '{}' \;
 +</code>
 +
 +----
 +
 +===== Find all files modified in the last 3 days =====
 +
 +<code bash>
 +find / -mtime -3 -type f
 +</code>
 +
 +----
 +
  • linux_wiki/find.1430228038.txt.gz
  • Last modified: 2019/05/25 23:50
  • (external edit)