Linux目錄結構,命令,文件類型學習

[toc]node

Linux目錄結構,命令,文件類型學習

1、 系統目錄結構

簡述linux

對於目錄,咱們大體可以理解,像書本學的章節,每一個章下又都有不少小節同樣;而Linux目錄和Windows目錄有着很大的不一樣,Linux目錄相似一個樹,最頂層是其根目錄,以下圖:數據庫

1.1 命令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用戶家目錄,存配置文件),普通用戶文件夾目錄在home下
[root@xavi-001 ~]# ls /root/
anaconda-ks.cfg

1.2 useradd建立新用戶

[root@xavi-001 ~]# useradd user1  //建立新用戶user1
[root@xavi-001 ~]# ls /home/user1/ //普通用戶user文件夾目錄在home下
  • 使用 su - 切換用戶名
[root@xavilinux01 ~]# su - user01
[user01@xavilinux01 ~]$ 
[user01@xavilinux01 ~]$ su - root
密碼:

1.3 tree 命令用樹型的形式來顯示下面有哪些目錄子目錄

系統沒有tree指令,須要用yum來安裝bash

[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 <font color=red>內容</font> 用量顯示文檔的全稱,按q退出

mark

1.5 經常使用目錄說明

  • /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)

mark

mark

  • /media:系統會自動識別一些設備(如U盤、光驅等),當識別後,Linux會把識別的設備掛載到該目錄下。session

  • /mnt:系統提供該目錄是爲了讓用戶臨時掛載別的文件系統。咱們能夠將光驅掛載到/mnt/上,而後進入該目錄查看光驅裏的內容。dom

  • /opt:這是給主機額外安裝軟件所設置的目錄,該目錄默認爲空。好比你要安裝一個ORACLE數據庫,能夠放到該目錄下。ssh

[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等,每一個進程都會有文件和目錄,基本同樣socket

[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 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/

2、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命令 ls -l -i -a -t -h -d

[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

3、 文件類型 d - c b s l

mark

[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裏面的額快捷方式,表示一個指向;首字母是b,block,塊設備;s =socket 套接文件,用於進程間通訊
[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

總結前面所學的的文件類型ide

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

4、 alias命令

「alias」=故名思議是取別名的意思,將一個經常使用的比較長的命令用一個別名替代。

「which」=查詢該命令所在目錄;

前面使用的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裏的路徑

PATH命令,表示的一系列的路徑,which在查看時用的就是PATH裏的路徑;在Linux安裝一些軟件一般要添加路徑環境變量PATH.PATH環境變量通俗的講就是把程序的路徑"備案"到系統中,這樣執行這些程序時就不須要輸入完整路徑,直接在bash輸入程序名就能夠執行.好比經常使用的"ls"命令就是添加好了環境變量才能夠直接執行ls;

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

如何建立別名,和消除別名,參考如下指令 alias xavier='ls -lha'

[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: 未找到命令...

注:alias的效力僅限於該次登陸的操做,重啓後失效。 若要使得該別名永久生效,須要編輯 .profile 或 .cshrc文件

相關文章
相關標籤/搜索