chore(find): more examples

This commit is contained in:
Michele Cereda
2024-09-06 08:46:47 +02:00
parent 1a81ad54a9
commit c71748221f
2 changed files with 30 additions and 15 deletions

View File

@@ -1,7 +1,5 @@
# Find
## Table of contents <!-- omit in toc -->
1. [TL;DR](#tldr)
1. [Time specifications](#time-specifications)
1. [Gotchas](#gotchas)
@@ -9,6 +7,9 @@
## TL;DR
<details>
<summary>Usage</summary>
```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
```
</details>
## 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 (`-`).<br/>
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 (`-`).<br/>
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).<br/>
With the `-Xtime` form, times depend on the given unit; if no unit is given, it defaults to full 24 hours periods
(days).<br/>
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).<br/>
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).<br/>
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"?]
<!--
References
Reference
═╬═Time══
-->
<!-- Others -->

View File

@@ -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