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文件

相关文章
相关标签/搜索