find 命令实践
来源:互联网 发布:中药方剂软件下载 编辑:程序博客网 时间:2024/05/20 16:32
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 {} \;
参考资料
1. 15 Practical Linux Find Command Examples
- find 命令实践
- linux find命令实践
- 18、find命令之xargs(还没实践用)
- find 命令
- find 命令
- find 命令
- find命令
- find命令
- find 命令
- find命令
- FIND命令
- find 命令
- find命令
- find命令
- find 命令
- Find命令
- find命令
- FIND 命令
- 文字字符串长度截取
- TCP可靠传输的实现
- LINQ to XML 实战
- 字符串常量与字符串变量
- SQL 左外连接,右外连接,全连接,内连接
- find 命令实践
- java用于form表单/页面回填的工具类
- 2D光影引擎
- cvs commit: sticky tag `someTag' for file `***' is not a branch
- android 关于横竖屏问题
- linux下C语言链接Mysql数据库的两个注意的小问题
- Mindmanager保存PDF文件时,作者更改及相关信息更改
- Session,ViewState用法
- fstatfs/statfs函数详解