diff --git a/knowledge base/find.md b/knowledge base/find.md index 1ea7072..40a588f 100644 --- a/knowledge base/find.md +++ b/knowledge base/find.md @@ -1,7 +1,5 @@ # Find -## Table of contents - 1. [TL;DR](#tldr) 1. [Time specifications](#time-specifications) 1. [Gotchas](#gotchas) @@ -9,6 +7,9 @@ ## TL;DR +
+ Usage + ```sh # Change the permissions of all files and directories in the current directory, # recursively. @@ -94,12 +95,17 @@ find … 2>/dev/null find … 2> >(grep -v 'Permission denied' >&2) # BASH and ZSH only ``` +
+ ## Time specifications -Primaries used to check the difference between the file last access, creation or modification time and the time `find` was started. +Primaries used to check the difference between the file last access, creation or modification time and the time `find` +was started. -All time specification primaries take a numeric argument, and allow the number to be preceded by a plus sign (`+`) or a minus sign (`-`).
-A preceding plus sign means **more than `n`**, a preceding minus sign means **less than `n`** and neither means **exactly `n`**. +All time specification primaries take a numeric argument, and allow the number to be preceded by a plus sign (`+`) or a +minus sign (`-`).
+A preceding plus sign means **more than `n`**, a preceding minus sign means **less than `n`** and neither means +**exactly `n`**. Accepted time information: @@ -110,7 +116,8 @@ Accepted time information: With the `-Xmin` form, times are rounded up to the next full **minute**. This is the same as using `-Xtime Nm`. -With the `-Xtime` form, times depend on the given unit; if no unit is given, it defaults to full 24 hours periods (days).
+With the `-Xtime` form, times depend on the given unit; if no unit is given, it defaults to full 24 hours periods +(days).
Accepted units: - `s` for seconds @@ -121,8 +128,11 @@ Accepted units: Any number of units may be combined in one `-Xtime` argument. -with the `-newerXY file` form, `find` checks if `file` has a more recent last access time (X=a), inode creation time (X=B), change time (X=c), or modification time (X=m) than the last access time (Y=a), inode creation time (Y=B), change time (Y=c), or modification time (Y=m).
-If Y=t, `file` is interpreted as a direct date specification of the form understood by `cvs`. Also, `-newermm` is the same as `-newer`. +with the `-newerXY file` form, `find` checks if `file` has a more recent last access time (X=a), inode creation time +(X=B), change time (X=c), or modification time (X=m) than the last access time (Y=a), inode creation time (Y=B), change +time (Y=c), or modification time (Y=m).
+If Y=t, `file` is interpreted as a direct date specification of the form understood by `cvs`. Also, `-newermm` is the +same as `-newer`. ```sh # Find files last accessed exactly 5 minutes ago. @@ -187,7 +197,8 @@ find / -newer file.txt -user wnj -print - [How can I exclude all "permission denied" messages from "find"?] diff --git a/snippets/find.sh b/snippets/find.sh index 055374c..55be41e 100644 --- a/snippets/find.sh +++ b/snippets/find.sh @@ -1,11 +1,15 @@ #!/usr/bin/env sh -# Ignore permission errors. -# ------------------------- - +# Ignore permission errors find '/' -type 'f' -name 'git-remote-keybase' 2>/dev/null +find '/' -type 'f' -name 'git-remote-keybase' -readable # GNU find only -# GNU find. -find '/' -type 'f' -name 'git-remote-keybase' -readable +# Find files modified in the last 24h +find '.' -newermt '24 hours ago' +find '.' -mtime '-24h' -find '.' -type 'd' -name '.git' -exec dirname {} ';' | xargs -I {} -n 1 -t git -C {} remote --verbose +# Find files changed in the last 24h +find '.' -newerct '24 hours ago' +find '.' -ctime '-24h' + +find '.' -type 'd' -name '.git' -exec dirname {} ';' | xargs -t -I {} git -C {} remote --verbose