Skip to content

Instantly share code, notes, and snippets.

@ibreathebsb
Last active August 22, 2018 01:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ibreathebsb/aa8da236c8284cf34b876b95421e4224 to your computer and use it in GitHub Desktop.
Save ibreathebsb/aa8da236c8284cf34b876b95421e4224 to your computer and use it in GitHub Desktop.

which

在用户的目录($PATH)下查找指定的可执行文件

~ which ifconfig
/sbin/ifconfig

which -a ifconfig -a 列出所有可执行文件,而不只是第一个

whereis

whereis locates the binary, source and manual files for the specified command names

whereis 查找指定命令的二进制文件、源文件和手册文件

-b 只查找二进制程序

-s 只查找源文件

-m 只查找帮助手册

whichwhereis不同之处在于which只定位可执行文件,而whereis则会查找可执行文件、源文件以及手册文件

locate

从文件数据库中查找指定的文件,速度较快

find

在文件系统中查找指定文件 find [PATH] [option] [action]

几个常用的选项

find / -user username somefile find / -uid n somefile 查找某个用户的文件

find / -group groupname somefile find / -gid n somefile 查找某个群组的文件

find / -name somefile 查找名为somfile的文件

find / -type TYPE 查找指定类型的文件

find / -size +-SIZE 查找大于或者小于指定大小的文件

find / -mtime|-atime|-mtime n|+n|-n 按照时间查找文件: <---(+n)-(n)(-n)---->now

find / -perm [+|-]mode 查找指定权限的文件, -mode表示文件的权限必须包括mode的所有权限,例如find / 0755寻找rwxr-xr-x的文件,那么777的文件也会别算入其中;而+mode表示目标文件的权限必须至少有一位和mode相同,例如find / 7000寻找--s--s--t的文件,那么权限为1000--------t的文件也会被列入其中,因为t符合了

上一条已废弃

find / -perm [/|-]mode 查找指定权限的文件,mode表示权限精确匹配的文件;-mode表示文件的权限必须包括mode的所有权限,例如find / -0755寻找rwxr-xr-x的文件,那么777的文件也会别算入其中;而/mode表示目标文件的权限必须至少有一位和mode相同,例如find / /7000寻找--s--s--t的文件,那么权限为1000--------t的文件也会被列入其中,因为t符合了

find ./ -perm /7000 -exec ls -l '{}' \; -exec表示执行后面的命令, 即ls -l file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment