Linux系统常见的根目录结构:
-
/
(根目录) -
/boot
(引导装入程序的静态文件) -
/dev
(设备文件) -
/etc
(主机特定的系统配置) -
/lib
(基本共享库和核心模块) -
/mnt
(临时挂装文件系统的挂装点) -
/opt
(附加的应用程序软件包) -
/sbin
(基本系统二进制文件) -
/tmp
(临时文件) -
/usr
(辅助层次结构) -
/var
(可变数据)
+---------+-----------------+-------------+
当您在命令行上运行程序时,bash 实际上搜索目录列表来查找您所请求的程序。 但是,bash 引用一个名为
| | 可共享 | 不可共享 |
+---------+-----------------+-------------+
|静态 | /usr | /etc |
| | /opt | /boot |
+---------+-----------------+-------------+
|可变 | /var/mail | /var/run |
| | /var/spool/news | /var/lock |
+---------+-----------------+-------------+
FHS与查找文件:
PATH:
PATH
的环境变量,它是一个用冒号分隔的目录列表
[root@rcc-pok-idg-2305 /]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root@rcc-pok-idg-2305 /]# which --help
Usage: /usr/bin/which [options] [--] programname [...]
Options: --version, -[vV] Print version and exit successfully.
--help, Print this help and exit successfully.
--skip-dot Skip directories in PATH that start with a dot.
--skip-tilde Skip directories in PATH that start with a tilde.
--show-dot Don't expand a dot to current directory in output.
--show-tilde Output a tilde for HOME directory for non-root.
--tty-only Stop processing options on the right if not on tty.
--all, -a Print all matches in PATH, not just the first
--read-alias, -i Read list of aliases from stdin.
--skip-alias Ignore option --read-alias; don't read stdin.
--read-functions Read shell functions from stdin.
--skip-functions Ignore option --read-functions; don't read stdin.
whereis - locate the binary, source, and manual page files for a command
find 和通配符:
可以在-name
的参数中使用“glob”通配符,前提条件是您用双引号引用了它们或用反斜杠进行了转义
使用-iname
来进行不区分大小写的搜索
find与正则表达式:
$ find /etc -iregex '.*xt.*'
/etc/X11/xkb/types/extra
/etc/X11/xkb/semantics/xtest
/etc/X11/xkb/compat/xtest
/etc/X11/app-defaults/XTerm
-iregex
选项,该选项忽略模式中的大小写
注意:find
要求指定的正则表达式与整个路径匹配,而不只是该路径的一部分。为此,指定前导和尾随的.*
是必要的
如:[root@rcc-pok-idg-2305 /]# find /etc -iregex 'xt'
[root@rcc-pok-idg-2305 /]#
而[root@rcc-pok-idg-2305 /]# find /etc -iregex '.*xt.*'
/etc/racoon/psk.txt
/etc/DIR_COLORS.xterm
/etc/skel/.mozilla/extensions
/etc/selinux/targeted/modules/active/file_contexts.template
find -type选项:
-type
参数是b
(块设备)、c
(字符设备)、d
(目录)、p
(命名管道)、f
(常规文件)、l
(符号链接)和s
(套接字)允许查找某一类型的文件系统对象。
[root@rcc-pok-idg-2305 /]# find /usr/bin -name '*vim*' -type l
/usr/bin/rvim
/usr/bin/vimdiff
-mtime
选项允许您根据最近一次的修改时间来选择文件。mtime 的参数以 24 小时为单位,当输入时带加号(表示“之后”)或者减号(表示“之前”)时,它最有用
-size
选项允许您根据文件的大小来查找它们。缺省情况下,-size
的参数是 512 个字节的块,但是添加后缀可以使操作更简便。可用的后缀是b
(512 字节的块)、c
(字节)、k
(千字节)和w
(2 字节的字)。另外,您可以在前放置加号(“大于”)或者减号(“小于”)。
slocate
代表“安全定位(secure locate)”。它将许可权信息存储在数据库中,这样普通用户不能以别的方式窥探他们不能读取的目录。slocate
的用法信息在本质上与locate
的信息相同,尽管输出可能不同(取决于正在运行命令的用户
Slocate and locate both do essentially the same thing:
Slocate 与locate区别:
search a database containing the file names and locations on the system
for a match and report all that are found.
Both count on another program -- updatedb -- to do the heavy lifting by creating/maintaining
the database to be searched.
Slocate provides greater security by storing the permissions and ownership of each file, and then only
showing the files that the user running the slocate request has permission to access.