dd find exec

来源:互联网 发布:java方法高并发 编辑:程序博客网 时间:2024/06/11 09:46

给file1文件大小增加到3M
[root@localhost mnt]# touch file1 file2
[root@localhost mnt]# ll
总用量 0
-rw-r–r– 1 root root 0 7月 19 11:41 file1
-rw-r–r– 1 root root 0 7月 19 11:26 file2
[root@localhost mnt]# dd if=/dev/zero of=file1 bs=1M count=3 (用零源源不断地填充file1文件)
记录了3+0 的读入
记录了3+0 的写出
3145728字节(3.1 MB)已复制,0.00323493 秒,972 MB/秒
[root@localhost mnt]# ll
总用量 3072
-rw-r–r– 1 root root 3145728 7月 19 11:42 file1
-rw-r–r– 1 root root 0 7月 19 11:26 file2
找出/mnt目录下文件大小大于2M的文件并删除
[root@localhost mnt]# find -type f -size +2M -exec rm -f {} \;
[root@localhost mnt]# find -type f -size +2M | xargs rm -f ;
[root@localhost mnt]# ll
总用量 0
-rw-r–r– 1 root root 0 7月 19 11:26 file2

-exec
1.参数是一个一个传递的,传递一个参数执行一次rm
2.文件名有空格等特殊字符也能处理
-xargs
1.一次将参数传给命令,可以使用-n控制参数个数
2.ls cp rm 不支持直接管道符,需要传递参数xargs