查找命令:which + 命令
[root@weijie /]# which ls
alias ls='ls --color=auto'
/usr/bin/ls
查找命令:whereis + 命令
[root@weijie /]# whereis pwd
pwd: /usr/bin/pwd /usr/include/pwd.h /usr/share/man/man1/pwd.1.gz
查找命令:locate + 命令(模糊度高,不常用)
需要安装lacate模块
yum install -y mlocate
updatedb
locate pwd
查找文件:find (有多种用法,很常用)
find -type -name -atime -ctime -mtime
可以从文件类型,文件名字,活动时间,创建时间,修改时间进行查找。
查目录:
[root@weijie tmp]# find ./ -type d
./
./.Test-unix
./.X11-unix
./.font-unix
./.XIM-unix
./.ICE-unix
./test
./systemd-private-f666249a23d44fce956b325628f1e7eb-vgauthd.service-0Aqrdf
./systemd-private-f666249a23d44fce956b325628f1e7eb-vgauthd.service-0Aqrdf/tmp
./systemd-private-f666249a23d44fce956b325628f1e7eb-vmtoolsd.service-lAG0Mi
./systemd-private-f666249a23d44fce956b325628f1e7eb-vmtoolsd.service-lAG0Mi/tmp
./systemd-private-f666249a23d44fce956b325628f1e7eb-vmtoolsd.service-lAG0Mi/tmp/vmware-root
查找了当前文件下的所有目录。
查文件
[root@weijie tmp]# find ./ -type f
./yum.log
./ks-script-fMorpH
./test/1.txt
查找了当前目录下的所有文件。
按照文件名字查文件
格式:find + 文件所在的目录 -name + 文件名(支持模糊匹配)
[root@weijie tmp]# find /tmp/test/ -name 1.txt
/tmp/test/1.txt
[root@weijie tmp]# find /tmp/test/ -name *.txt
/tmp/test/1.txt
有的时候需要转译符/
按更改时间来查找文件:
[root@weijie tmp]# find /tmp/test/ -mtime -2
/tmp/test/
/tmp/test/1.txt
-2 代表更改时间在两天内的文件 +2 代表更改时间在两天外的文件
2代表两天更改的文件
当然还有其他的方式,下面就是列举,不做案例。
查找文件更新日时在距现在时刻二分以上的文件
find ./ -mmin +2
查找文件更新日时在距现在时刻一分以上二分以内的文件
find ./ -mmin 2
查找文件更新时间比文件abc的内容更新时间新的文件
find ./ -newer abc
查找文件访问时间比文件abc的内容更新时间新的文件
find ./ -anewer abc
查找空文件或空目录
find ./ -empty
查找空文件并删除
find ./ -empty -type f -print -delete
查找权限为644的文件或目录(需完全符合)
find ./ -perm 664
查找用户/组权限为读写,其他用户权限为读(其他权限不限)的文件或目录
find ./ -perm -664
查找用户有写权限或者组用户有写权限的文件或目录
find ./ -perm /220
find ./ -perm /u+w,g+w
find ./ -perm /u=w,g=w
查找所有者权限有读权限的目录或文件
find ./ -perm -u=r
查找用户组权限有读权限的目录或文件
find ./ -perm -g=r
查找其它用户权限有读权限的目录或文件
find ./ -perm -o=r
查找所有者为lzj的文件或目录
find ./ -user lzj
查找组名为gname的文件或目录
find ./ -group gname
查找文件的用户ID不存在的文件
find ./ -nouser
查找文件的组ID不存在的文件
find ./ -nogroup
查找有执行权限但没有可读权限的文件
find ./ -executable ! -readable
查找文件size小于10个字节的文件或目录
find ./ -size -10c
查找文件size等于10个字节的文件或目录
find ./ -size 10c
查找文件size大于10个字节的文件或目录
find ./ -size +10c
查找文件size小于10k的文件或目录
find ./ -size -10k
查找文件size小于10M的文件或目录
find ./ -size -10M
查找文件size小于10G的文件或目录
find ./ -size -10G
stat 查看文件的信息,创建时间,更改时间…
[root@weijie tmp]# stat test
File: ‘test’
Size: 19 Blocks: 0 IO Block: 4096 directory
Device: 803h/2051d Inode: 337 Links: 2
Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:user_tmp_t:s0
Access: 2020-02-26 19:55:22.199895900 +0800
Modify: 2020-02-26 19:55:20.275896031 +0800
Change: 2020-02-26 19:55:20.275896031 +0800
Birth: -