1. 查找/拷贝 当前目录下包含dog字符串的文件
test$ tree
.
|-- des
`-- src
|-- mycat.c
|-- mydog.c
|-- mydog.h
|-- readme
|-- yourdog.c
`-- yourdog.h
2 directories, 6 files
test$ find ./src -name "*dog*" -print
./src/mydog.c
./src/yourdog.c
./src/yourdog.h
./src/mydog.h
test$ find ./src -name "*dog*" -exec cp {} ./des \;
test$ tree
.
|-- des
| |-- mydog.c
| |-- mydog.h
| |-- yourdog.c
| `-- yourdog.h
`-- src
|-- mycat.c
|-- mydog.c
|-- mydog.h
|-- readme
|-- yourdog.c
`-- yourdog.h
2 directories, 10 files
2. 删除包含特殊字符的文件
sandbox$ ll
total 72K
-rw-r--r-- 1 fan fan 68K 2011-09-15 13:38 help_find
-rw-r--r-- 1 fan fan 422 2011-09-08 13:39 test-history
sandbox$ ll -i
total 72K
133800 -rw-r--r-- 1 fan fan 68K 2011-09-15 13:38 help_find
156665 -rw-r--r-- 1 fan fan 422 2011-09-08 13:39 test-history
sandbox$ find -inum 133800 -print
./help_find
sandbox$ find -inum 133800 -exec rm {} \;
sandbox$ ll
total 4.0K
-rw-r--r-- 1 fan fan 422 2011-09-08 13:39 test-history
3. find the files not check out and remove them
find . -perm 444 -type f -print
find . -perm 444 -type f -exec rm -f {} \;
4. find the files bigger than 1M size and remove them
find . -size +1000000c -print
find . -size +1000000c -exec rm {} \;
5. find and delete vim temp files
find . -name ".*swp" -print
find . -name ".*swp" -exec rm {} \;
test$ tree
.
|-- des
`-- src
|-- mycat.c
|-- mydog.c
|-- mydog.h
|-- readme
|-- yourdog.c
`-- yourdog.h
2 directories, 6 files
test$ find ./src -name "*dog*" -print
./src/mydog.c
./src/yourdog.c
./src/yourdog.h
./src/mydog.h
test$ find ./src -name "*dog*" -exec cp {} ./des \;
test$ tree
.
|-- des
| |-- mydog.c
| |-- mydog.h
| |-- yourdog.c
| `-- yourdog.h
`-- src
|-- mycat.c
|-- mydog.c
|-- mydog.h
|-- readme
|-- yourdog.c
`-- yourdog.h
2 directories, 10 files
2. 删除包含特殊字符的文件
sandbox$ ll
total 72K
-rw-r--r-- 1 fan fan 68K 2011-09-15 13:38 help_find
-rw-r--r-- 1 fan fan 422 2011-09-08 13:39 test-history
sandbox$ ll -i
total 72K
133800 -rw-r--r-- 1 fan fan 68K 2011-09-15 13:38 help_find
156665 -rw-r--r-- 1 fan fan 422 2011-09-08 13:39 test-history
sandbox$ find -inum 133800 -print
./help_find
sandbox$ find -inum 133800 -exec rm {} \;
sandbox$ ll
total 4.0K
-rw-r--r-- 1 fan fan 422 2011-09-08 13:39 test-history
3. find the files not check out and remove them
find . -perm 444 -type f -print
find . -perm 444 -type f -exec rm -f {} \;
4. find the files bigger than 1M size and remove them
find . -size +1000000c -print
find . -size +1000000c -exec rm {} \;
5. find and delete vim temp files
find . -name ".*swp" -print
find . -name ".*swp" -exec rm {} \;
参考资料