6.1 2.1-2.4

2.1 系统目录结构

ls:用于列举系统中的目录或文件

[root@hyc-01-01 ~]#ls /

bin   dev  home  lib64  mnt  proc  run   srv  tmp  var

boot  etc  lib   media  opt  root  sbin  sys  usr

[root@hyc-01-01 ~]# ls /root

anaconda-ks.cfg

root目录:用户家目录,用于存放该用户相关的配置文件及属于该用户的文件

[root@hyc-01-01 ~]# useradd hyc 创建普通用户

[root@hyc-01-01 hyc]# pwd

/home/hyc 普通用户家目录在home目录下,root用户家目录在根目录下

 

/etc/ssh/sshd_configssh的配置文件

tree命令

[root@hyc-01-01 hyc]# yum install -y tree 安装tree命令

[root@hyc-01-01 /]# tree home 将目录结构和内容以树型显示

home

└── hyc

    └── 1

        └── 2

            └── 3

                └── 4

                    └── 5

6 directories, 0 files

[root@hyc-01-01 /]# tree –hep 显示tree的常用选项

tree: Invalid argument -`-'.

usage: tree [-acdfghilnpqrstuvxACDFQNSUX] [-H baseHREF] [-T title ] [-L level [-R]]

         [-P pattern] [-I pattern] [-o filename] [--version] [--help] [--inodes]

         [--device] [--noreport] [--nolinks] [--dirsfirst] [--charset charset]

         [--filelimit[=]#] [--si] [--timefmt[=]<f>] [<directory list>]

[root@hyc-01-01 /]# man tree 查询某命令或文件的说明时可以使用man,用于显示帮助文档

 

[root@hyc-01-01 /]# tree -L 2 /home 指定最大目录深度为2

/home

└── hyc

    └── 1

2 directories, 0 files

常用目录:

/bin/sbin/usr/bin/usr/sbin用于存放用户使用的命令,如lsvitree等;

bin->usr/bin bin软链接到usr/bin

binsbin的区别:sbin下的命令通常仅root用户有权使用;

root用户和普通用户均有权使用bin目录下的命令;

PATH:环境变量

[root@hyc-01-01 /]# ls /boot 该目录下为系统启动的关键文件,如grub相关的文件等,该目录被删除或受损可能导致系统无法启动

config-3.10.0-693.el7.x86_64

efi

grub

grub2

initramfs-0-rescue-369c7d2d07a94ae185739de6ad9c2a1c.img

initramfs-3.10.0-693.el7.x86_64.img

initrd-plymouth.img

symvers-3.10.0-693.el7.x86_64.gz

System.map-3.10.0-693.el7.x86_64

vmlinuz-0-rescue-369c7d2d07a94ae185739de6ad9c2a1c

vmlinuz-3.10.0-693.el7.x86_64

[root@hyc-01-01 /]# ls /dev 存放linux系统中的设备文件,包括光盘、硬盘、鼠标等设备的相关文件

[root@hyc-01-01 /]# ls /etc 系统配置相关文件

[root@hyc-01-01 /]# ls /home 用户家目录,存放用户相关文件

[root@hyc-01-01 /]# ls /lib liblib64存放系统库文件,许多命令会依赖库文件,库文件类似windows中的.dll文件

[root@hyc-01-01 /]# ldd /bin/ls 查看ls命令依赖的库文件

         linux-vdso.so.1 =>  (0x00007ffcd89b1000)

         libselinux.so.1 => /lib64/libselinux.so.1 (0x00007fd6dfd32000)

         libcap.so.2 => /lib64/libcap.so.2 (0x00007fd6dfb2d000)

         libacl.so.1 => /lib64/libacl.so.1 (0x00007fd6df923000)

         libc.so.6 => /lib64/libc.so.6 (0x00007fd6df560000)

         libpcre.so.1 => /lib64/libpcre.so.1 (0x00007fd6df2fe000)

         libdl.so.2 => /lib64/libdl.so.2 (0x00007fd6df0f9000)

         /lib64/ld-linux-x86-64.so.2 (0x000055b785644000)

         libattr.so.1 => /lib64/libattr.so.1 (0x00007fd6deef4000)

         libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fd6decd8000)

2.2 系统目录结构

Centos7开始不区分32位或64位,统一为64位;

32位和64位的区别在于64位可以识别超过4G的内存大小;

[root@hyc-01-01 /]# ls /media 媒介目录,是一个临时挂载的目录,若插入一个U盘或其他外部设备则会自动放到media目录下

[root@hyc-01-01 /]# ls /mnt 临时目录,用户可以将光驱或新加载的硬盘挂载到该目录

[root@hyc-01-01 /]# ls /opt 空目录

[root@hyc-01-01 /]# ls /proc 存放以启动进程pid命名的目录,包括该进程的一些信息

lrwxrwxrwx. 1 root root 0 6   1 21:47 cwd -> / 进程所在路径(进程在哪里运行)

[root@hyc-01-01 /]# ls /run 进程产生的临时文件,重启或关机消失,进程产生的pid文件在该目录下

[root@hyc-01-01 /]# ls /srv 会产生服务相关的文件,默认为空

[root@hyc-01-01 /]# ls /sys 存放系统相关的文件,一般不设置

[root@hyc-01-01 /]# ls -ld tmp 系统临时目录,通常任何用户对该目录都有较大权限,可以随意增删,由于特殊权限t导致用户只能修改、增删自己的文件和目录

drwxrwxrwt. 13 root root 4096 6   1 21:15 tmp

[root@hyc-01-01 /]# ls /usr 用户的文件在该目录下

[root@hyc-01-01 /]# ls /var var是一个重要的目录,用于存放日志文件、缓存、pid等文件会放在var

该目录中的/var/log会存系统日志,许多系统相关的日志在/var/log/messages下;

部分进程的pid会在/var/run下;

总结:

binsbin存放系统相关命令,/usr/bin/usr/sbinbinsbin的软链接(类似windows快捷方式);

/boot目录很重要,但通常不做修改;

/usr/local存放用户的一些服务,通常将自己编译的服务放到该目录下;

2.3 ls命令

-l 列出文件的详细信息

[root@hyc-01-01 ~]# ls -l

总用量 4

-rw-------. 1 root root 1418 5  25 04:56 anaconda-ks.cfg

第一列:文件的权限

第二列:有多少文件使用了相同的inode

-i 查看文件inode

[root@hyc-01-01 ~]# ls -i anaconda-ks.cfg

33574978 anaconda-ks.cfg

Inode

即文件相关信息,包括权限信息,所属用户、组以及有多少文件使用了下同的inode、文件大小和时间等信息,ls –l中显示的信息即inode中包含的信息;

inode会记录文件存在了磁盘的哪个区块;

相同inode号的文件在磁盘上对应相同的数据块;

 

-h 显示文件大小的单位

[root@hyc-01-01 ~]# ls -lh anaconda-ks.cfg

-rw-------. 1 root root 1.4K 5  25 04:56 anaconda-ks.cfg

 

-a 查看目录下包括隐藏文件在内的所有文件

[root@hyc-01-01 ~]# ls -a

.   anaconda-ks.cfg  .bash_logout   .bashrc  .ssh

..  .bash_history    .bash_profile  .cshrc   .tcshrc

以点开头的文件或目录一般都是隐藏的

[root@hyc-01-01 ~]# ls -la

总用量 32

dr-xr-x---.  3 root root  147 5  28 22:01 . 即代表当前目录本身,显示的属性和root目录相同

dr-xr-xr-x. 17 root root  224 5  29 23:32 ..

-rw-------.  1 root root 1418 5  25 04:56 anaconda-ks.cfg

-rw-------.  1 root root 4202 6   1 22:56 .bash_history

-rw-r--r--.  1 root root   18 12 29 2013 .bash_logout

-rw-r--r--.  1 root root  176 12 29 2013 .bash_profile

-rw-r--r--.  1 root root  176 12 29 2013 .bashrc

-rw-r--r--.  1 root root  100 12 29 2013 .cshrc

drwx------.  2 root root   80 5  30 22:44 .ssh

-rw-r--r--.  1 root root  129 12 29 2013 .tcshrc

三个inode号相同的目录:

[root@hyc-01-01 /]# ls -i root

33574978 anaconda-ks.cfg

[root@hyc-01-01 ~]# ls -i .

33574978 anaconda-ks.cfg

[root@hyc-01-01 ~]# ls -i .ssh/..

33574978 anaconda-ks.cfg

一个目录的每个子目录下都会有一个和该目录inode号相同的..目录

 

-t 以时间顺序排序,越晚排序越靠前

[root@hyc-01-01 ~]# ls -alt

总用量 32

-rw-------.  1 root root 4202 6   1 22:56 .bash_history

drwx------.  2 root root   80 5  30 22:44 .ssh

dr-xr-xr-x. 17 root root  224 5  29 23:32 ..

dr-xr-x---.  3 root root  147 5  28 22:01 .

-rw-------.  1 root root 1418 5  25 04:56 anaconda-ks.cfg

-rw-r--r--.  1 root root   18 12 29 2013 .bash_logout

-rw-r--r--.  1 root root  176 12 29 2013 .bash_profile

-rw-r--r--.  1 root root  176 12 29 2013 .bashrc

-rw-r--r--.  1 root root  100 12 29 2013 .cshrc

-rw-r--r--.  1 root root  129 12 29 2013 .tcshrc

ll 效果等同于ls –l,相当于ls –l的别名

[root@hyc-01-01 ~]# ll

总用量 4

-rw-------. 1 root root 1418 5  25 04:56 anaconda-ks.cfg

[root@hyc-01-01 ~]# which ll 查看命令别名

alias ll='ls -l --color=auto'

         /usr/bin/ls

[root@hyc-01-01 ~]# alias ls –color=auto使显示出的文件附带颜色

alias ls='ls --color=auto'

[root@hyc-01-01 ~]# alias ll

alias ll='ls -l --color=auto'

[root@hyc-01-01 ~]# /bin/ls –la 不会附带颜色

 

2.4 文件类型

[root@hyc-01-01 ~]# ls –al 其中开头的字母d表示文件类型为目录

总用量 32

dr-xr-x---.  3 root root  147 5  28 22:01 .

d:一般的目录文件

-:普通文本文件或二进制文件,如/bin/lsauthorized_keys/bin/ls无法查看,authorized_keys可以使用cat等命令查看

c:字符串设备,在ls –l下以×××显示,包括鼠标、键盘

l:链接文件,在ls –l下以粉绿色显示,包括软链接和硬链接

lrwxrwxrwx. 1 root root          13 5  30 20:42 fd -> /proc/self/fd 链接文件指向真正文件

b:块设备文件,光盘、磁盘均属于块设备文件

ssocket文件,一个系统内的两个进程可以使用socket文件通信


猜你喜欢

转载自blog.51cto.com/12216458/2123395
6.1