2018.6.1任务

Wesley13
• 阅读 664

2.1/2.2 系统目录结构

ls命令可以列写目录,可以看一下根目录下的内容。

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

root用户的家目录就在/root/

[root@lhy ~]# ls /root
anaconda-ks.cfg  openscap_data

家目录用于存储用户的配置文件和普通文件,比如

[root@lhy ~]# ls /root/.ssh/authorized_keys 
/root/.ssh/authorized_keys

如果我希望通过ssh连接一个普通的非root用户,那么就需要把这个配置文件(公钥)放置在对应用户的家目录里(/etc/ssh/sshd_config文件规定的)。比如,新建一个用户lhy01,这个配置文件就需要放置在/home/lhy01/下,这个目录在创建用户时候会自动创建。

[root@lhy ~]# useradd lhy01
[root@lhy ~]# ls /home/
lhy01
[root@lhy ~]# ls /home/lhy01/ -a
.  ..  .bash_logout  .bash_profile  .bashrc

想查看一个目录有什么子目录,可以用tree命令。如果没有安装可以用yum安装。

[root@lhy ~]# yum install tree -y
Loaded plugins: fastestmirror
base                                                                                                | 3.6 kB  00:00:00     
extras                                                                                              | 3.4 kB  00:00:00     
updates                                                                                             | 3.4 kB  00:00:00     
(1/2): extras/7/x86_64/primary_db                                                                   | 147 kB  00:00:00     
(2/2): updates/7/x86_64/primary_db                                                                  | 2.0 MB  00:00:00     
Loading mirror speeds from cached hostfile
 * base: mirrors.huaweicloud.com
 * extras: mirrors.163.com
 * updates: mirrors.huaweicloud.com
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================================
 Package                   Arch                        Version                             Repository                 Size
===========================================================================================================================
Installing:
 tree                      x86_64                      1.6.0-10.el7                        base                       46 k

Transaction Summary
===========================================================================================================================
Install  1 Package

Total download size: 46 k
Installed size: 87 k
Downloading packages:
tree-1.6.0-10.el7.x86_64.rpm                                                                        |  46 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : tree-1.6.0-10.el7.x86_64                                                                                1/1 
  Verifying  : tree-1.6.0-10.el7.x86_64                                                                                1/1 

Installed:
  tree.x86_64 0:1.6.0-10.el7                                                                                               

Complete!

tree可以简单的可以显示一个文档

tree /

但是由于文件过于多,可能突破Xshell的ScrollBack上限。我们用参数来显示两层目录。查看tree的用法有两种,一种是用tree本身来看,另一种是用Manual Page命令。

[root@lhy ~]# tree --help
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>]
  ------- Listing options -------
  -a            All files are listed.
  -d            List directories only.
  -l            Follow symbolic links like directories.
  -f            Print the full path prefix for each file.
  -x            Stay on current filesystem only.
  -L level      Descend only level directories deep.
  -R            Rerun tree when max dir level reached.
  -P pattern    List only those files that match the pattern given.
  -I pattern    Do not list files that match the given pattern.
  --noreport    Turn off file/directory count at end of tree listing.
  --charset X   Use charset X for terminal/HTML and indentation line output.
  --filelimit # Do not descend dirs with more than # files in them.
  --timefmt <f> Print and format time according to the format <f>.
  -o filename   Output to file instead of stdout.
  --du          Print directory sizes.
  --prune       Prune empty directories from the output.
  -------- File options ---------
  -q            Print non-printable characters as '?'.
  -N            Print non-printable characters as is.
  -Q            Quote filenames with double quotes.
  -p            Print the protections for each file.
  -u            Displays file owner or UID number.
  -g            Displays file group owner or GID number.
  -s            Print the size in bytes of each file.
  -h            Print the size in a more human readable way.
  --si          Like -h, but use in SI units (powers of 1000).
  -D            Print the date of last modification or (-c) status change.
  -F            Appends '/', '=', '*', '@', '|' or '>' as per ls -F.
  --inodes      Print inode number of each file.
  --device      Print device ID number to which each file belongs.
  ------- Sorting options -------
  -v            Sort files alphanumerically by version.
  -r            Sort files in reverse alphanumeric order.
  -t            Sort files by last modification time.
  -c            Sort files by last status change time.
  -U            Leave files unsorted.
  --dirsfirst   List directories before files (-U disables).
  ------- Graphics options ------
  -i            Don't print indentation lines.
  -A            Print ANSI lines graphic indentation lines.
  -S            Print with ASCII graphics indentation lines.
  -n            Turn colorization off always (-C overrides).
  -C            Turn colorization on always.
  ------- XML/HTML options -------
  -X            Prints out an XML representation of the tree.
  -H baseHREF   Prints out HTML format with baseHREF as top directory.
  -T string     Replace the default HTML title and H1 header with string.
  --nolinks     Turn off hyperlinks in HTML output.
  ---- Miscellaneous options ----
  --version     Print version and exit.
  --help        Print usage and this help message and exit.


[root@lhy ~]# man tree

TREE(1)                                         General Commands Manual                                         TREE(1)

NAME
       tree - list contents of directories in a tree-like format.

SYNOPSIS
       tree  [-acdfghilnpqrstuvxACDFQNSUX]  [-L level [-R]] [-H baseHREF] [-T title] [-o filename] [--nolinks] [-P pat‐
       tern] [-I pattern] [--inodes] [--device] [--noreport] [--dirsfirst] [--version] [--help] [--filelimit #]  [--si]
       [--prune] [--du] [--timefmt format] [directory ...]

DESCRIPTION
       Tree  is  a  recursive  directory listing program that produces a depth indented listing of files, which is col‐
       orized ala dircolors if the LS_COLORS environment variable is set and output is to tty.  With no arguments, tree
       lists  the  files in the current directory.  When directory arguments are given, tree lists all the files and/or
       directories found in the given directories each in turn.   Upon  completion  of  listing  all  files/directories
       found, tree returns the total number of files and/or directories listed.

       By  default, when a symbolic link is encountered, the path that the symbolic link refers to is printed after the
       name of the link in the format:

           name -> real-path

       If the `-l' option is given and the symbolic link refers to an actual directory, then tree will follow the  path
       of the symbolic link as if it were a real directory.

OPTIONS
       Tree understands the following command line switches:

LISTING OPTIONS
       -a     All files are printed.  By default tree does not print hidden files (those beginning with a dot `.').  In
              no event does tree print the file system constructs `.' (current directory)  and  `..'  (previous  direc‐
              tory).

       -d     List directories only.

       -l     Follows  symbolic  links  if  they point to directories, as if they were directories. Symbolic links that
              will result in recursion are avoided when detected.

       -f     Prints the full path prefix for each file.

       -x     Stay on the current file-system only.  Ala find -xdev.

       -L level
              Max display depth of the directory tree.

       -R     Recursively cross down the tree each level directories (see -L option), and at each of them execute  tree
              again adding `-o 00Tree.html' as a new option.

       -P pattern
              List  only  those  files that match the wild-card pattern.  Note: you must use the -a option to also con‐
              sider those files beginning with a dot `.'  for matching.  Valid wildcard operators are `*' (any zero  or
              more  characters),  `?'  (any  single  character),  `[...]' (any single character listed between brackets
              (optional - (dash) for character range may be used: ex: [A-Z]), and `[^...]' (any  single  character  not
              listed in brackets) and `|' separates alternate patterns.

       -I pattern
              Do not list those files that match the wild-card pattern.

       --prune
              Makes  tree  prune empty directories from the output, useful when used in conjunction with -P or -I.  See
              BUGS AND NOTES below for more information on this option.

       --noreport
              Omits printing of the file and directory report at the end of the tree listing.

       --charset charset
              Set the character set to use when outputting HTML and for line drawing.

       --filelimit #
              Do not descend directories that contain more than # entries.


       --timefmt format
              Prints (implies -D) and formats the date according to the format string which uses the  strftime(3)  syn‐
              tax.

       -o filename
              Send output to filename.

FILE OPTIONS
       -q     Print non-printable characters in filenames as question marks instead of the default.

       -N     Print non-printable characters as is instead of as escaped octal numbers.

       -Q     Quote the names of files in double quotes.

       -p     Print the file type and permissions for each file (as per ls -l).

       -u     Print the username, or UID # if no username is available, of the file.

       -g     Print the group name, or GID # if no group name is available, of the file.

       -s     Print the size of each file in bytes along with the name.

       -h     Print  the size of each file but in a more human readable way, e.g. appending a size letter for kilobytes
              (K), megabytes (M), gigabytes (G), terabytes (T), petabytes (P) and exabytes (E).

       --si   Like -h but use SI units (powers of 1000) instead.

       --du   For each directory report its size as the accumulation of sizes of all its files and sub-directories (and
              their  files, and so on).  The total amount of used space is also given in the final report (like the 'du
              -c' command.) This option requires tree to read the entire directory tree before emitting  it,  see  BUGS
              AND NOTES below.  Implies -s.

       -D     Print  the  date of the last modification time or if -c is used, the last status change time for the file
              listed.

       -F     Append a `/' for directories, a `=' for socket files, a  `*'  for  executable  files,  a  `>'  for  doors
              (Solaris) and a `|' for FIFO's, as per ls -F

       -F     Append a `/' for directories, a `=' for socket files, a  `*'  for  executable  files,  a  `>'  for  doors
              (Solaris) and a `|' for FIFO's, as per ls -F

       --inodes
              Prints the inode number of the file or directory

       --device
              Prints the device number to which the file or directory belongs

SORTING OPTIONS
       -v     Sort the output by version.

       -r     Sort the output in reverse alphabetic order.

       -t     Sort the output by last modification time instead of alphabetically.

       -c     Sort  the  output  by  last status change instead of alphabetically.  Modifies the -D option (if used) to
              print the last status change instead of modification time.

       -U     Do not sort.  Lists files in directory order. Disables --dirsfirst.

       --dirsfirst
              List directories before files. This is a meta-sort that alters the above sorts.  This option is  disabled
              when -U is used.

GRAPHICS OPTIONS
       -i     Makes tree not print the indentation lines, useful when used in conjunction with the -f option.

       -A     Turn on ANSI line graphics hack when printing the indentation lines.

       -S     Turn  on  ASCII line graphics (useful when using Linux console mode fonts). This option is now equivalent
              to `--charset=IBM437' and may eventually be depreciated.

       -n     Turn colorization off always, over-ridden by the -C option.

       -C     Turn colorization on always, using built-in color defaults if the LS_COLORS environment variable  is  not
              set.  Useful to colorize output to a pipe.

XML/HTML OPTIONS
       -X     Turn on XML output. Outputs the directory tree as an XML formatted file.

       -H baseHREF
              Turn  on HTML output, including HTTP references. Useful for ftp sites.  baseHREF gives the base ftp loca‐
              tion when using HTML output. That is, the local directory may be `/local/ftp/pub', but it must be  refer‐
              enced   as   `ftp://hostname.organization.domain/pub'   (baseHREF   should  be  `ftp://hostname.organiza‐
              tion.domain'). Hint: don't use ANSI lines with this option, and don't give more than one directory in the
              directory  list.  If  you  wish  to use colors via CCS style-sheet, use the -C option in addition to this
              option to force color output.

       -T title
              Sets the title and H1 header string in HTML output mode.

       --nolinks
              Turns off hyperlinks in HTML output.

MISC OPTIONS
       --help Outputs a verbose usage listing.

       --version
              Outputs the version of tree.

FILES
       /etc/DIR_COLORS          System color database.
       ~/.dircolors        Users color database.


ENVIRONMENT
       LS_COLORS      Color information created by dircolors
       TREE_COLORS    Uses this for color information over LS_COLORS if it is set.
       TREE_CHARSET   Character set for tree to use in HTML mode.
       LC_CTYPE       Locale for filename output.
       LC_TIME        Locale for timefmt output, see strftime(3).
       TZ             Timezone for timefmt output, see strftime(3).

AUTHOR
       Steve Baker (ice@mama.indstate.edu)
       HTML output hacked by Francesc Rocher (rocher@econ.udg.es)
       Charsets and OS/2 support by Kyosuke Tokoro (NBG01720@nifty.ne.jp)

BUGS AND NOTES
       Tree does not prune "empty" directories when the -P and -I options are used by default. Use the --prune option.

       The -h and --si options round to the nearest whole number unlike the ls implementations which rounds up always.

       Pruning files and directories with the -I, -P and --filelimit options  will  lead  to  incorrect  file/directory
       count reports.

       The  --prune  and  --du options cause tree to accumulate the entire tree in memory before emitting it. For large
       directory trees this can cause a significant delay in output and the use of large amounts of memory.

       The timefmt expansion buffer is limited to a ridiculously large 255 characters.  Output of time  strings  longer
       than this will be undefined, but are guaranteed to not exceed 255 characters.

       XML trees are not colored, which is a bit of a shame.

       Probably more.

SEE ALSO
       dircolors(1), ls(1), find(1), du(1), strftime(3)

Tree 1.6.0     

 Manual page tree(1) line 1 (press h for help or q to quit)

可以看到用-L参数可以设置最深搜索层数,-d只显示文件夹。

[root@lhy ~]# tree / -L 2 -d
/
├── bin -> usr/bin
├── boot
│   ├── efi
│   ├── grub
│   └── grub2
├── dev
│   ├── block
│   ├── bsg
│   ├── bus
│   ├── char
│   ├── cpu
│   ├── disk
│   ├── dri
│   ├── fd -> /proc/self/fd
│   ├── hugepages
│   ├── input
│   ├── mapper
│   ├── mqueue
│   ├── net
│   ├── pts
│   ├── raw
│   ├── shm
│   ├── snd
│   └── vfio
├── etc
│   ├── alternatives
│   ├── audisp
│   ├── audit
│   ├── bash_completion.d
│   ├── binfmt.d
│   ├── chkconfig.d
│   ├── cron.d
│   ├── cron.daily
│   ├── cron.hourly
│   ├── cron.monthly
│   ├── cron.weekly
│   ├── dbus-1
│   ├── default
│   ├── depmod.d
│   ├── dhcp
│   ├── dracut.conf.d
│   ├── firewalld
│   ├── gcrypt
│   ├── gnupg
│   ├── groff
│   ├── grub.d
│   ├── gss
│   ├── init.d -> rc.d/init.d
│   ├── iproute2
│   ├── kernel
│   ├── krb5.conf.d
│   ├── ld.so.conf.d
│   ├── libnl
│   ├── logrotate.d
│   ├── modprobe.d
│   ├── modules-load.d
│   ├── my.cnf.d
│   ├── NetworkManager
│   ├── openldap
│   ├── opt
│   ├── pam.d
│   ├── pkcs11
│   ├── pki
│   ├── plymouth
│   ├── pm
│   ├── polkit-1
│   ├── popt.d
│   ├── postfix
│   ├── ppp
│   ├── prelink.conf.d
│   ├── profile.d
│   ├── python
│   ├── rc0.d -> rc.d/rc0.d
│   ├── rc1.d -> rc.d/rc1.d
│   ├── rc2.d -> rc.d/rc2.d
│   ├── rc3.d -> rc.d/rc3.d
│   ├── rc4.d -> rc.d/rc4.d
│   ├── rc5.d -> rc.d/rc5.d
│   ├── rc6.d -> rc.d/rc6.d
│   ├── rc.d
│   ├── rpm
│   ├── rsyslog.d
│   ├── rwtab.d
│   ├── sasl2
│   ├── security
│   ├── selinux
│   ├── sgml
│   ├── skel
│   ├── ssh
│   ├── ssl
│   ├── statetab.d
│   ├── sudoers.d
│   ├── sysconfig
│   ├── sysctl.d
│   ├── systemd
│   ├── terminfo
│   ├── tmpfiles.d
│   ├── tuned
│   ├── udev
│   ├── vmware-tools
│   ├── wpa_supplicant
│   ├── X11
│   ├── xdg
│   ├── xinetd.d
│   ├── xml
│   ├── yum
│   └── yum.repos.d
├── home
│   └── lhy01
├── lib -> usr/lib
├── lib64 -> usr/lib64
├── media
├── mnt
├── opt
├── proc
│   ├── 1
│   ├── 10
│   ├── 11
│   ├── acpi
│   ├── asound
│   ├── bus
│   ├── driver
│   ├── fs
│   ├── irq
│   ├── mpt
│   ├── net -> self/net
│   ├── scsi
│   ├── self -> 1879
│   ├── sys
│   ├── sysvipc
│   └── tty
├── root
│   └── openscap_data
├── run
│   ├── console
│   ├── dbus
│   ├── faillock
│   ├── firewalld
│   ├── initramfs
│   ├── lock
│   ├── log
│   ├── mount
│   ├── netreport
│   ├── NetworkManager
│   ├── plymouth
│   ├── sepermit
│   ├── setrans
│   ├── sudo
│   ├── systemd
│   ├── tmpfiles.d
│   ├── tuned
│   ├── udev
│   ├── user
│   └── vmware
├── sbin -> usr/sbin
├── srv
├── sys
│   ├── block
│   ├── bus
│   ├── class
│   ├── dev
│   ├── devices
│   ├── firmware
│   ├── fs
│   ├── hypervisor
│   ├── kernel
│   ├── module
│   └── power
├── tmp
│   ├── systemd-private-72a51b409754493b803ada2e9f1e8ca6-vgauthd.service-SJRZXu
│   ├── systemd-private-72a51b409754493b803ada2e9f1e8ca6-vmtoolsd.service-Ct0xiS
│   ├── systemd-private-b5d827de47c64188ae996c7b05c8f1b2-vgauthd.service-SHMZTz
│   └── systemd-private-b5d827de47c64188ae996c7b05c8f1b2-vmtoolsd.service-LXMW2A
├── usr
│   ├── bin
│   ├── etc
│   ├── games
│   ├── include
│   ├── lib
│   ├── lib64
│   ├── libexec
│   ├── local
│   ├── sbin
│   ├── share
│   ├── src
│   └── tmp -> ../var/tmp
└── var
    ├── adm
    ├── cache
    ├── crash
    ├── db
    ├── empty
    ├── games
    ├── gopher
    ├── kerberos
    ├── lib
    ├── local
    ├── lock -> ../run/lock
    ├── log
    ├── mail -> spool/mail
    ├── nis
    ├── opt
    ├── preserve
    ├── run -> ../run
    ├── spool
    ├── tmp
    └── yp

370 directories

目录/usr/bin/  /usr/sbin/   /bin/  /sbin/ 这几个目录中保存的是一系列的命令。为什么直接敲命令而不需要执行具体目录下的文件,这是因为环境变量PATH的作用,这点之后再讲。

/sbin/下的命令一般是root用户的命令,普通用户下的命令一般是/bin/下的。

[root@lhy ~]# ls /sbin/
accessdb              e2fsck                     ip                 nl-link-list                sestatus
addgnupghome          e2image                    ip6tables          nl-pktloc-lookup            setcap
addpart               e2label                    ip6tables-restore  nl-qdisc-add                setenforce
adduser               e2undo                     ip6tables-save     nl-qdisc-delete             setfiles
agetty                e4defrag                   ipmaddr            nl-qdisc-list               setpci
aide                  eapol_test                 iprconfig          nologin                     setsebool
alternatives          ebtables                   iprdbg             nstat                       sfdisk
anacron               ebtables-restore           iprdump            ownership                   shutdown
applygnupgdefaults    ebtables-save              iprinit            packer                      slattach
arp                   ether-wake                 iprsos             pam_console_apply           sln
arpd                  ethtool                    iprupdate          pam_tally2                  smtp-sink
arping                faillock                   ipset              pam_timestamp_check         smtp-source
audispd               fdformat                   iptables           parted                      ss
auditctl              fdisk                      iptables-restore   partprobe                   sshd
auditd                filefrag                   iptables-save      partx                       sshd-keygen
augenrules            findfs                     iptunnel           pidof                       sulogin
aureport              firewalld                  irqbalance         ping6                       sushell
ausearch              fixfiles                   kdump              pivot_root                  swaplabel
authconfig            fsck                       kexec              plipconfig                  swapoff
authconfig-tui        fsck.btrfs                 killall5           plymouthd                   swapon
autrace               fsck.cramfs                kpartx             plymouth-set-default-theme  switch_root
avcstat               fsck.ext2                  lchage             postalias                   sysctl
badblocks             fsck.ext3                  ldattach           postcat                     sys-unconfig
biosdecode            fsck.ext4                  ldconfig           postconf                    tc
biosdevname           fsck.minix                 lgroupadd          postdrop                    telinit
blkdeactivate         fsck.xfs                   lgroupdel          postfix                     tracepath
blkdiscard            fsfreeze                   lgroupmod          postkick                    tracepath6
blkid                 fstrim                     lid                postlock                    tune2fs
blockdev              fxload                     lnewusers          postlog                     tuned
bridge                genhomedircon              lnstat             postmap                     tuned-adm
btrfs                 genhostid                  load_policy        postmulti                   udevadm
btrfsck               genl                       logrotate          postqueue                   unix_chkpwd
btrfs-convert         genl-ctrl-list             logsave            postsuper                   unix_update
btrfs-debug-tree      getcap                     losetup            poweroff                    update-alternatives
btrfs-find-root       getenforce                 lpasswd            ppp-watch                   update-pciids
btrfs-image           getpcaps                   lsmod              pwck                        useradd
btrfs-map-logical     getsebool                  lspci              pwconv                      userdel
btrfs-select-super    glibc_post_upgrade.x86_64  luseradd           pwhistory_helper            usermod
btrfstune             groupadd                   luserdel           pwunconv                    usernetctl
btrfs-zero-log        groupdel                   lusermod           rdisc                       vigr
build-locale-archive  groupmems                  makedumpfile       readprofile                 vipw
cacertdir_rehash      groupmod                   matchpathcon       reboot                      virt-what
capsh                 grpck                      mii-diag           resize2fs                   visudo
cbq                   grpconv                    mii-tool           resizepart                  vmcore-dmesg
cfdisk                grpunconv                  mkdict             restorecon                  vpddecode
chcpu                 grub2-bios-setup           mkdumprd           rmmod                       weak-modules
chkconfig             grub2-get-kernel-settings  mke2fs             route                       wipefs
chpasswd              grub2-install              mkfs               routef                      wpa_cli
chroot                grub2-mkconfig             mkfs.btrfs         routel                      wpa_passphrase
clock                 grub2-ofpathname           mkfs.cramfs        rsyslogd                    wpa_supplicant
clockdiff             grub2-probe                mkfs.ext2          rtacct                      xfs_admin
consoletype           grub2-reboot               mkfs.ext3          rtcwake                     xfs_bmap
cracklib-check        grub2-rpm-sort             mkfs.ext4          rtmon                       xfs_copy
cracklib-format       grub2-set-default          mkfs.minix         rtpr                        xfs_db
cracklib-packer       grub2-setpassword          mkfs.xfs           rtstat                      xfs_estimate
cracklib-unpacker     grub2-sparc64-setup        mkhomedir_helper   runlevel                    xfs_freeze
create-cracklib-dict  grubby                     mklost+found       runuser                     xfs_fsr
crond                 halt                       mkswap             sasldblistusers2            xfs_growfs
ctrlaltdel            hardlink                   modinfo            saslpasswd2                 xfs_info
ctstat                hwclock                    modprobe           sefcontext_compile          xfs_io
debugfs               iconvconfig                mount.fuse         selabel_digest              xfs_logprint
delpart               iconvconfig.x86_64         nameif             selabel_lookup              xfs_mdrestore
depmod                ifcfg                      netreport          selabel_lookup_best_match   xfs_metadump
devlink               ifconfig                   NetworkManager     selabel_partial_match       xfs_mkfile
dhclient              ifdown                     new-kernel-pkg     selinuxconlist              xfs_ncheck
dhclient-script       ifenslave                  newusers           selinuxdefcon               xfs_quota
dmfilemapd            ifstat                     nl-class-add       selinuxenabled              xfs_repair
dmidecode             ifup                       nl-class-delete    selinuxexeccon              xfs_rtcp
dmsetup               init                       nl-classid-lookup  selinux_restorecon          xtables-multi
dmstats               insmod                     nl-class-list      semodule                    zdump
dracut                install-info               nl-cls-add         sendmail                    zic
dumpe2fs              installkernel              nl-cls-delete      sendmail.postfix            zramctl
e2freefrag            intel-microcode2ucode      nl-cls-list        service
[root@lhy ~]# ls /bin/
[                     groups                 nl-link-set               sotruss
a2p                   grub2-editenv          nl-link-stats             splain
addr2line             grub2-file             nl-list-caches            split
alias                 grub2-fstest           nl-list-sockets           sprof
apropos               grub2-glue-efi         nl-monitor                sqlite3
ar                    grub2-kbdcomp          nl-neigh-add              ssh
arch                  grub2-menulst2cfg      nl-neigh-delete           ssh-add
as                    grub2-mkfont           nl-neigh-list             ssh-agent
aserver               grub2-mkimage          nl-neightbl-list          ssh-copy-id
aulast                grub2-mklayout         nl-pktloc-lookup          ssh-keygen
aulastlog             grub2-mknetdir         nl-qdisc-add              ssh-keyscan
ausyscall             grub2-mkpasswd-pbkdf2  nl-qdisc-delete           ssltap
auvirt                grub2-mkrelpath        nl-qdisc-list             stat
awk                   grub2-mkrescue         nl-route-add              stdbuf
base64                grub2-mkstandalone     nl-route-delete           strings
basename              grub2-script-check     nl-route-get              strip
bash                  grub2-syslinux2cfg     nl-route-list             stty
bashbug               gsettings              nl-rule-list              su
bashbug-64            gsoelim                nl-tctree-list            sudo
bg                    gtar                   nl-util-addr              sudoedit
bond2team             gtbl                   nm                        sudoreplay
bootctl               gtroff                 nmcli                     sum
busctl                gunzip                 nm-online                 sync
c2ph                  gzexe                  nmtui                     systemctl
cal                   gzip                   nmtui-connect             systemd-analyze
ca-legacy             h2ph                   nmtui-edit                systemd-ask-password
captoinfo             hdsploader             nmtui-hostname            systemd-cat
cat                   head                   nohup                     systemd-cgls
catchsegv             hexdump                nproc                     systemd-cgtop
catman                hostid                 nroff                     systemd-coredumpctl
cd                    hostname               nsenter                   systemd-delta
centrino-decode       hostnamectl            numfmt                    systemd-detect-virt
certutil              i386                   objcopy                   systemd-escape
c++filt               iconv                  objdump                   systemd-firstboot
chacl                 id                     od                        systemd-hwdb
chage                 idiag-socket-details   oldfind                   systemd-inhibit
chattr                idn                    open                      systemd-loginctl
chcon                 igawk                  openssl                   systemd-machine-id-setup
chfn                  info                   openvt                    systemd-notify
chgrp                 infocmp                oscap                     systemd-nspawn
chmod                 infokey                os-prober                 systemd-path
chown                 infotocap              p11-kit                   systemd-run
chrt                  install                passwd                    systemd-stdio-bridge
chsh                  ionice                 paste                     systemd-sysv-convert
chvt                  ipcalc                 pathchk                   systemd-tmpfiles
cksum                 ipcmk                  pchrt                     systemd-tty-ask-password-agent
clear                 ipcrm                  perl                      tabs
cmp                   ipcs                   perl5.16.3                tac
cmsutil               iptables-xml           perlbug                   tail
col                   isosize                perldoc                   tailf
colcrt                jobs                   perlthanks                tar
colrm                 join                   pflags                    taskset
column                journalctl             pgawk                     tbl
comm                  kbdinfo                pgrep                     teamd
command               kbd_mode               pic                       teamdctl
coredumpctl           kbdrate                piconv                    teamnl
cp                    kdumpctl               pinentry                  tee
cpio                  kernel-install         pinentry-curses           test
cpupower              kill                   ping                      testgdbm
crlutil               kmod                   ping6                     tic
crontab               last                   pinky                     timedatectl
csplit                lastb                  pk12util                  timeout
csslint-0.6           lastlog                pkaction                  tload
curl                  lchfn                  pkcheck                   tmon
cut                   lchsh                  pkexec                    toe
date                  ld                     pkg-config                top
db_archive            ld.bfd                 pkill                     touch
db_checkpoint         ldd                    pkla-admin-identities     tput
db_deadlock           ld.gold                pkla-check-authorization  tr
db_dump               less                   pkttyagent                tracepath
db_dump185            lessecho               pl2pm                     tracepath6
db_hotbackup          lesskey                pldd                      tree
db_load               lesspipe.sh            plymouth                  troff
db_log_verify         lexgrog                pmap                      true
db_printlog           link                   pod2html                  truncate
db_recover            linux32                pod2man                   trust
db_replicate          linux64                pod2text                  tset
db_stat               linux-boot-prober      pod2usage                 tsort
db_tuner              ln                     post-grohtml              tty
db_upgrade            loadkeys               powernow-k8-decode        turbostat
dbus-binding-tool     loadunimap             pr                        tzselect
dbus-cleanup-sockets  locale                 preconv                   udevadm
dbus-daemon           localectl              pre-grohtml               ul
dbus-monitor          localedef              printenv                  ulockmgr_server
dbus-send             logger                 printf                    umask
dbus-uuidgen          login                  prlimit                   umount
db_verify             loginctl               ps                        unalias
dd                    logname                psed                      uname
deallocvt             look                   psfaddtable               unexpand
df                    ls                     psfgettable               unicode_start
dgawk                 lsattr                 psfstriptable             unicode_stop
diff                  lsblk                  psfxtable                 uniq
diff3                 lscpu                  pstruct                   unlink
dir                   lsinitrd               ptaskset                  unshare
dircolors             lsipc                  ptx                       unxz
dirname               lslocks                pwd                       update-ca-trust
dmesg                 lslogins               pwdx                      update-mime-database
dnsdomainname         lsns                   pwmake                    uptime
domainname            lsscsi                 pwscore                   urlgrabber
dracut                lua                    pydoc                     users
du                    luac                   python                    usleep
dumpkeys              machinectl             python2                   usx2yloader
dwp                   mailq                  python2.7                 utmpdump
echo                  mailq.postfix          ranlib                    uuidgen
egrep                 make                   raw                       vdir
eject                 makedb                 read                      VGAuthService
elfedit               man                    readelf                   vi
env                   mandb                  readlink                  view
envsubst              manpath                realpath                  vim
eqn                   mapscrn                recode-sr-latin           vimdiff
ex                    mcookie                rename                    vimtutor
expand                md5sum                 renice                    vlock
expr                  mesg                   reset                     vmhgfs-fuse
factor                mixartloader           resizecons                vmstat
fallocate             mkdir                  rev                       vm-support
false                 mkfifo                 rm                        vmtoolsd
fc                    mkinitrd               rmail                     vmware-checkvm
fg                    mknod                  rmail.postfix             vmware-guestproxycerttool
fgconsole             mktemp                 rmdir                     vmware-hgfsclient
fgrep                 modutil                rpcgen                    vmware-namespace-cmd
file                  more                   rpm                       vmware-rpctool
find                  mount                  rpm2cpio                  vmware-toolbox-cmd
find2perl             mountpoint             rpmdb                     vmware-vgauth-cmd
findmnt               msgattrib              rpmkeys                   vmware-xferlogs
fipscheck             msgcat                 rpmquery                  vxloader
fipshmac              msgcmp                 rpmverify                 w
firewall-cmd          msgcomm                rsyslog-recover-qi.pl     wait
firewall-offline-cmd  msgconv                runcon                    wall
flock                 msgen                  run-parts                 watch
fmt                   msgexec                rvi                       watchgnupg
fold                  msgfilter              rview                     wc
free                  msgfmt                 rvim                      wdctl
fusermount            msggrep                s2p                       whatis
gapplication          msghack                scp                       whereis
gawk                  msginit                script                    which
gdbus                 msgmerge               scriptreplay              whiptail
gencat                msgunfmt               sdiff                     who
genl-ctrl-list        msguniq                secon                     whoami
geoiplookup           mv                     sed                       write
geoiplookup6          namei                  seq                       x86_64
geoipupdate           ndptool                setarch                   x86_energy_perf_policy
geqn                  neqn                   setfacl                   xargs
getconf               netstat                setfont                   xgettext
getent                newaliases             setkeycodes               xmlcatalog
getfacl               newaliases.postfix     setleds                   xmllint
getkeycodes           newgrp                 setmetamode               xmlsec1
getopt                nf-ct-add              setpriv                   xmlwf
getopts               nf-ct-list             setsid                    xsltproc
gettext               nf-exp-add             setterm                   xxd
gettext.sh            nf-exp-delete          setup-nsssysinit          xz
gio                   nf-exp-list            setup-nsssysinit.sh       xzcat
gio-querymodules-64   nf-log                 setvtrgb                  xzcmp
glib-compile-schemas  nf-monitor             sftp                      xzdec
gmake                 nf-queue               sg                        xzdiff
gneqn                 ngettext               sh                        xzegrep
gnroff                nice                   sha1sum                   xzfgrep
gpasswd               nisdomainname          sha224sum                 xzgrep
gpg                   nl                     sha256sum                 xzless
gpg2                  nl-addr-add            sha384sum                 xzmore
gpg-agent             nl-addr-delete         sha512sum                 yes
gpgconf               nl-addr-list           showconsolefont           ypdomainname
gpg-connect-agent     nl-class-add           showkey                   yum
gpg-error             nl-class-delete        shred                     zcat
gpgparsemail          nl-classid-lookup      shuf                      zcmp
gpgsplit              nl-class-list          signtool                  zdiff
gpgv                  nl-cls-add             signver                   zegrep
gpgv2                 nl-cls-delete          size                      zfgrep
gpg-zip               nl-cls-list            skill                     zforce
gpic                  nl-fib-lookup          slabtop                   zgrep
gprof                 nl-link-enslave        sleep                     zless
grep                  nl-link-ifindex2name   slogin                    zmore
groff                 nl-link-list           snice                     znew
grops                 nl-link-name2ifindex   soelim                    zsoelim
grotty                nl-link-release        sort

/boot/下的文件是启动相关的文件,比如grub文件。比如删除了vmlinuz-3.10.0-693.el7.x86_64这些文件,你就不能正常启动这个系统了。

[root@lhy ~]# ls /boot/
config-3.10.0-693.el7.x86_64                             initramfs-3.10.0-693.el7.x86_64kdump.img
efi                                                      initrd-plymouth.img
grub                                                     symvers-3.10.0-693.el7.x86_64.gz
grub2                                                    System.map-3.10.0-693.el7.x86_64
initramfs-0-rescue-7b83625f83564e1691eca0a488be153c.img  vmlinuz-0-rescue-7b83625f83564e1691eca0a488be153c
initramfs-3.10.0-693.el7.x86_64.img                      vmlinuz-3.10.0-693.el7.x86_64

/dev/文件是linux系统的特有的设备文件,鼠标、键盘、显示器等文件都保存在这里。

[root@lhy ~]# ls /dev/
agpgart          dmmidi     log                 port    shm       tty14  tty27  tty4   tty52  tty8     vcs    vfio
autofs           dri        loop-control        ppp     snapshot  tty15  tty28  tty40  tty53  tty9     vcs1   vga_arbiter
block            fb0        mapper              ptmx    snd       tty16  tty29  tty41  tty54  ttyS0    vcs2   vhci
bsg              fd         mcelog              pts     sr0       tty17  tty3   tty42  tty55  ttyS1    vcs3   vhost-net
btrfs-control    fd0        mem                 random  stderr    tty18  tty30  tty43  tty56  ttyS2    vcs4   vmci
bus              full       midi                raw     stdin     tty19  tty31  tty44  tty57  ttyS3    vcs5   vsock
cdrom            fuse       mqueue              rtc     stdout    tty2   tty32  tty45  tty58  uhid     vcs6   zero
char             hidraw0    net                 rtc0    tty       tty20  tty33  tty46  tty59  uinput   vcsa
console          hpet       network_latency     sda     tty0      tty21  tty34  tty47  tty6   urandom  vcsa1
core             hugepages  network_throughput  sda1    tty1      tty22  tty35  tty48  tty60  usbmon0  vcsa2
cpu              hwrng      null                sda2    tty10     tty23  tty36  tty49  tty61  usbmon1  vcsa3
cpu_dma_latency  initctl    nvram               sda3    tty11     tty24  tty37  tty5   tty62  usbmon2  vcsa4
crash            input      oldmem              sg0     tty12     tty25  tty38  tty50  tty63  usbmon3  vcsa5
disk             kmsg       parport0            sg1     tty13     tty26  tty39  tty51  tty7   usbmon4  vcsa6

/etc/文件夹是系统的配置文件所在的位置。

[root@lhy ~]# ls /etc/sysconfig/network-scripts/ifcfg-ens33
/etc/sysconfig/network-scripts/ifcfg-ens33
[root@lhy ~]# ls /etc/ssh/sshd_config 
/etc/ssh/sshd_config
[root@lhy ~]# ls /etc/
adjtime                  ethertypes          ld.so.conf                popt.d          skel
aide.conf                exports             ld.so.conf.d              postfix         ssh
aliases                  favicon.png         libaudit.conf             ppp             ssl
aliases.db               filesystems         libnl                     prelink.conf.d  statetab
alternatives             firewalld           libuser.conf              printcap        statetab.d
anacrontab               fstab               locale.conf               profile         subgid
asound.conf              fuse.conf           localtime                 profile.d       subuid
audisp                   gcrypt              login.defs                protocols       sudo.conf
audit                    GeoIP.conf          logrotate.conf            python          sudoers
bash_completion.d        GeoIP.conf.default  logrotate.d               rc0.d           sudoers.d
bashrc                   gnupg               machine-id                rc1.d           sudo-ldap.conf
binfmt.d                 GREP_COLORS         magic                     rc2.d           sysconfig
centos-release           groff               makedumpfile.conf.sample  rc3.d           sysctl.conf
centos-release-upstream  group               man_db.conf               rc4.d           sysctl.d
chkconfig.d              group-              mke2fs.conf               rc5.d           systemd
cron.d                   grub2.cfg           modprobe.d                rc6.d           system-release
cron.daily               grub.d              modules-load.d            rc.d            system-release-cpe
cron.deny                gshadow             motd                      rc.local        terminfo
cron.hourly              gshadow-            mtab                      redhat-release  tmpfiles.d
cron.monthly             gss                 my.cnf                    resolv.conf     tuned
crontab                  host.conf           my.cnf.d                  rpc             udev
cron.weekly              hostname            NetworkManager            rpm             vconsole.conf
crypttab                 hosts               networks                  rsyslog.conf    vimrc
csh.cshrc                hosts.allow         nsswitch.conf             rsyslog.d       virc
csh.login                hosts.deny          nsswitch.conf.bak         rwtab           vmware-tools
dbus-1                   init.d              openldap                  rwtab.d         wpa_supplicant
default                  inittab             opt                       sasl2           X11
depmod.d                 inputrc             os-release                securetty       xdg
dhcp                     iproute2            pam.d                     security        xinetd.d
DIR_COLORS               issue               passwd                    selinux         xml
DIR_COLORS.256color      issue.net           passwd-                   services        yum
DIR_COLORS.lightbgcolor  kdump.conf          pkcs11                    sestatus.conf   yum.conf
dracut.conf              kernel              pki                       sgml            yum.repos.d
dracut.conf.d            krb5.conf           plymouth                  shadow
e2fsck.conf              krb5.conf.d         pm                        shadow-
environment              ld.so.cache         polkit-1                  shells

/home/是用户的家目录,存用户的文件,类比于/root/

[root@lhy ~]# ls /home/
lhy01

/lib/ /lib64/等文件夹存的是库文件。库文件类似于Windows下的×.dll文件。可以用ldd命令查看某个命令的依赖库。

[root@lhy ~]# ldd /bin/ls
    linux-vdso.so.1 =>  (0x00007ffd4e88f000)
    libselinux.so.1 => /lib64/libselinux.so.1 (0x00007feffcfcf000)
    libcap.so.2 => /lib64/libcap.so.2 (0x00007feffcdca000)
    libacl.so.1 => /lib64/libacl.so.1 (0x00007feffcbc0000)
    libc.so.6 => /lib64/libc.so.6 (0x00007feffc7fd000)
    libpcre.so.1 => /lib64/libpcre.so.1 (0x00007feffc59b000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007feffc396000)
    /lib64/ld-linux-x86-64.so.2 (0x00005636e812b000)
    libattr.so.1 => /lib64/libattr.so.1 (0x00007feffc191000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007feffbf75000)

CentOS7之后,CentOS操作系统就没有32位系统了。32位和64位系统的最大的区别就在于识别的内存大小不一样。如果是32位的系统,只能识别4GB内存,由于操作系统本身内存占用以及地址保留,实际可以使用的内存空间为3.2G左右。

/media/目录是媒介目录,默认是空的。如果插入优盘、硬盘,系统会自动挂载到/media目录。

/mnt/是挂载目录 ,默认也为空,可以把想要的文件系统挂载到此处。

/opt/默认也是空目录,是按完系统后你又需要安装其他的应用软件,一般是源码包的软件,可以自己指定路径,管理员习惯性的把软件按在这,你也可以安装在其他位置。

/proc/存放的是进程文件,每一个进程都有一个目录,文件夹名为PID

[root@lhy ~]# ls /proc/
1     16    265   291  304  319  332  346   399   55   641  acpi         filesystems  mdstat        softirqs
10    17    267   292  305  32   333  347   40    56   642  asound       fs           meminfo       stat
11    18    268   293  306  320  334  3535  400   57   644  buddyinfo    interrupts   misc          swaps
111   1805  27    294  307  321  335  372   401   580  645  bus          iomem        modules       sys
12    2     272   295  308  322  336  373   4018  581  647  cgroups      ioports      mounts        sysrq-trigger
1202  20    273   296  309  323  337  380   41    582  653  cmdline      irq          mpt           sysvipc
1203  21    274   297  31   324  338  383   42    583  666  consoles     kallsyms     mtrr          timer_list
1204  22    2763  298  311  325  339  391   4259  584  679  cpuinfo      kcore        net           timer_stats
1269  23    28    299  312  326  34   392   43    585  7    crypto       keys         pagetypeinfo  tty
1288  24    285   3    313  327  340  393   468   586  76   devices      key-users    partitions    uptime
1293  25    287   30   314  328  341  394   470   587  77   diskstats    kmsg         sched_debug   version
13    258   288   300  315  329  342  395   491   610  8    dma          kpagecount   schedstat     vmallocinfo
1346  260   289   301  316  33   343  396   5     634  9    driver       kpageflags   scsi          vmstat
15    263   29    302  317  330  344  397   51    636  969  execdomains  loadavg      self          zoneinfo
1525  264   290   303  318  331  345  398   53    637  970  fb           locks        slabinfo

查看某一个PID进程的文件,比如/proc/285/。其中有一个cwd,这个是进程所在的路径。比如我对于某个进程不熟悉,我就根据PID来查看这个进程是从哪执行,执行什么命令(comm文件)。

[root@lhy ~]# ls -l /proc/285/
ls: cannot read symbolic link /proc/285/exe: No such file or directory
total 0
dr-xr-xr-x. 2 root root 0 Jun  2 23:57 attr
-rw-r--r--. 1 root root 0 Jun  2 23:57 autogroup
-r--------. 1 root root 0 Jun  2 23:57 auxv
-r--r--r--. 1 root root 0 Jun  2 23:57 cgroup
--w-------. 1 root root 0 Jun  2 23:57 clear_refs
-r--r--r--. 1 root root 0 Jun  2 23:36 cmdline
-rw-r--r--. 1 root root 0 Jun  2 23:57 comm
-rw-r--r--. 1 root root 0 Jun  2 23:57 coredump_filter
-r--r--r--. 1 root root 0 Jun  2 23:57 cpuset
lrwxrwxrwx. 1 root root 0 Jun  2 23:57 cwd -> /
-r--------. 1 root root 0 Jun  2 23:57 environ
lrwxrwxrwx. 1 root root 0 Jun  2 23:57 exe
dr-x------. 2 root root 0 Jun  2 23:57 fd
dr-x------. 2 root root 0 Jun  2 23:57 fdinfo
-rw-r--r--. 1 root root 0 Jun  2 23:57 gid_map
-r--------. 1 root root 0 Jun  2 23:57 io
-r--r--r--. 1 root root 0 Jun  2 23:57 limits
-rw-r--r--. 1 root root 0 Jun  2 23:57 loginuid
dr-x------. 2 root root 0 Jun  2 23:57 map_files
-r--r--r--. 1 root root 0 Jun  2 23:57 maps
-rw-------. 1 root root 0 Jun  2 23:57 mem
-r--r--r--. 1 root root 0 Jun  2 23:57 mountinfo
-r--r--r--. 1 root root 0 Jun  2 23:57 mounts
-r--------. 1 root root 0 Jun  2 23:57 mountstats
dr-xr-xr-x. 5 root root 0 Jun  2 23:57 net
dr-x--x--x. 2 root root 0 Jun  2 23:57 ns
-r--r--r--. 1 root root 0 Jun  2 23:57 numa_maps
-rw-r--r--. 1 root root 0 Jun  2 23:57 oom_adj
-r--r--r--. 1 root root 0 Jun  2 23:57 oom_score
-rw-r--r--. 1 root root 0 Jun  2 23:57 oom_score_adj
-r--r--r--. 1 root root 0 Jun  2 23:57 pagemap
-r--r--r--. 1 root root 0 Jun  2 23:57 personality
-rw-r--r--. 1 root root 0 Jun  2 23:57 projid_map
lrwxrwxrwx. 1 root root 0 Jun  2 23:57 root -> /
-rw-r--r--. 1 root root 0 Jun  2 23:57 sched
-r--r--r--. 1 root root 0 Jun  2 23:57 schedstat
-r--r--r--. 1 root root 0 Jun  2 23:57 sessionid
-rw-r--r--. 1 root root 0 Jun  2 23:57 setgroups
-r--r--r--. 1 root root 0 Jun  2 23:57 smaps
-r--r--r--. 1 root root 0 Jun  2 23:57 stack
-r--r--r--. 1 root root 0 Jun  2 23:57 stat
-r--r--r--. 1 root root 0 Jun  2 23:57 statm
-r--r--r--. 1 root root 0 Jun  2 23:36 status
-r--r--r--. 1 root root 0 Jun  2 23:57 syscall
dr-xr-xr-x. 3 root root 0 Jun  2 23:57 task
-r--r--r--. 1 root root 0 Jun  2 23:57 timers
-rw-r--r--. 1 root root 0 Jun  2 23:57 uid_map
-r--r--r--. 1 root root 0 Jun  2 23:57 wchan

/run/是进程产生的临时文件,关机就会消失。

[root@lhy ~]# ls /run/
auditd.pid  cron.reboot  firewalld  log        NetworkManager  setrans   syslogd.pid  tuned  utmp
console     dbus         initramfs  mount      plymouth        sshd.pid  systemd      udev   vmware
crond.pid   faillock     lock       netreport  sepermit        sudo      tmpfiles.d   user   xtables.lock

/srv/文件夹默认是空的,存系统服务产生的一些文件。

/sys/存系统内核相关的文件,一般我们不去修改它们。

/tmp/是临时文件夹,任何用户都可以向其中添加文件,权限宽泛,但是普通用户之间的文件自己管理,有特殊权限,之后会讲。

/usr/是系统用户的目录,类似于根目录。

/var/目录存储的日志文件。比如系统日志存在/var/log/messages里面。

2.3 ls命令

ls命令可以列出当前目录的文件和文件夹,这是一个非常常用的一个命令,下面会介绍一下其常用参数。

列出文件的详细信息,使用参数-l

[root@lhy ~]# ls -l
total 4
-rw-------. 1 root root 1622 May 29 14:05 anaconda-ks.cfg
drwxr-xr-x. 2 root root   40 May 29 14:04 openscap_data

第一列是文件类型与权限,第二列表示有多少文件使用了相同的inode,inode记录的是这个文件的存储位置。inode指向的是固定的一个存储块,如果两个文件inode号相同,那么它们存储的位置就是相同的,这个和后续的硬链接有关,暂且不表。第三列表示所有者,第四列表示所属组。第五列是文件大小,单位是Byte。后面就是创建时间和文件名。

查看某一文件的inode使用-i参数。

[root@lhy ~]# ls -i anaconda-ks.cfg 
67145602 anaconda-ks.cfg

使用-h可以更人性化的查看文件大小。

[root@lhy ~]# ls -lh
total 4.0K
-rw-------. 1 root root 1.6K May 29 14:05 anaconda-ks.cfg
drwxr-xr-x. 2 root root   40 May 29 14:04 openscap_data

使用-a可以查看所有文件,包括隐藏文件、隐藏目录。

[root@lhy ~]# ls -la
total 36
dr-xr-x---.  4 root root  184 Jun  1 11:53 .
dr-xr-xr-x. 17 root root  245 May 31 15:43 ..
-rw-------.  1 root root 1622 May 29 14:05 anaconda-ks.cfg
-rw-------.  1 root root 3206 Jun  1 13:52 .bash_history
-rw-r--r--.  1 root root   18 Dec 29  2013 .bash_logout
-rw-r--r--.  1 root root  176 Dec 29  2013 .bash_profile
-rw-r--r--.  1 root root  176 Dec 29  2013 .bashrc
-rw-r--r--.  1 root root  100 Dec 29  2013 .cshrc
drwxr-xr-x.  2 root root   40 May 29 14:04 openscap_data
drwx------.  2 root root   80 May 31 16:47 .ssh
-rw-r--r--.  1 root root  129 Dec 29  2013 .tcshrc
-rw-------.  1 root root 6877 Jun  1 11:53 .viminfo

每个目录下面都会有两个目录叫做当前目录(./)上一级目录(../),下面显示的就是为什么/root/的inode是4,因为有四个相同的目录指向同一个位置。一般来说对于目录来说,这个inode的个数和其下子目录数相同。

[root@lhy ~]# ls -i /root/
 67145602 anaconda-ks.cfg  101110119 openscap_data
[root@lhy ~]# ls -i .
 67145602 anaconda-ks.cfg  101110119 openscap_data
[root@lhy ~]# ls -i .ssh/..
 67145602 anaconda-ks.cfg  101110119 openscap_data
[root@lhy ~]# ls -i openscap_data/..
 67145602 anaconda-ks.cfg  101110119 openscap_data


[root@lhy ~]# ls -ld /root
dr-xr-x---. 4 root root 184 Jun  1 11:53 /root
[root@lhy ~]# ls -a /root
.   anaconda-ks.cfg  .bash_logout   .bashrc  openscap_data  .tcshrc
..  .bash_history    .bash_profile  .cshrc   .ssh           .viminfo

使用-t选项可以按照时间降序排列。

[root@lhy ~]# ls -lt ..
total 20
drwxrwxrwt.  11 root root 4096 Jun  3 03:10 tmp
drwxr-xr-x.  22 root root  580 Jun  2 23:55 run
drwxr-xr-x.   3 root root   19 Jun  2 23:49 home
drwxr-xr-x.  76 root root 8192 Jun  2 23:49 etc
drwxr-xr-x.  19 root root 3260 Jun  2 23:36 dev
dr-xr-xr-x.  13 root root    0 Jun  2 23:36 sys
dr-xr-xr-x. 178 root root    0 Jun  2 23:36 proc
dr-xr-x---.   4 root root  184 Jun  1 11:53 root
dr-xr-xr-x.   5 root root 4096 May 29 14:21 boot
drwxr-xr-x.  19 root root  267 May 29 14:21 var
drwxr-xr-x.  13 root root  155 May 29 14:01 usr
lrwxrwxrwx.   1 root root    9 May 29 14:01 lib64 -> usr/lib64
lrwxrwxrwx.   1 root root    8 May 29 14:01 sbin -> usr/sbin
lrwxrwxrwx.   1 root root    7 May 29 14:01 lib -> usr/lib
lrwxrwxrwx.   1 root root    7 May 29 14:01 bin -> usr/bin
drwxr-xr-x.   2 root root    6 Nov  5  2016 media
drwxr-xr-x.   2 root root    6 Nov  5  2016 mnt
drwxr-xr-x.   2 root root    6 Nov  5  2016 opt
drwxr-xr-x.   2 root root    6 Nov  5  2016 srv

使用-d选项仅显示目录,不显示其他。

[root@lhy ~]# ls -ld /
dr-xr-xr-x. 17 root root 245 May 31 15:43 /
[root@lhy ~]# ls -lt /
total 20
drwxrwxrwt.  11 root root 4096 Jun  3 03:10 tmp
drwxr-xr-x.  22 root root  580 Jun  2 23:55 run
drwxr-xr-x.   3 root root   19 Jun  2 23:49 home
drwxr-xr-x.  76 root root 8192 Jun  2 23:49 etc
drwxr-xr-x.  19 root root 3260 Jun  2 23:36 dev
dr-xr-xr-x.  13 root root    0 Jun  2 23:36 sys
dr-xr-xr-x. 178 root root    0 Jun  2 23:36 proc
dr-xr-x---.   4 root root  184 Jun  1 11:53 root
dr-xr-xr-x.   5 root root 4096 May 29 14:21 boot
drwxr-xr-x.  19 root root  267 May 29 14:21 var
drwxr-xr-x.  13 root root  155 May 29 14:01 usr
lrwxrwxrwx.   1 root root    9 May 29 14:01 lib64 -> usr/lib64
lrwxrwxrwx.   1 root root    8 May 29 14:01 sbin -> usr/sbin
lrwxrwxrwx.   1 root root    7 May 29 14:01 lib -> usr/lib
lrwxrwxrwx.   1 root root    7 May 29 14:01 bin -> usr/bin
drwxr-xr-x.   2 root root    6 Nov  5  2016 media
drwxr-xr-x.   2 root root    6 Nov  5  2016 mnt
drwxr-xr-x.   2 root root    6 Nov  5  2016 opt
drwxr-xr-x.   2 root root    6 Nov  5  2016 srv

之前也提过,使用man命令可以查看ls的所有参数,我们只需要记住常用的,按需查询即可。

最后,使用别名可以方便输入命令,比如给目录自动添加颜色需要--color=auto的参数,而想只需要ls就能实现,这个会在2.5节讲到。

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

2.4 文件类型

上一小节讲到使用ls -l查看文件的时候第一列显示的是文件的类型与权限。文件类型就是第一个字符表示的。

[root@lhy ~]# ls -la
total 36
dr-xr-x---.  4 root root  184 Jun  1 11:53 .
dr-xr-xr-x. 17 root root  245 May 31 15:43 ..
-rw-------.  1 root root 1622 May 29 14:05 anaconda-ks.cfg
drwxr-xr-x.  2 root root   40 May 29 14:04 openscap_data
drwx------.  2 root root   80 May 31 16:47 .ssh
-rw-------.  1 root root 6877 Jun  1 11:53 .viminfo

d表示这个“文件“是一个目录。’-‘表示这个”文件“是普通文本文档。不管是普通文本文档还是二进制文件,都会显示为’-‘ 。

c表示字符串设备。

[root@lhy ~]# ls -l /dev/tty0 
crw--w----. 1 root tty 4, 0 Jun  2 23:36 /dev/tty0

l表示软连接文件,相当于Windows的快捷方式

[root@lhy ~]# ls -l /dev/stderr 
lrwxrwxrwx. 1 root root 15 Jun  2 23:36 /dev/stderr -> /proc/self/fd/2

b表示块设备,比如光盘,硬盘等。

[root@lhy ~]# ls -l /dev/sda*
brw-rw----. 1 root disk 8, 0 Jun  2 23:36 /dev/sda
brw-rw----. 1 root disk 8, 1 Jun  2 23:36 /dev/sda1
brw-rw----. 1 root disk 8, 2 Jun  2 23:36 /dev/sda2
brw-rw----. 1 root disk 8, 3 Jun  2 23:36 /dev/sda3

s表示socket文件,用于进程、服务之间通信所用的文件。

[root@lhy ~]# ls -l /dev/log
srw-rw-rw-. 1 root root           0 Jun  2 23:36 log

2.5 alias命令

ls和ll命令其实都是有别名的,我们可以用alias命令查看。

[root@lhy ~]# alias ls
alias ls='ls --color=auto'
[root@lhy ~]# alias ll
alias ll='ls -l --color=auto'
[root@lhy ~]# alias yum
-bash: alias: yum: not found
[root@lhy ~]# alias which
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

如果存在别名就会显示别名,如果不存在会返回not found。我们发现which的别名中就有alias命令,所以查看一个命令来源可以直接使用which命令。

如果想看所有的有别名命令,直接使用alias即可。

[root@lhy ~]# 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'

不希望使用别名而想直接应用命令,使用绝对路径即可。

[root@lhy ~]# /bin/ls .
anaconda-ks.cfg  openscap_data

下面介绍一个系统的环境变量PATH

[root@lhy ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

可以看到PATH中使用:分割了很多文件目录,只要是在这些目录里的可执行文件都可以直接输入文件名而执行,which查询命令就是在PATH中查询的。

现在,我们创建一个别名aming,比如让它变为ls -lha,使用如下方法

[root@lhy ~]# alias aming='ls -lha'
[root@lhy ~]# aming
total 36K
dr-xr-x---.  4 root root  184 Jun  1 11:53 .
dr-xr-xr-x. 17 root root  245 May 31 15:43 ..
-rw-------.  1 root root 1.6K May 29 14:05 anaconda-ks.cfg
-rw-------.  1 root root 3.2K Jun  1 13:52 .bash_history
-rw-r--r--.  1 root root   18 Dec 29  2013 .bash_logout
-rw-r--r--.  1 root root  176 Dec 29  2013 .bash_profile
-rw-r--r--.  1 root root  176 Dec 29  2013 .bashrc
-rw-r--r--.  1 root root  100 Dec 29  2013 .cshrc
drwxr-xr-x.  2 root root   40 May 29 14:04 openscap_data
drwx------.  2 root root   80 May 31 16:47 .ssh
-rw-r--r--.  1 root root  129 Dec 29  2013 .tcshrc
-rw-------.  1 root root 6.8K Jun  1 11:53 .viminfo
[root@lhy ~]# which aming
alias aming='ls -lha'
    /usr/bin/ls

取消别名的方法也很简单,使用unalias + 别名 即可。

[root@lhy ~]# unalias aming
[root@lhy ~]# aming
-bash: aming: command not found
点赞
收藏
评论区
推荐文章
blmius blmius
3年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
待兔 待兔
5个月前
手写Java HashMap源码
HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22
Jacquelyn38 Jacquelyn38
3年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
Easter79 Easter79
3年前
Twitter的分布式自增ID算法snowflake (Java版)
概述分布式系统中,有一些需要使用全局唯一ID的场景,这种时候为了防止ID冲突可以使用36位的UUID,但是UUID有一些缺点,首先他相对比较长,另外UUID一般是无序的。有些时候我们希望能使用一种简单一些的ID,并且希望ID能够按照时间有序生成。而twitter的snowflake解决了这种需求,最初Twitter把存储系统从MySQL迁移
Wesley13 Wesley13
3年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Wesley13 Wesley13
3年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Stella981 Stella981
3年前
Django中Admin中的一些参数配置
设置在列表中显示的字段,id为django模型默认的主键list_display('id','name','sex','profession','email','qq','phone','status','create_time')设置在列表可编辑字段list_editable
Wesley13 Wesley13
3年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
11个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这