OSDN Git Service

Regular updates
[twpd/master.git] / find.md
1 ---
2 title: Find
3 category: CLI
4 layout: 2017/sheet
5 ---
6
7 ### Usage
8 {: .-prime}
9
10 ```bash
11 find <path> <conditions> <actions>
12 ```
13
14 ### Conditions
15
16 ```bash
17 -name "*.c"
18 ```
19
20 ```bash
21 -user jonathan
22 -nouser
23 ```
24
25 ```bash
26 -type f            # File
27 -type d            # Directory
28 -type l            # Symlink
29 ```
30
31 ```bash
32 -depth 2           # At least 3 levels deep
33 -regex PATTERN
34 ```
35
36 ```bash
37 -size 8            # Exactly 8 512-bit blocks 
38 -size -128c        # Smaller than 128 bytes
39 -size 1440k        # Exactly 1440KiB
40 -size +10M         # Larger than 10MiB
41 -size +2G          # Larger than 2GiB
42 ```
43
44 ```bash
45 -newer   file.txt
46 -newerm  file.txt        # modified newer than file.txt
47 -newerX  file.txt        # [c]hange, [m]odified, [B]create
48 -newerXt "1 hour ago"    # [t]imestamp
49 ```
50
51 ### Condition flow
52
53 ```bash
54 \! -name "*.c"
55 \( x -or y \)
56 ```
57
58 ### Actions
59
60 ```bash
61 -exec rm {} \;
62 -print
63 -delete
64 ```
65
66 ### Examples
67
68 ```bash
69 find . -name '*.jpg'
70 find . -name '*.jpg' -exec rm {} \;
71 ```
72
73 ```bash
74 find . -newerBt "24 hours ago"
75 ```