本文索引:node
以树形显示目录及文件的结构linux
安装:yum install -y tree 指定层数: tree -L 2 / 更多用法: man tree
[root@localhost ~]# tree -L 1 / / ├── bin -> usr/bin ├── boot ├── dev ├── etc ├── home ├── lib -> usr/lib ├── lib64 -> usr/lib64 ├── media ├── mnt ├── opt ├── proc ├── root ├── run ├── sbin -> usr/sbin ├── srv ├── sys ├── tmp ├── usr └── var 19 directories, 0 files
目录 | 说明 |
---|---|
/bin | 经常使用命令存放目录,如/bin/ls |
/boot | 系统启动核心文件存放目录 |
/dev | 系统的外部设备文件存放目录 |
/etc | 系统配置文件相关存放目录,如网卡配置文件/etc/sysconfig/network-scripts/ifcfg-ens33 |
/home | 非root用户家目录 |
/lib | /lib64 |
/media | u盘、光驱的默认挂载目录 |
/mnt | 临时挂载其余文件系统的目录 |
/opt | 额外软件安装目录 |
/proc | 虚拟目录,系统内存的映射;经过访问其内文件获取系统信息 |
/root | root用户家目录 |
/run | 系统当前运行进程的pid文件 |
/sbin | 超级用户命令目录 |
/srv | 服务启动时须要获取的数据信息 |
/sys | 存放硬件驱动程序相关的信息 |
/tmp | 临时文件存放目录 |
/usr | 系统程序和文件存放的目录 |
/var | 存放内容不断变化的文件如日志文件、pid文件 |
关于/bin和/sbin目录的说明:centos
[root@localhost ~]# ls -ld /bin /sbin lrwxrwxrwx. 1 root root 7 10月 18 02:24 /bin -> usr/bin lrwxrwxrwx. 1 root root 8 10月 18 02:24 /sbin -> usr/sbin 能够看出,/bin和/sbin目录都是/usr目录内同名目录的软连接
ls命令 列出文件和目录的详细信息(权限、大小、建立修改时间等)bash
能够多个参数一块儿使用,例如 -lh 、-ltssh
几个经常使用的例子:centos7
# 查看/root目录下全部文件 [root@localhost ~]# ls -alh /root 总用量 28K dr-xr-x---. 3 root root 147 10月 18 20:06 . dr-xr-xr-x. 17 root root 245 10月 18 19:51 .. -rw-------. 1 root root 1.4K 10月 18 02:47 anaconda-ks.cfg -rw-------. 1 root root 768 10月 17 22:20 .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 38 10月 18 20:06 .ssh -rw-r--r--. 1 root root 129 12月 29 2013 .tcshrc # 查看/root目录的详细信息,大小单位自动转换 [root@localhost ~]# ls -lhd /root/ dr-xr-x---. 3 root root 147 10月 18 20:06 /root/ # 查看/root目录下各文件的inode号等详细信息 [root@localhost ~]# ls -ali /root/ 总用量 28 33574977 dr-xr-x---. 3 root root 147 10月 18 20:06 . 64 dr-xr-xr-x. 17 root root 245 10月 18 19:51 .. 33574987 -rw-------. 1 root root 1422 10月 18 02:47 anaconda-ks.cfg 33574979 -rw-------. 1 root root 768 10月 17 22:20 .bash_history 33975623 -rw-r--r--. 1 root root 18 12月 29 2013 .bash_logout 33975624 -rw-r--r--. 1 root root 176 12月 29 2013 .bash_profile 33975625 -rw-r--r--. 1 root root 176 12月 29 2013 .bashrc 33975626 -rw-r--r--. 1 root root 100 12月 29 2013 .cshrc 50679988 drwx------. 2 root root 38 10月 18 20:06 .ssh 33975627 -rw-r--r--. 1 root root 129 12月 29 2013 .tcshrc
[root@centos7 ~]# ls -l /root/ 总用量 4 -rw-------. 1 root root 1422 8月 31 05:34 anaconda-ks.cfg
ls列出的文件信息的具体含义依次为日志
权限 | 连接数 | 所属主 | 所属组 | 大小 | 修改时间 | 文件名 |
---|---|---|---|---|---|---|
-rw-------. | 1 | root | root | 1422 | 8月 31 05:34 | anaconda-ks.cfg |
权限的第一位表示文件或目录的类型code
权限第2-10位,每3位为一组,分别表示:排序
最后极易忽略的这个点( . ),表示文件应用了selinux策略索引
[root@centos7 ~]# ls -ild . /root/ /root/.ssh/.. 16797761 dr-xr-x---. 3 root root 173 9月 20 22:26 . 16797761 dr-xr-x---. 3 root root 173 9月 20 22:26 /root/ 16797761 dr-xr-x---. 3 root root 173 9月 20 22:26 /root/.ssh/..
使用alias给命令建立别名代替长长的一串命令,更方便输入,提升效率!
[root@centos7 ~]# ls -l /root/ 总用量 4 -rw-------. 1 root root 1422 8月 31 05:34 anaconda-ks.cfg [root@centos7 ~]# which ls alias ls='ls --color=auto' /usr/bin/ls
alias 查看系统内已有别名的目录,也能够建立新的别名,使用unalias命令取消别名。
# 查看别名 [root@centos7 ~]# alias alias cp='cp -i' alias egrep='egrep --color=auto' alias fgrep='fgrep --color=auto' alias grep='grep --color=auto' alias l.='ls -d .* --color=auto' alias ll='ls -l --color=auto' alias ls='ls --color=auto' alias mv='mv -i' alias rm='rm -i' alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
# alias lt='ls -lt'
# unalias lt