Difference between revisions of "Find"

From Useful Things
Jump to: navigation, search
m (Several matches)
Line 13: Line 13:
 
<code>-xdev</code> stay on the current filesystem<br />
 
<code>-xdev</code> stay on the current filesystem<br />
 
<code>-o</code> logical OR, use parentheses for clarity - must be escaped in bash
 
<code>-o</code> logical OR, use parentheses for clarity - must be escaped in bash
 +
 +
== Find files and do something with each ==
 +
<syntaxhighlight lang="bash">
 +
find . -type f -print0 | xargs -0 <command>
 +
</syntaxhighlight>
 +
<code>-print0</code> print the full file name on the standard output, followed by a null character (instead of the newline character that -print uses)<br />
 +
<code>-0</code> input items are terminated by a null character instead of by whitespace, and the quotes and backslash are not special (every character is taken literally).

Revision as of 07:52, 19 April 2015

Between dates

find / -newermt "27 Dec 2013" ! -newermt "1 Jan 2014"

-newermt newer than specified modification time
! invert proceeding condition

Several matches

find / -xdev \( -name .DS_Store -o -name ._.DS_Store \)

-xdev stay on the current filesystem
-o logical OR, use parentheses for clarity - must be escaped in bash

Find files and do something with each

find . -type f -print0 | xargs -0 <command>

-print0 print the full file name on the standard output, followed by a null character (instead of the newline character that -print uses)
-0 input items are terminated by a null character instead of by whitespace, and the quotes and backslash are not special (every character is taken literally).