find 的命令是强大, 要会用才好

 

关于 find 的高级应用:

1: change the file owner: tt --> test1
  find . -name tt -exec chown test1 {} \;
 
2: rename or remove the specified file
  find . -inum 11111 -exec mv {} new_file \;
  find . -inum 11111 -exec rm {} \;
 
  future step:
  find . -user tt -exec cp {} ./file \;
  find . -inum 11111 -exec cp {} ./file \;
 
 
4:查找文件权限 700:/ 查找文件权限非400
  find . -perm 700  / find . ! -perm 400

 

5,对大文件进行转移:

find . -size +3000000
会把大于3G 的文件列出来
如果要转移的话: find . -size +3000000 -exec cp '{}' /tmp ';'

 

2012-11-04  进行的change (action):

对一个文件系统下东西进行转移:

find /tmp/a/ -mtime +100 -exec mv '{}' /tmp/bk/ ';'

(注意,这个/tmp/a/ 下面的文件可能有文件夹,执行脚本的时候,会有报错,警告,但是,没有关系,看看/tmp/bk/ 下面已经有文件转移过去,并且/tmp/a下面已经没有就可以了)

(这个操作没有压缩,是因为 怕原来的 文件系统会因为压缩,是原来的file system 撑暴

---------------

20110923 补充:

找出100 天的东西:(一定要写path, 很危险)

find /oracle/ ora102/admin/bdump -mtime +100 -exec  rm {} \;

 

20111024 补充:

找出30天以前 以log 结尾的删除:

find . -name "*.log" -mtime +30 -exec rm {} \;

 

20120817补充:

今天移动文件饿时候 报错:

./t/sheng is identical

解决方法:

find . -name "sheng*" -exec cp -R {} /t \;

注意-R 的用法。

 

找出并且删掉,注意,上面command 一定要写好路径(path) 因为是 rm, 一定要小心。

 

20121031 更新:

测试目的:
改变特定文件的权限:

先创建3个文件:
cd /tmp/test

touch a b c
ls
-rw-r--r--  1 root system a
-rw-r--r--  1 root system b
-rw-r--r--  1 root system c

chmod o+x `find /tmp/test/ -mtime -1`

看一下测试结果:

cd /tmp/test
ls

-rw-r--r-x  1 root system a
-rw-r--r-x  1 root system b
-rw-r--r-x  1 root system c

---------


下面接着测试:

打包:一些特定文件:

tar -cvf 1.tar `find /tmp/test/ -mtime -1`

压缩:

压缩到指定目录:

tar -zxvf /home/images.tar.gz -C /specific dir

 

----

20150806 update:

在linux下使用find命令时,报错:find: missing argument to `-exec'

在{}和\之间必须要有空格,否则会报上面的错。

for example: find . -name *.txt -exec ls -l {} \;

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

shenghuiping2001

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值