Linux系统目录结构、文件类型、ls命令、alias别名

2.1-2.2 系统目录结构

1.Linux系统下的帮助命令man

Linux下的帮助指令,通过man指令可以查看Linux中的指令帮助、配置文件帮助和编程帮助等信息

man 命令

2.为了方便查看系统目录结构,使用tree(树状)命令:

[root@yolks1 ~]# tree
-bash: tree: 未找到命令
[root@yolks1 ~]# yum install -y tree
已加载插件:fastestmirror
base                                                                  | 3.6 kB  00:00:00     
extras                                                                | 3.4 kB  00:00:00     
updates                                                               | 3.4 kB  00:00:00     
(1/4): base/7/x86_64/group_gz                                         | 166 kB  00:00:00     
(2/4): extras/7/x86_64/primary_db                                     | 147 kB  00:00:00     
(3/4): base/7/x86_64/primary_db                                       | 5.9 MB  00:00:03     
(4/4): updates/7/x86_64/primary_db                                    | 2.0 MB  00:00:03     
Determining fastest mirrors
 * base: mirrors.cn99.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 tree.x86_64.0.1.6.0-10.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

=============================================================================================
 Package            架构                 版本                       源                  大小
=============================================================================================
正在安装:
 tree               x86_64               1.6.0-10.el7               base                46 k

事务概要
=============================================================================================
安装  1 软件包

总下载量:46 k
安装大小:87 k
Downloading packages:
警告:/var/cache/yum/x86_64/7/base/packages/tree-1.6.0-10.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
tree-1.6.0-10.el7.x86_64.rpm 的公钥尚未安装
tree-1.6.0-10.el7.x86_64.rpm                                          |  46 kB  00:00:00     
从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 检索密钥
导入 GPG key 0xF4A80EB5:
 用户ID     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
 指纹       : 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 软件包     : centos-release-7-4.1708.el7.centos.x86_64 (@anaconda)
 来自       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : tree-1.6.0-10.el7.x86_64                                                 1/1 
  验证中      : tree-1.6.0-10.el7.x86_64                                                 1/1 

已安装:
  tree.x86_64 0:1.6.0-10.el7                                                                 

完毕!

// yum安装
yum install -y tree

// 帮助命令(不常用)
tree --help

// man查询用法(常用)
man tree

// 示例:查看根目录以下两级
tree -L 2  /

3.Linux根目录下各子目录详解

  • Linux常用命令存储文件夹:/bin/、/sbin/、/usr/bin/、/usr/sbin/
    • /sbin/目录只能root账户使用,普通账户则使用/bin/
  • 系统启动目录: /boot/
  • 设备文件目录: /dev/
  • 配置文件目录: /etc/
    • /etc/sysconfig/network-scripts/ifcfg-ens33(网卡配置)
    • /etc/ssh/sshd_config(ssh配置)
  • 普通用户家目录:/home/
  • root用户家目录:/root/
  • 系统库文件目录:/lib/、/lib64/
    • //查看某个命令使用那些库 例如:"/bin/ls"
    • ldd /bin/ls
  • 媒介目录:/media/
  • 临时挂载目录:/mnt/
  • 空目录:/opt/
  • 系统启动进程目录:/proc/
    • 每个进程pid都有单独文件在此目录下
  • 进程产生的文件目录:/run/
  • 服务产生的文件目录:/srv/
  • 系统内核相关文件目录:/sys/
  • 系统临时目录:/tmp/
    • 注意:任何人都可操作,但仅限自己的数据
  • 用户文件目录:/usr/
  • 多存放系统日志:/var/

2.3 LS命令(List)

用来显示目标列表,在Linux中是使用率较高的命令。ls命令的输出信息可以进行彩色加亮显示,以分区不同类型的文件。

  • l 详细信息 == ll(ls -l)

    • 文件类型、权限、位置、相同inode的个数、所有者、所属组、大小、创建 时间、文件名
    [root@yolks1 ~]# ls -l 
    总用量 4
    -rw-------. 1 root root 1418 5月  25 05:32 anaconda-ks.cfg
    
    • ll 来源
      • 即用别名代替 ls - l 命令
    [root@yolks1 ~]# which ll
    alias ll='ls -l --color=auto'
    	    /usr/bin/ls
    
  • i inode号,记录创建/修改时间、大小、所属组、所有者等信息

    [root@yolks1 ~]# ls -i anaconda-ks.cfg
    33574978 anaconda-ks.cfg
    
  • a 显示出包含隐藏文件或目录全部信息

    • 单独使用
    [root@yolks1 ~]# ls
    anaconda-ks.cfg
    [root@yolks1 ~]# ls -a
    .   anaconda-ks.cfg  .bash_logout   .bashrc  .ssh
    ..  .bash_history    .bash_profile  .cshrc   .tcshrc
    
    • 结合 - l 使用
     //  结合使用
    [root@yolks1 ~]# ls -la
    总用量 28
    dr-xr-x---.  3 root root  147 5月  27 16:50 .
    dr-xr-xr-x. 17 root root  265 5月  27 18:02 ..
    -rw-------.  1 root root 1418 5月  25 05:32 anaconda-ks.cfg
    -rw-------.  1 root root  482 5月  27 19:39 .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月  27 19:48 .ssh
    -rw-r--r--.  1 root root  129 12月 29 2013 .tcshrc
    
  • t 用文件和目录的更改时间排序(默认倒序排列,即最新的在顶)

    [root@yolks1 ~]# ls -lt /var/
    总用量 12
    drwxr-xr-x.  7 root root 4096 6月   1 20:27 log
    drwxrwxrwt. 14 root root 4096 6月   1 20:21 tmp
    drwxr-xr-x. 25 root root 4096 5月  25 05:34 lib
    drwxr-xr-x.  3 root root   34 5月  25 05:29 db
    drwxr-xr-x.  5 root root   44 5月  25 05:29 cache
    drwxr-xr-x.  3 root root   18 5月  25 05:29 empty
    drwxr-xr-x.  8 root root   87 5月  25 05:29 spool
    drwxr-xr-x.  3 root root   18 5月  25 05:28 kerberos
    lrwxrwxrwx.  1 root root   10 5月  25 05:28 mail -> spool/mail
    lrwxrwxrwx.  1 root root   11 5月  25 05:28 lock -> ../run/lock
    lrwxrwxrwx.  1 root root    6 5月  25 05:28 run -> ../run
    drwxr-xr-x.  2 root root    6 8月   7 2017 crash
    drwxr-xr-x.  2 root root    6 11月  5 2016 adm
    drwxr-xr-x.  2 root root    6 11月  5 2016 games
    drwxr-xr-x.  2 root root    6 11月  5 2016 gopher
    drwxr-xr-x.  2 root root    6 11月  5 2016 local
    drwxr-xr-x.  2 root root    6 11月  5 2016 nis
    drwxr-xr-x.  2 root root    6 11月  5 2016 opt
    drwxr-xr-x.  2 root root    6 11月  5 2016 preserve
    drwxr-xr-x.  2 root root    6 11月  5 2016 yp
    
  • d 仅显示查看目录,不会显示目录下的文件

    • 单独使用
    [root@yolks1 ~]# ls -d /root/
    /root/
    
    • 结合 - l 选项使用
    [root@yolks1 ~]# ls -ld /root/
    dr-xr-x---. 3 root root 147 5月  27 16:50 /root/
    
  • h 以最合适的大小显示文件大小

    • 如下面示例中以kb显示大小
    [root@yolks1 ~]# ls
    anaconda-ks.cfg
    [root@yolks1 ~]# ls -lh anaconda-ks.cfg
    -rw-------. 1 root root 1.4K 5月  25 05:32 anaconda-ks.cfg
    
  • 更多详细用法详见 man ls命令帮助选项

2.4 Linux系统目录下的文件类型

  • - 普通文件 (可以cat打开)

    • 绿色的指的是可执行的编译文件,不能用cat打开

  • d 目录

    • 对应颜色为 蓝色

  • c 字符串设备(鼠标、键盘)

    • 对应颜色为 黄色

  • l 软链接 (相当于Windows快捷方式)

    • 对应颜色为 粉绿色 --- >>> 黄色/蓝色

  • b 块设备(光盘、磁盘)

    • 对应颜色为 黄色

  • s 机器内通信文件 (进程间通信文件)

    • 对应颜色为 粉色
    • 通信方式两种
      • ① TCP/IP : A机器到B机器端口间通信
      • ② SOCKET : 进程间通信

2.5 alias命令

用来设置指令的别名。我们可以使用该命令可以将一些较长的命令进行简化。使用alias时,用户必须使用单引号''将原来的命令引起来,防止特殊字符导致错误。

  • 查询具体某个命令别名详细信息

        which  命令
    
    • 示例 :
    [root@yolks1 ~]# which man
    /usr/bin/man
    [root@yolks1 ~]# which ls
    alias ls='ls --color=auto'
    	    /usr/bin/ls
    [root@yolks1 ~]# which cd
    /usr/bin/cd
    
  • 显示当前系统全部别名

    • 示例 :
    [root@yolks1 ~]# 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'
    
  • 环境变量(Windows也有此概念) PATH

    • 查看环境变量
    [root@yolks1 ~]# echo $PATH
    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
    

使用 alias别名

1. 定义别名
alias 新的命令='原命令 -选项/参数'
  • 示例 :

    [root@yolks1 ~]# alias yolks='ls -lha'
    [root@yolks1 ~]# yolks
    总用量 28K
    dr-xr-x---.  3 root root  147 5月  27 16:50 .
    dr-xr-xr-x. 17 root root  265 5月  27 18:02 ..
    -rw-------.  1 root root 1.4K 5月  25 05:32 anaconda-ks.cfg
    -rw-------.  1 root root  482 5月  27 19:39 .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月  27 19:48 .ssh
    -rw-r--r--.  1 root root  129 12月 29 2013 .tcshrc
    
  • 查看来源

    [root@yolks1 ~]# which yolks
    alias yolks='ls -lha'
    /usr/bin/ls
    
2.永久生效
  • 编辑 ~/.bashrc - 示例 : /root/.bashrc

删除或取消一个别名

  • 示例 :
     [root@yolks1 ~]# unalias yolks
     [root@yolks1 ~]# yolks
      -bash: yolks: 未找到命令
     [root@yolks1 ~]# which yolks
      /usr/bin/which: no yolks in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)

转载于:https://my.oschina.net/yolks/blog/1518902

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值