文件查找/打包压缩

一、文件查找

1、which/whereis/whatis

which 只能查询命令
[root@aliyun ~]# which ls
alias ls='ls --color=auto'
	/usr/bin/ls

whereis 可以查看命令和配置文件的位置
[root@aliyun ~]# whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz

whatis 查询命令在哪章和下面一样
[root@aliyun ~]# whatis ls
ls (1)               - list directory contents
[root@aliyun ~]# man -f ls
ls (1)               - list directory contents

2、locate

维护着一个查询数据库
[root@qfedu.com ~]# vim /etc/updatedb.conf
1)文件系统类型
2)目录
如果被更改之后,需要更新数据库
[root@qfedu.com ~]# updatedb 手动更新数据库

[root@qfedu.com ~]# locate 被查找的关键字
[root@qfedu.com ~]# locate *.txt
*是通配符 

3、find

语法
find  查找位置 查找条件

按名称来查找
-name	文件名	
-iname	不区分大小写
find /etc -name 'passwd' 
[root@t1 ~]# find /etc -name passwd
/etc/pam.d/passwd
/etc/passwd

按大小查找
-zise	文件类型
[root@t1 ~]# find /etc/ -size +1M
/etc/selinux/targeted/contexts/files/file_contexts.bin
/etc/selinux/targeted/policy/policy.31

[root@t1 ~]# find /etc/ -size -1M
/etc/crypttab
/etc/environment

查找大于1M小于10M的文件
-a可以换成-and
-o可以换成-or
[root@t1 ~]# find /etc -size +1M -a -size -10M
/etc/selinux/targeted/contexts/files/file_contexts.bin
/etc/selinux/targeted/policy/policy.31

按文件类型查找
-type
[root@t1 ~]# find /etc -type  d
/etc
/etc/fonts

-exec 对之前查找出来的文件做进一步操作
-ok   和-exec一样,只不过多了提示
[root@t1 opt]# find /opt -name 'a.txt' -exec rm -f {} \;
[root@t1 opt]# find /opt -name 'aa.txt' -ok rm -f {} \;
< rm ... /opt/aa.txt > ? y

按时间查找
time表示单位是天
min 表示分钟
-atime			-mtime			-ctime	
-amin			-mmin			-cmin
access时间		modify时间		 change时间

查找两分钟前访问过的文件
[root@qfedu.com ~]# find /tmp -amin -2
/tmp/a.txt

二、文件打包及压缩

归档:
	[root@qfedu.com ~]# tar cvf file.tar 被打包的文件 ...
	[root@qfedu.com ~]# tar cvf abc.tar a b c d e
	
解包:
	[root@qfedu.com ~]# tar xvf 打包文件 -C  /opt/
	-C 指定解包路径

gzip类型的归档压缩
# tar cvzf  test.tar.gz    a.txt b.txt file1 file2
# tar xvzf  test.tar.gz

c create  创建
v verbose 显示详细过程
f file
x extract 抽取 解开
z gzip类型
j bzip2类型

bzip2类型的归档压缩
# tar cvjf  test.tar.bz2   a.txt b.txt file1 file2
# tar xvjf  test.tar.bz2



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值