您的位置:首页 > 运维架构 > Linux

点石成金-Linux目录结构,命令,文件类型学习

2017-12-16 13:50 411 查看
一周第五次课(12月15日)

2.1/2.2 系统目录结构

2.3 ls命令

2.4 文件类型

2.5 alias命令

一 系统目录结构

命令ls

命令ls(list的简写)用于猎取系统的目录或文件

[root@xavi-001 ~]# ls
anaconda-ks.cfg  initial-setup-ks.cfg  [root@localhost

利用ls查看根目录

[root@xavi-001 ~]# ls /
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var


/root:该目录是系统管理员的用户主目录。(家目录,存配置文件)

[root@xavi-001 ~]# ls /root/
anaconda-ks.cfg

[root@xavi-001 ~]# useradd user1  //创建新用户user1
[root@xavi-001 ~]# ls /home/user1/ //user的家目录就在home目录下


tree 用树型的形式来显示下面有哪些目录子目录
系统没有tree目录,需要用yum来安装

[root@xavi-001 ~]# yum install -y tree

[root@xavi-001 ~]# tree /   //查看tree目录,特别长

[root@xavi-001 ~]# 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>]


命令 man 用量显示文档的全称,按q退出



/bin:bin是Binary的缩写,该目录下存放的是最常用的命令。普通用户和系统管理员都能用的

/sbin:s就是Super User的意思,该目录存放的是系统管理员(root)使用的系统管理程序。

/boot:该目录下存放的是启动Linux时使用的一些核心文件,包括一些连接文件以及镜像文件。

/dev:dev是Device(设备)的缩写。该目录下存放的是Linux的外部设备。在Linux中,访问设备的方式和访问文件的方式是相同的。

/etc:该目录下存放的是所有系统管理所需要的配置文件和子目录。

/home:这是用户的主目录。在Linux中,每个用户都有一个自己的目录,一般该目录名是以用户的账号命名的。

/lib和/lib64:这两个目录下存放的是系统最基本的动态连接共享库,其作用类似于Windows里的DLL文件,几乎所有的应用程序都需要用到这些共享库。其中/lib64为64位的软件包的库文件所在目录

[root@xavi-001 ~]# ldd /bin/ls  //查找关联目录
linux-vdso.so.1 =>  (0x00007ffdfa1f1000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f698648e000)
libcap.so.2 => /lib64/libcap.so.2 (0x00007f6986289000)
libacl.so.1 => /lib64/libacl.so.1 (0x00007f698607f000)
libc.so.6 => /lib64/libc.so.6 (0x00007f6985cbe000)
libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f6985a5d000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f6985858000)
/lib64/ld-linux-x86-64.so.2 (0x00007f69866c8000)
libattr.so.1 => /lib64/libattr.so.1 (0x00007f6985653000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f6985437000)




/media:系统会自动识别一些设备(如U盘、光驱等),当识别后,Linux会把识别的设备挂载到该目录下。

/mnt:系统提供该目录是为了让用户临时挂载别的文件系统。我们可以将光驱挂载到/mnt/上,然后进入该目录查看光驱里的内容。

/opt:这是给主机额外安装软件所设置的目录,该目录默认为空。比如你要安装一个ORACLE数据库,可以放到该目录下。

[root@xavi-001 ~]# ls /media/
[root@xavi-001 ~]# ls /mnt/
[root@xavi-001 ~]# ls /opt/


/proc:该目录是一个虚拟的目录,是系统内存的映射,我们可以通过直接访问来获取系统信息。该目录的内容在内存里,我们可以直接修改里面的某些文件。比如可以通过下面的命令来屏蔽主机的ping命令,使其他人无法ping你的机器。后续,在日常工作中,你会经常用到类似的用法。

# echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all

[root@xavi-001 ~]# ls /proc/
1     18    232   251  279  38   41   495  530  611  922        consoles     interrupts  loadavg       partitions     sysvipc
10    19    2328  252  28   380  42   5    538  613  927        cpuinfo      iomem       locks         sched_debug    timer_list
12    2     233   26   280  39   43   505  545  62   929        crypto       ioports     mdstat        schedstat      timer_stats
13    20    2331  261  281  395  439  509  547  669  938        devices      irq         meminfo       scsi           tty
1340  21    241   27   282  4    440  517  549  7    94         diskstats    kallsyms    misc          self           uptime
1349  2184  242   273  29   40   444  519  550  8    acpi       dma          kcore       modules       slabinfo       version
1350  2186  243   274  3    401  446  520  554  9    asound     driver       keys        mounts        softirqs       vmallocinfo
14    2247  244   275  30   404  448  521  555  912  buddyinfo  execdomains  key-users   mpt           stat           vmstat
15    2250  247   276  351  405  450  522  558  913  bus        fb           kmsg        mtrr          swaps          zoneinfo
16    231   248   277  373  406  452  524  591  917  cgroups    filesystems  kpagecount  net           sys
17    2310  250   278  374  407  454  529  6    918  cmdline    fs           kpageflags  pagetypeinfo  sysrq-trigger

进程生产PID,有1,10等,每个进程都会有文件和目录,基本一样

[root@xavi-001 ~]# ls /proc/1
attr        cmdline          environ  io         mem         ns             pagemap      schedstat  stat     timers
autogroup   comm             exe      limits     mountinfo   numa_maps      personality  sessionid  statm    uid_map
auxv        coredump_filter  fd       loginuid   mounts      oom_adj        projid_map   setgroups  status   wchan
cgroup      cpuset           fdinfo   map_files  mountstats  oom_score      root         smaps      syscall
clear_refs  cwd              gid_map  maps       net         oom_score_adj  sched        stack      task

[root@xavi-001 ~]# ls -l /proc/281  //281也是一个进程,里面的有很多目录和文件
ls: 无法读取符号链接/proc/281/exe: 没有那个文件或目录
总用量 0
dr-xr-xr-x 2 root root 0 12月 16 09:42 attr
-rw-r--r-- 1 root root 0 12月 16 09:42 autogroup
-r-------- 1 root root 0 12月 16 09:42 auxv
-r--r--r-- 1 root root 0 12月 16 09:42 cgroup
--w------- 1 root root 0 12月 16 09:42 clear_refs
-r--r--r-- 1 root root 0 12月 16 09:32 cmdline
-rw-r--r-- 1 root root 0 12月 16 09:42 comm
-rw-r--r-- 1 root root 0 12月 16 09:42 coredump_filter
-r--r--r-- 1 root root 0 12月 16 09:42 cpuset
lrwxrwxrwx 1 root root 0 12月 16 09:42 cwd -> /     //进程所在的路径
-r-------- 1 root root 0 12月 16 09:42 environ
lrwxrwxrwx 1 root root 0 12月 16 09:42 exe
dr-x------ 2 root root 0 12月 16 09:42 fd
dr-x------ 2 root root 0 12月 16 09:42 fdinfo
-rw-r--r-- 1 root root 0 12月 16 09:42 gid_map
-r-------- 1 root root 0 12月 16 09:42 io
-r--r--r-- 1 root root 0 12月 16 09:42 limits
-rw-r--r-- 1 root root 0 12月 16 09:42 loginuid
dr-x------ 2 root root 0 12月 16 09:42 map_files
-r--r--r-- 1 root root 0 12月 16 09:42 maps
-rw------- 1 root root 0 12月 16 09:42 mem
-r--r--r-- 1 root root 0 12月 16 09:42 mountinfo
-r--r--r-- 1 root root 0 12月 16 09:42 mounts
-r-------- 1 root root 0 12月 16 09:42 mountstats
dr-xr-xr-x 6 root root 0 12月 16 09:42 net
dr-x--x--x 2 root root 0 12月 16 09:42 ns
-r--r--r-- 1 root root 0 12月 16 09:42 numa_maps
-rw-r--r-- 1 root root 0 12月 16 09:42 oom_adj
-r--r--r-- 1 root root 0 12月 16 09:42 oom_score
-rw-r--r-- 1 root root 0 12月 16 09:42 oom_score_adj
-r--r--r-- 1 root root 0 12月 16 09:42 pagemap
-r--r--r-- 1 root root 0 12月 16 09:42 personality
-rw-r--r-- 1 root root 0 12月 16 09:42 projid_map
lrwxrwxrwx 1 root root 0 12月 16 09:42 root -> /     //根目录
-rw-r--r-- 1 root root 0 12月 16 09:42 sched
-r--r--r-- 1 root root 0 12月 16 09:42 schedstat
-r--r--r-- 1 root root 0 12月 16 09:42 sessionid
-rw-r--r-- 1 root root 0 12月 16 09:42 setgroups
-r--r--r-- 1 root root 0 12月 16 09:42 smaps
-r--r--r-- 1 root root 0 12月 16 09:42 stack
-r--r--r-- 1 root root 0 12月 16 09:42 stat
-r--r--r-- 1 root root 0 12月 16 09:42 statm
-r--r--r-- 1 root root 0 12月 16 09:32 status
-r--r--r-- 1 root root 0 12月 16 09:42 syscall
dr-xr-xr-x 3 root root 0 12月 16 09:42 task
-r--r--r-- 1 root root 0 12月 16 09:42 timers
-rw-r--r-- 1 root root 0 12月 16 09:42 uid_map
-r--r--r-- 1 root root 0 12月 16 09:42 wchan


/root:该目录是系统管理员的用户主目录。

/run:这个目录其实和/var/run是同一个目录,这里面存放的是一些服务的pid,一个服务启动完后,是有一个pid文件的。至于为什么说是同一个目录,Linux是如何做到的,后续我们再介绍。
/run/进程产生的临时文件,一旦关机重启就消失了

[root@xavi-001 ~]# ls /run/
abrt          chronyd.pid  dmeventd-client  initramfs     lsm          NetworkManager  samba           sshd.pid     udev
alsactl.pid   console      dmeventd-server  ksmtune.pid   lvm          plymouth        sepermit        sysconfig    user
atd.pid       crond.pid    faillock         libvirt       lvmetad.pid  ppp             setrans         syslogd.pid  utmp
auditd.pid    cron.reboot  firewalld        libvirtd.pid  mdadm        radvd           setroubleshoot  systemd      xtables.lock
avahi-daemon  cups         gssproxy.pid     lock          mount        rpcbind         sm-notify.pid   tmpfiles.d
certmonger    dbus         gssproxy.sock    log           netreport    rpcbind.sock    spice-vdagentd  tuned


/srv:该目录存放的是一些服务启动之后需要提取的数据。

/sys:该目录存放的是与硬件驱动程序相关的信息。

[root@xavi-001 ~]# ls /srv/
[root@xavi-001 ~]# ls /sys/     //系统内核相关的文件
block  bus  class  dev  devices  firmware  fs  hypervisor  kernel  module  power


/tmp:该目录是用来存放一些临时文件的,权限很大,任何用户都可以再里面填写和删除

[root@xavi-001 ~]# ls /tmp/
systemd-private-326256f65ea943dd8a67183d93dfe298-cups.service-AeQUKR
systemd-private-326256f65ea943dd8a67183d93dfe298-vmtoolsd.service-4S9XrS
systemd-private-66398656a9a941ce9ccbdb01047bb234-cups.service-PmWt6O
systemd-private-66398656a9a941ce9ccbdb01047bb234-vmtoolsd.service-GWHU20
systemd-private-d19532cf8bd34e658a8f10d18cbbd068-cups.service-HyM93B
systemd-private-d19532cf8bd34e658a8f10d18cbbd068-vmtoolsd.service-IxzO4H
systemd-private-fb35f8ad85b54d3fa3ceaaa57cea1ae1-cups.service-1DZjWJ
systemd-private-fb35f8ad85b54d3fa3ceaaa57cea1ae1-vmtoolsd.service-XH83aQ


/usr:这是一个非常重要的目录,类似于Windows下的Program Files目录,用户的很多应用程序和文件都存放在该目录下。后面的章节中,我们会多次用到这个目录。

[root@xavi-001 ~]# ls /usr/
bin  etc  games  include  lib  lib64  libexec  local  sbin  share  src  tmp

[root@xavi-001 ~]# ls /usr/local/
bin  etc  games  include  lib  lib64  libexec  sbin  share  src


/var:该目录存放的是在不断扩充且经常被修改的目录,包括各种日志文件或者pid文件,刚刚提到的/var/run就是在/var目录下面,var也是一个非常重要的目录,系统上运行各个程序时所产生的日志都被记录在该目录下(即/var/log目录中),另外mail指令的预设也放置在这里。

[root@xavi-001 ~]# ls /var/
account  cache  db     games   kerberos  local  log   nis  preserve  spool   tmp
adm      crash  empty  gopher  lib       lock   mail  opt  run       target  yp
[root@xavi-001 ~]# ls /var/log
anaconda       cron           firewalld  maillog-20170813   pluto    secure             spooler-20171213    wtmp
audit          cron-20170813  gdm        maillog-20171213   ppp      secure-20170813    sssd                Xorg.0.log
boot.log       cron-20171213  glusterfs  messages           qemu-ga  secure-20171213    tallylog            Xorg.0.log.old
btmp           cups           lastlog    messages-20170813  rhsm     speech-dispatcher  tuned               yum.log
btmp-20171213  dmesg          libvirt    messages-20171213  sa       spooler            vmware-vmsvc.log
chrony         dmesg.old      maillog    ntpstats           samba    spooler-20170813   wpa_supplicant.log
[root@xavi-001 ~]# ls /var/log/messages
/var/log/messages
[root@xavi-001 ~]# ls /var/run/
abrt          chronyd.pid  dmeventd-client  initramfs     lsm          NetworkManager  samba           sshd.pid     udev
alsactl.pid   console      dmeventd-server  ksmtune.pid   lvm          plymouth        sepermit        sysconfig    user
atd.pid       crond.pid    faillock         libvirt       lvmetad.pid  ppp             setrans         syslogd.pid  utmp
auditd.pid    cron.reboot  firewalld        libvirtd.pid  mdadm        radvd           setroubleshoot  systemd      xtables.lock
avahi-daemon  cups         gssproxy.pid     lock          mount        rpcbind         sm-notify.pid   tmpfiles.d
certmonger    dbus         gssproxy.sock    log           netreport    rpcbind.sock    spice-vdagentd  tuned

在Linux系统中,有几个重要的目录需要注意,不要误删除或者随意更改其内部文件总结下常用的目录

[root@xavi-001 ~]# ls /usr/bin /usr/sbin /bin/  /sbin/ /etc/ /var/ /usr/local/

二 ls命令

[root@xavi-001 ~]# ls -l
总用量 8
-rw-------. 1 root root 1422 8月   9 05:35 anaconda-ks.cfg   //数字1表示有多少文件使用了相同的 anaconda,第一个root表示是root的用户,第二个root表示的root用户组
-rw-r--r--. 1 root root 1647 8月   9 00:17 initial-setup-ks.cfg
-rw-r--r--  1 root root    0 12月 13 00:01 [root@localhost
[root@xavi-001 ~]# ls -i anaconda-ks.cfg  //查看文件的iload号
33574986 anaconda-ks.cfg

[root@xavi-001 ~]#  ls -lh anaconda-ks.cfg //-lh表示更人性化的现示,1422byte
-rw-------. 1 root root 1.4K 8月   9 05:35 anaconda-ks.cfg

[root@xavi-001 ~]# ls -la  //查看所有目录,带.的表示当前目录,..表示上一级目录
总用量 32
dr-xr-x---.  5 root root  227 12月 13 00:02 .
dr-xr-xr-x. 17 root root  253 8月  10 22:50 ..
-rw-------.  1 root root 1422 8月   9 05:35 anaconda-ks.cfg
-rw-------.  1 root root 1999 12月 15 21:27 .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
drwxr-xr-x.  3 root root   18 8月  10 20:22 .cache
drwxr-xr-x.  3 root root   18 8月  10 20:22 .config
-rw-r--r--.  1 root root  100 12月 29 2013 .cshrc
-rw-r--r--.  1 root root 1647 8月   9 00:17 initial-setup-ks.cfg
-rw-r--r--   1 root root    0 12月 13 00:01 [root@localhost
drwx------.  2 root root   80 12月 15 00:37 .ssh
-rw-r--r--.  1 root root  129 12月 29 2013 .tcshrc

[root@xavi-001 ~]# ls -ld /root/
dr-xr-x---. 5 root root 227 12月 13 00:02 /root/
[root@xavi-001 ~]# ls -i /root/
33574986 anaconda-ks.cfg  34888138 initial-setup-ks.cfg  33989830 [root@localhost
[root@xavi-001 ~]# ls -i .
33574986 anaconda-ks.cfg  34888138 initial-setup-ks.cfg  33989830 [root@localhost
[root@xavi-001 ~]# ls -i .ssh/..   //.ssh的上级目录就是root
33574986 anaconda-ks.cfg  34888138 initial-setup-ks.cfg  33989830 [root@localhost


==带.的表示当前目录,.. 表示上一级目录==
[root@xavi-001 ~]# ls -a /
.   1             bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
..  .autorelabel  boot  etc  lib   media  opt  root  sbin  sys  usr
[root@xavi-001 ~]# ls -a /root/
.   anaconda-ks.cfg  .bash_logout   .bashrc  .config  initial-setup-ks.cfg  .ssh
..  .bash_history    .bash_profile  .cache   .cshrc   [root@localhost       .tcshrc


[root@xavi-001 ~]# ls -lta  //加t后,按时间顺序排序
总用量 32
-rw-------.  1 root root 1999 12月 15 21:27 .bash_history
drwx------.  2 root root   80 12月 15 00:37 .ssh
dr-xr-x---.  5 root root  227 12月 13 00:02 .
-rw-r--r--   1 root root    0 12月 13 00:01 [root@localhost
dr-xr-xr-x. 17 root root  253 8月  10 22:50 ..
drwxr-xr-x.  3 root root   18 8月  10 20:22 .config
drwxr-xr-x.  3 root root   18 8月  10 20:22 .cache
-rw-------.  1 root root 1422 8月   9 05:35 anaconda-ks.cfg
-rw-r--r--.  1 root root 1647 8月   9 00:17 initial-setup-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
[root@xavi-001 ~]# ls -la
总用量 32
dr-xr-x---.  5 root root  227 12月 13 00:02 .
dr-xr-xr-x. 17 root root  253 8月  10 22:50 ..
-rw-------.  1 root root 1422 8月   9 05:35 anaconda-ks.cfg
-rw-------.  1 root root 1999 12月 15 21:27 .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
drwxr-xr-x.  3 root root   18 8月  10 20:22 .cache
drwxr-xr-x.  3 root root   18 8月  10 20:22 .config
-rw-r--r--.  1 root root  100 12月 29 2013 .cshrc
-rw-r--r--.  1 root root 1647 8月   9 00:17 initial-setup-ks.cfg
-rw-r--r--   1 root root    0 12月 13 00:01 [root@localhost
drwx------.  2 root root   80 12月 15 00:37 .ssh
-rw-r--r--.  1 root root  129 12月 29 2013 .tcshrc

[root@xavi-001 ~]# ls -l /root/    //不加d,会把目录下的所有文件列出
总用量 8
-rw-------. 1 root root 1422 8月   9 05:35 anaconda-ks.cfg
-rw-r--r--. 1 root root 1647 8月   9 00:17 initial-setup-ks.cfg
-rw-r--r--  1 root root    0 12月 13 00:01 [root@localhost
[root@xavi-001 ~]# ls -ld /root/   //加了d只列目录本身
dr-xr-x---. 5 root root 227 12月 13 00:02 /root/

==总结常用的ls命令==

[root@xavi-001 ~]# man ls
[root@xavi-001 ~]# ls -l -i -a -t -h -d

[root@xavi-001 ~]# which ll
alias ll='ls -l --color=auto'  //表示有颜色的区别开
/usr/bin/ls
[root@xavi-001 ~]# ls /
1    boot  etc   lib    media  opt   root  sbin  sys  usr
bin  dev   home  lib64  mnt    proc  run   srv   tmp  var
[root@xavi-001 ~]# /bin/ls/
-bash: /bin/ls/: 不是目录
[root@xavi-001 ~]# /bin/ls /
1    boot  etc   lib    media  opt   root  sbin  sys  usr
bin  dev   home  lib64  mnt    proc  run   srv   tmp  var

三 文件类型

[root@xavi-001 ~]# ls -la
总用量 32
dr-xr-x---.  5 root root  227 12月 13 00:02 .    //第一列表示文件的权限,第一位d表示的是文件的类型,directory
dr-xr-xr-x. 17 root root  253 8月  10 22:50 ..
-rw-------.  1 root root 1422 8月   9 05:35 anaconda-ks.cfg   //—表示的是普通文件
-rw-------.  1 root root 1999 12月 15 21:27 .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
drwxr-xr-x.  3 root root   18 8月  10 20:22 .cache
drwxr-xr-x.  3 root root   18 8月  10 20:22 .config
-rw-r--r--.  1 root root  100 12月 29 2013 .cshrc
-rw-r--r--.  1 root root 1647 8月   9 00:17 initial-setup-ks.cfg
-rw-r--r--   1 root root    0 12月 13 00:01 [root@localhost
drwx------.  2 root root   80 12月 15 00:37 .ssh
-rw-r--r--.  1 root root  129 12月 29 2013 .tcshrc


==cat可以查看普通的文本文档,即前面带—,权限烈性显示为普通文档的,所以类似/bin/ls 这类的二进制文件就不能查看了==

[root@xavi-001 ~]# cat anaconda-ks.cfg
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
cdrom
# Use graphical install
graphical


首字母为c,表示的是字符串设备,比如鼠标和键盘,首字母为l表示是软链接设备,相当于Windows里面的额快捷方式,表示一个指向;首字母是不,block,块设备
*、
[root@xavi-001 ~]# ls -l /dev/
总用量 0
crw-rw---- 1 root video    10, 175 12月 16 09:32 agpgart
crw------- 1 root root     10, 235 12月 16 09:32 autofs
drwxr-xr-x 2 root root         140 12月 16 09:32 block
drwxr-xr-x 2 root root          80 12月 16 09:32 bsg
crw------- 1 root root     10, 234 12月 16 09:32 btrfs-control
drwxr-xr-x 3 root root          60 12月 16 09:32 bus
lrwxrwxrwx 1 root root           3 12月 16 09:32 cdrom -> sr0
drwxr-xr-x 2 root root        3060 12月 16 09:33 char
crw------- 1 root root      5,   1 12月 16 09:32 console
lrwxrwxrwx 1 root root          11 12月 16 09:32 core -> /proc/kcore
drwxr-xr-x 3 root root          80 12月 16 09:32 cpu
crw------- 1 root root     10,  61 12月 16 09:32 cpu_dma_latency
crw------- 1 root root     10,  62 12月 16 09:32 crash
drwxr-xr-x 5 root root         100 12月 16 09:32 disk
crw-rw---- 1 root audio    14,   9 12月 16 09:32 dmmidi
drwxr-xr-x 2 root root         100 12月 16 09:32 dri
crw-rw---- 1 root video    29,   0 12月 16 09:32 fb0
lrwxrwxrwx 1 root root          13 12月 16 09:32 fd -> /proc/self/fd


[root@xavi-001 ~]# ls -l /dev/log
srw-rw-rw- 1 root root 0 12月 16 09:32 /dev/log

总结前面所学的的文件类型

[root@xavi-001 ~]# d - c b s l

四 alias命令

前面使用的ll,ls都是有别名的,如何查找他们的别名呢,使用which,这里可看到alias表示的就是这个指令是由命令+选项的组合形成的新的命令

[root@xavi-001 ~]# which ls
alias ls='ls --color=auto'
/usr/bin/ls

[root@xavi-001 ~]# ls
anaconda-ks.cfg  initial-setup-ks.cfg  [root@localhost
[root@xavi-001 ~]# /usr/bin/ls //此两条命令相同
anaconda-ks.cfg initial-setup-ks.cfg [root@localhost


查看系统中有哪些命令的是有别名的

[root@xavi-001 ~]# 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-tild


path命令,表示的一系列的路径,which在查看时用的就是PATH里的路径

[root@xavi-001 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin


如何创建别名,和消除别名,参考以下指令

[root@xavi-001 ~]# alias xavier='ls -lha'
[root@xavi-001 ~]# xavier
总用量 32K
dr-xr-x---.  5 root root  227 12月 13 00:02 .
dr-xr-xr-x. 17 root root  253 8月  10 22:50 ..
-rw-------.  1 root root 1.4K 8月   9 05:35 anaconda-ks.cfg
-rw-------.  1 root root 2.0K 12月 15 21:27 .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
drwxr-xr-x.  3 root root   18 8月  10 20:22 .cache
drwxr-xr-x.  3 root root   18 8月  10 20:22 .config
-rw-r--r--.  1 root root  100 12月 29 2013 .cshrc
-rw-r--r--.  1 root root 1.7K 8月   9 00:17 initial-setup-ks.cfg
-rw-r--r--   1 root root    0 12月 13 00:01 [root@localhost
drwx------.  2 root root   80 12月 15 00:37 .ssh
-rw-r--r--.  1 root root  129 12月 29 2013 .tcshrc
[root@xavi-001 ~]# which xavier
alias xavier='ls -lha'
/usr/bin/ls
[root@xavi-001 ~]# unalias xavier
[root@xavi-001 ~]# xavier
bash: xavier: 未找到命令...
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Linux 文件类型 alias ls