第十章 其他常用工具

来源:互联网 发布:java treemap是红黑树 编辑:程序博客网 时间:2024/06/06 20:38

1、一般删除

删除一个目录下所有“.O”文件,并将对应目录保存到文件mlkk.list

$ find ./ -name *.o  -print -exec rm '{}' \; > mlkk.list

特殊说明:

2、特殊删除

rm -f `find . -name \*.o -print`

如果搜索到的文件在rm可容纳的删除范围之内,则可按照上述操作,否则会失败 ,则可:

find   .-name \*.o  -print | tee file.list | xargs rm -f

xargs 语法格式:

command1 | xargs command2

命令command1的标准输出,xargs 把从标准输入得到的若干字符串当做命令行参数来执行command2.

3、查找几天前修改过的一个文件

(1)、 find . type f -mtime +5 -print  //查找5天前修改的文件

(2)、find . type f  -mtime +3 -mtime -4 -print   //查找3天前4天内

备注:

a、-mtime 选项参数n为天数

-mtime  n  //修改的时间等于n天

-mtime  +n  // 多余n天

-mtime  -n //少于n天

b、搜索文件类型

-type f  //搜索普通文件                      -type p  //搜索命名的管道文件

-type  l // 搜索链接文件                     -type s   //搜索socket文件

-type  d  //搜索目录                            -type  b  // 搜索块设备文件

-type c  //搜索字符设备文件

4、其他查找文件的方法

比find更快的搜索文件的方法

locate 会通过查询一个本地的数据库来搜索文件名

eg: locate whereis    //查找文件名中包含whereis的文件

locate -b whereis  // 不搜索中间路径,只匹配文件名

locate -b   '\whereis'   //精确匹配文件名

(locate默认会搜索本地数据库 /var/lib/mlocate/mlocate.db)    -b   或 -basename  过滤信息

备注: 通常后台程序每天会执行一次update命令来更新 本地数据库 mlocate.db

file 文件名    // 可以判断文件类型

5、数据备份

命令dd

eg:

dd if=/dev/sda3 of=sda.img //把分区sda3备份到文件sda.img

dd格式:

dd if = [FILE]  of = [FILE] count=[Blocks] bs=[BYTES]

选项 if (input file)  of (output file)

count:指定在数据复制过程中只复制Blocks个输入块,bs指定了块的大小。

dd命令复制的总字节数等于 BYTES*BLOCKS。

默认使用512字节。

6、下载工具

wget 与curl

eg: wget ftpgnu.org/pub/gnu/make/make-3.8.tar.gz

curl 与wget类似,只不过会把下载的数据打印到终端屏幕上,如果需要在硬盘保存文件,需要重定向到一个文件

eg:   curl   http://ftpgnu.org/.../ .tar.gz  > make-3.8.tar.gz


原创粉丝点击