-
Notifications
You must be signed in to change notification settings - Fork 3
/
find
60 lines (41 loc) · 2.02 KB
/
find
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# To find files by case-insensitive extension (ex: .jpg, .JPG, .jpG):
find . -iname "*.jpg"
# To find directories:
find . -type d
# To find files:
find . -type f
# To find files by octal permission:
find . -type f -perm 777
# To find files with setuid bit set:
find . -xdev \( -perm -4000 \) -type f -print0 | xargs -0 ls -l
# To find files with extension '.txt' and remove them:
find ./path/ -name '*.txt' -exec rm '{}' \;
# To find files with extension '.txt' and look for a string into them:
find ./path/ -name '*.txt' | xargs grep 'string'
# To find files with size bigger than 5 Mb and sort them by size:
find . -size +5M -type f -print0 | xargs -0 ls -Ssh | sort -z
# To find files bigger thank 2 MB and list them:
find . -type f -size +20000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
# To find files modified more than 7 days ago and list file information
find . -type f -mtime +7d -ls
# To find symlinks owned by a user and list file information
find . -type l --user=username -ls
# To search for and delete empty directories
find . -type d -empty -exec rmdir {} \;
# To search for directories named build at a max depth of 2 directories
find . -maxdepth 2 -name build -type d
# To search all files who are not in .git directory
find . ! -iwholename '*.git*' -type f
# Find all files that have the same node (hard link) as MY_FILE_HERE
find . -type f -samefile MY_FILE_HERE 2>/dev/null
# like repo forall by by find
find . -type d -name '*.git' | cut -c 3- | while read REPO_PROJECT; do (cd $REPO_PROJECT; git remote add ts file:///home/gerrit2/review_site/git/asr/$REPO_PROJECT); done
find . -type d -name '*.git' | cut -c 3- | while read REPO_PROJECT; do (cd $REPO_PROJECT; git push ts --all); done
# delete old file by find
find /path/to/ -type f -mtime +5 -name '*.gz' -execdir rm -- '{}' \;
# find all git project in gerrit
find . -name "*.git" | grep -v ".repo" | wc -l
# rm all empty dir recursively
while [ -n "$(find . -depth -type d -empty -print -exec rmdir {} +)" ]; do :; done
# rm all empty dir
find . -type d -empty -delete