【linux 文件管理】9-文件查找和压缩

https://edu.aliyun.com/lesson_1733_14280?spm=5176.10731542.0.0.62af1acb9dHjn1#_14280

  • locate文件查找,基于数据库,不影响服务器性能
    type locate
    locate --help
    locate test.sh
    它搜索的是locate的数据库,把之前的文件记录在数据库中
    touch aaa
    locate aaa
    updatedb 更新locate数据库
    ll /var/lib/mlocate/mlocate.db
    locate aaa

locate ".sh"
locate -i "
.sh" 不区分大小写
locate -n "*.sh" 显示前几个
locate -r ".sh$" 正则

  • find实时查找,遍历指定路径,会影响服务器性能
    需要读取和执行的权限
    tree /data/ -d
    ls /data
    touch /data/f1.sh
    find /data 默认递归文件下的所有目录

只搜索data目录本身
find /data -maxdepth 1
find /data -depth 先处理文件再处理目录
find /data -name "test"
find /data -iname "test" 忽略大小写

ll /data/f1.sh -i
find /data -inum 68
ln /data/f1.sh /data/f11.sh
find --help
man find
samefile
find /data -samefile /data/f1.sh
find /data -links 2
find /data -regex '.*.sh$'

find /data -user wang -ls
getent passwd
su - user1
cd /data
touch user1.txt
ll -d .
exit
chmod a+w /data
ll -d
su -user1
touch user1.txt
ll
exit
userdel user1
ll
find /data -nouser 搜索没有所有者
find /data -nogroup
chown wang user1.txt
find /data -nouser

find /data -type -d 搜目录
find /data -type -f 普通文件
find /data -type -l 符号链接 s套接字 b块设备 c字符设备 p管道文件

ln -s f11.sh f11_link 软链接
find -type l
find -empty 搜空文件
find -empty -ls

与-a 或-o 非 -not,!
find -name ".sh" -user root -l
find -name "
.sh" -o -user root -ls
find ( -name "*.sh" -o -user root ) -ls

原文地址:https://www.cnblogs.com/sec875/p/13414194.html