find 命令实践

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 {} \;


参考资料

1. 15 Practical Linux Find Command Examples

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值