2013-10-14 02:36:58 +00:00
|
|
|
---
|
|
|
|
title: Find
|
2015-11-24 05:02:17 +00:00
|
|
|
category: CLI
|
2020-07-04 13:33:09 +00:00
|
|
|
updated: 2019-11-17
|
2013-10-14 02:36:58 +00:00
|
|
|
---
|
|
|
|
|
2013-10-14 02:44:03 +00:00
|
|
|
### Usage
|
2017-09-20 08:08:11 +00:00
|
|
|
{: .-prime}
|
2013-09-17 10:06:00 +00:00
|
|
|
|
2017-09-20 08:08:11 +00:00
|
|
|
```bash
|
|
|
|
find <path> <conditions> <actions>
|
|
|
|
```
|
2013-09-17 10:06:00 +00:00
|
|
|
|
2013-10-14 02:44:03 +00:00
|
|
|
### Conditions
|
2013-09-17 10:06:00 +00:00
|
|
|
|
2017-09-20 08:08:11 +00:00
|
|
|
```bash
|
|
|
|
-name "*.c"
|
|
|
|
```
|
|
|
|
|
|
|
|
```bash
|
|
|
|
-user jonathan
|
|
|
|
-nouser
|
|
|
|
```
|
|
|
|
|
|
|
|
```bash
|
|
|
|
-type f # File
|
|
|
|
-type d # Directory
|
|
|
|
-type l # Symlink
|
|
|
|
```
|
|
|
|
|
|
|
|
```bash
|
|
|
|
-depth 2 # At least 3 levels deep
|
|
|
|
-regex PATTERN
|
|
|
|
```
|
|
|
|
|
2018-11-07 22:57:17 +00:00
|
|
|
```bash
|
|
|
|
-size 8 # Exactly 8 512-bit blocks
|
|
|
|
-size -128c # Smaller than 128 bytes
|
|
|
|
-size 1440k # Exactly 1440KiB
|
|
|
|
-size +10M # Larger than 10MiB
|
|
|
|
-size +2G # Larger than 2GiB
|
|
|
|
```
|
|
|
|
|
2019-11-17 05:31:53 +00:00
|
|
|
```bash
|
|
|
|
-newer file.txt
|
|
|
|
-newerm file.txt # modified newer than file.txt
|
|
|
|
-newerX file.txt # [c]hange, [m]odified, [B]create
|
|
|
|
-newerXt "1 hour ago" # [t]imestamp
|
|
|
|
```
|
|
|
|
|
|
|
|
### Access time conditions
|
|
|
|
|
2019-10-01 21:19:11 +00:00
|
|
|
```bash
|
|
|
|
-atime 0 # Last accessed between now and 24 hours ago
|
|
|
|
-atime +0 # Accessed more than 24 hours ago
|
|
|
|
-atime 1 # Accessed between 24 and 48 hours ago
|
|
|
|
-atime +1 # Accessed more than 48 hours ago
|
|
|
|
-atime -1 # Accessed less than 24 hours ago (same a 0)
|
|
|
|
-ctime -6h30m # File status changed within the last 6 hours and 30 minutes
|
|
|
|
-mtime +1w # Last modified more than 1 week ago
|
|
|
|
```
|
|
|
|
|
2019-11-17 05:31:53 +00:00
|
|
|
These conditions only work in MacOS and BSD-like systems (no GNU/Linux support).
|
2013-09-17 10:06:00 +00:00
|
|
|
|
2013-10-14 02:44:03 +00:00
|
|
|
### Condition flow
|
2013-09-17 10:06:00 +00:00
|
|
|
|
2017-09-20 08:08:11 +00:00
|
|
|
```bash
|
2023-01-31 08:57:10 +00:00
|
|
|
\! -name "*.c" # NOT named "*.c"
|
2017-09-20 08:08:11 +00:00
|
|
|
\( x -or y \)
|
|
|
|
```
|
2013-09-17 10:06:00 +00:00
|
|
|
|
2013-10-14 02:44:03 +00:00
|
|
|
### Actions
|
2013-09-17 10:06:00 +00:00
|
|
|
|
2017-09-20 08:08:11 +00:00
|
|
|
```bash
|
|
|
|
-exec rm {} \;
|
|
|
|
-print
|
|
|
|
-delete
|
|
|
|
```
|
2013-09-17 10:06:00 +00:00
|
|
|
|
2013-10-14 02:44:03 +00:00
|
|
|
### Examples
|
2013-09-17 10:06:00 +00:00
|
|
|
|
2017-09-20 08:08:11 +00:00
|
|
|
```bash
|
|
|
|
find . -name '*.jpg'
|
|
|
|
find . -name '*.jpg' -exec rm {} \;
|
|
|
|
```
|
2013-09-17 10:06:00 +00:00
|
|
|
|
2017-09-20 08:08:11 +00:00
|
|
|
```bash
|
|
|
|
find . -newerBt "24 hours ago"
|
|
|
|
```
|
2019-10-01 21:19:11 +00:00
|
|
|
|
|
|
|
```bash
|
|
|
|
find . -type f -mtime +29 # find files modified more than 30 days ago
|
2023-01-31 08:57:10 +00:00
|
|
|
find . -type f -newermt 2016-08-07 \! -newermt 2016-08-08 # find in date range
|
2019-10-01 21:19:11 +00:00
|
|
|
```
|