指令:
locate:查询数据库 tar -cf:打包,压缩 z是gzip j是bzip J是xzip
updatedb:手动更新数据库 tar -xvf:解压缩 -C:重定向解压目录
find 路径 -name “文件名”:按文件名查找 -iname(忽略大小写) tar -tf:查看压包内容
find 路径 -size :按文件大小查找
find 路径 -maxdepth(最大深度)、-mindepth:指定查找的目录深度
find 路径 -atime -mtime -ctime:按时间查找 stat查看时间
atime:(access:接近 time)显示的是文件中的数据最后被访问的时间 发送方:tar -cf - 目录 | nc ip地址 密码
mtime:(modify :修改time)显示的是文件内容被修改的最后时间 接受方:nc -l 密码 | tar -xf - -C 路径
ctime:(change:改变 time)显示的是文件的权限、拥有者、所属的组、
链接数发生改变时的时间
find 路径 -user -group -nouser(缺失UID的文件) :按文件属主属组找
find 路径 -type(类型) :按文件类型查找
f:普通 d:目录 l:链接 b:块设备 c:字符设备 s:套接字 p:管道文件
find 路径 -perm(烫发) 664(精确) -664(包含):按文件权限查找
which :命令查找 grep: 文件内容过滤
*********************************************************************************************************************************************************************************************
简介:
grep: 文件内容过滤
find: 文件查找,针对文件名;locate:文件查找,依赖数据库
which :命令查找
文件查找
一、命令文件查找
一、查找ls 命令的位置
# which ls //从PATH环境变量
或者
# whereis vim
二、任意文件
locate
A. locate (查询的数据库: /var/lib/mlocate/mlocate.db)
计划任务:每天自动更新数据库 /etc/cron.daily/mlocate.cron
手动更新数据库:updatedb
#touch abc.txt
#locate abc.txt
无,为什么
#updatedb
#locate abc.txt
有,为什么
#rm -rf abc.txt
#locate abc.txt
有,为什么
#updatedb
#locate abc.txt
无,为什么
如果你的机器没有locate命令,你该怎么办呢?
yum provides locate
yum install -y mlocate
课后问题
在mnt目录中的文件无法用locate搜索。
因为配置文件中有排除查找路径。
/etc/updatedb.conf
第一行PRUNE_BIND_MOUNTS="yes"的意思是:是否进行限制搜索。
第二行是排除检索的文件系统类型,即列出的文件系统类型不进行检索。
第二行表示对哪些后缀的文件排除检索,也就是列在这里面的后缀的文件跳过不进行检索。不同后缀之间用空格隔开。
第四行是排除检索的路径,即列出的路径下的文件和子文件夹均跳过不进行检索。updatedb之后使用locate仍然找不到想要文件
find
语法
find [path...] [options] [expression] [action]
按文件名:-name
[root@tianyun ~]# find /etc -name "ifcfg-ens32"
[root@tianyun ~]# find /etc -iname "ifcfg-ens32" //-i忽略大小写
[root@tianyun ~]# find /etc -iname "ifcfg-ens*"
按文件大小:-size
[root@tianyun ~]# find /etc -size +5M //大于5M
[root@tianyun ~]# find /etc -size 5M //等于5M
[root@tianyun ~]# find /etc -size -5M //小于5M
[root@tianyun ~]# find /etc -size +5M -ls //-ls找到的处理动作
指定查找的目录深度:-maxdepth -mindepth
-maxdepth levels
-mindepth levels
[root@tianyun ~]# find / -maxdepth 3 -a -name "ifcfg-en*"
[root@tianyun ~]# find / -maxdepth 4 -a -name "ifcfg-en*"
按时间找(atime,mtime,ctime):
时间的概念
atime:(access time)显示的是文件中的数据最后被访问的时间,比如系统的进程直接使用或通过一些命令和脚本间接使用。(执行一些可执行文件或脚本)
mtime: (modify time)显示的是文件内容被修改的最后时间,比如用vi编辑时就会被改变。(也就是Block的内容)
ctime: (change time)显示的是文件的权限、拥有者、所属的组、链接数发生改变时的时间。当然当内容改变时也会随之改变(即inode内容发生改变和Block内容发生改变时)
案例
按时间找(atime,mtime,ctime):
[root@tianyun ~]# find /etc -mtime +5 //修改时间超过5天
[root@tianyun ~]# find /etc -mtime 5 //修改时间等于5天
[root@tianyun ~]# find /etc -mtime -5 //修改时间5天以内
按文件属主、属组找:-user -group
[root@tianyun ~]# find /home -user jack //属主是jack的文件
[root@tianyun ~]# find /home -group hr //属组是hr组的文件
[root@tianyun ~]# find /home -nouser //缺失UID的文件
按文件类型(了解):-type
[root@tianyun ~]# find /dev -type f //f普通
[root@tianyun ~]# find /dev -type d //d目录
[root@tianyun ~]# find /dev -type l //l链接
[root@tianyun ~]# find /dev -type b //b块设备
[root@tianyun ~]# find /dev -type c //c字符设备
[root@tianyun ~]# find /dev -type s //s套接字
[root@tianyun ~]# find /dev -type p //p管道文件
按文件权限:-perm
普通权限
[root@tianyun ~]# find . -perm 644 -ls //精确权限
[root@tianyun ~]# find . -perm -644 -ls //包含权限即可
特别权限
[root@tianyun ~]# find /usr/bin /usr/sbin -perm -4000 -ls //包含set uid
[root@tianyun ~]# find /usr/bin /usr/sbin -perm -2000 -ls //包含set gid
[root@tianyun ~]# find /usr/bin /usr/sbin -perm -1000 -ls //包含sticky
按正则表达式:(了解)
[root@tianyun ~]# find /etc/ -regex '.*ifcfg-ens3[0-9]'
找到后处理的动作 ACTIONS:
类型
-print 打印,默认选项
-ls
-delete
-exec 后面跟自定义的shell命令
-ok 后面跟自定义的shell命令
示例
# find /etc -name "ifcfg*"
# find /etc -name "ifcfg*" -print
# find /etc -name "ifcfg*" -ls
# find /etc -name "775*" -delete /775.txt是自定义文件
# find /etc -name "ifcfg*" -exec cp -rvf {} /tmp \; //不提示
# find /etc -name "ifcfg*" -ok cp -rvf {} /tmp \; //提示
# find /etc -name "775*" -exec rm -rf {} \;
简介:
tar命令是Unix/Linux系统中备份文件的可靠方法,几乎可以工作于任何环境中,它的使用权限是所有用户。
建议针对目录
文件打包及压缩
打包,压缩
语法:tar 选项 压缩包名称 源文件
===打包,压缩===
# tar -cf etc.tar /etc
观察三个包的体积。 # ll -h etc*
# tar -czf etc-gzip.tar.gz /etc/ //z是gzip -rw-r--r--. 1 root root 11M 10月 14 10:07 etc-gzip.tar.gz
# tar -cjf etc-bzip.tar.bz /etc/ //j是bzip -rw-r--r--. 1 root root 8.9M 10月 14 10:08 etc-bzip.tar.bz
# tar -cJf etc-xzip.tar.xz /etc/ //J是xzip -rw-r--r--. 1 root root 7.6M 10月 14 10:08 etc-xzip.tar.xz
压缩速度和压缩体积成反比。
file etc.tar.gz
解压,解包
查看
# tar -tf etc.tar //t查看f文件名
解压缩
# tar xf etc3.tar.xz //简单粗暴
# tar -xvf etc2.tar.bz2 -C /tmp //-C重定向到//tmp目录
解压zip
==解压zip
# unzip xxx.zip
案例(海量小文件)(了解)
案例4:host A /etc (海量小文件) --------> host B /tmp
常规方法:
[root@localhost ~]# scp -r /etc 172.16.20.21:/tmp
扩展方法nc方法:
==host B 监听端口(192.168.100.20:8888)==
[root@hostb ~]# systemctl stop firewalld.service
[root@hostb ~]# nc -l 8888 |tar -xzf - -C /tmp //启动监听程序8888
==host A 连接B 的端口==
[root@localhost ~]# tar -czf - /etc | nc 192.168.100.20 8888
tar: Removing leading `/' from member names
本文详细介绍了在Linux系统中查找文件的各种方法,包括使用`locate`、`find`和`grep`命令,以及如何打包和压缩文件,如gzip、bzip2和xzip。此外,还讲解了如何通过`updatedb`更新数据库,以及如何解压缩。同时,文章提到了文件查找的多种条件,如文件大小、时间戳和文件属性。最后,探讨了在海量文件传输中使用nc命令进行远程解压缩的高效方法。
1049

被折叠的 条评论
为什么被折叠?



