2.1/2.2 系统目录结构
ls命令可以列写目录,可以看一下根目录下的内容。
1[root@lhy ~]# ls / 2bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root用户的家目录就在/root/
1[root@lhy ~]# ls /root 2anaconda-ks.cfg openscap_data
家目录用于存储用户的配置文件和普通文件,比如
1[root@lhy ~]# ls /root/.ssh/authorized_keys 2/root/.ssh/authorized_keys
如果我希望通过ssh连接一个普通的非root用户,那么就需要把这个配置文件(公钥)放置在对应用户的家目录里(/etc/ssh/sshd_config文件规定的)。比如,新建一个用户lhy01,这个配置文件就需要放置在/home/lhy01/下,这个目录在创建用户时候会自动创建。
1[root@lhy ~]# useradd lhy01 2[root@lhy ~]# ls /home/ 3lhy01 4[root@lhy ~]# ls /home/lhy01/ -a 5. .. .bash_logout .bash_profile .bashrc
想查看一个目录有什么子目录,可以用tree命令。如果没有安装可以用yum安装。
1[root@lhy ~]# yum install tree -y 2Loaded plugins: fastestmirror 3base | 3.6 kB 00:00:00 4extras | 3.4 kB 00:00:00 5updates | 3.4 kB 00:00:00 6(1/2): extras/7/x86_64/primary_db | 147 kB 00:00:00 7(2/2): updates/7/x86_64/primary_db | 2.0 MB 00:00:00 8Loading mirror speeds from cached hostfile 9 * base: mirrors.huaweicloud.com 10 * extras: mirrors.163.com 11 * updates: mirrors.huaweicloud.com 12Resolving Dependencies 13--> Running transaction check 14---> Package tree.x86_64 0:1.6.0-10.el7 will be installed 15--> Finished Dependency Resolution 16 17Dependencies Resolved 18 19=========================================================================================================================== 20 Package Arch Version Repository Size 21=========================================================================================================================== 22Installing: 23 tree x86_64 1.6.0-10.el7 base 46 k 24 25Transaction Summary 26=========================================================================================================================== 27Install 1 Package 28 29Total download size: 46 k 30Installed size: 87 k 31Downloading packages: 32tree-1.6.0-10.el7.x86_64.rpm | 46 kB 00:00:00 33Running transaction check 34Running transaction test 35Transaction test succeeded 36Running transaction 37 Installing : tree-1.6.0-10.el7.x86_64 1/1 38 Verifying : tree-1.6.0-10.el7.x86_64 1/1 39 40Installed: 41 tree.x86_64 0:1.6.0-10.el7 42 43Complete!
tree可以简单的可以显示一个文档
tree /
但是由于文件过于多,可能突破Xshell的ScrollBack上限。我们用参数来显示两层目录。查看tree的用法有两种,一种是用tree本身来看,另一种是用Manual Page命令。
1[root@lhy ~]# tree --help 2usage: tree [-acdfghilnpqrstuvxACDFQNSUX] [-H baseHREF] [-T title ] [-L level [-R]] 3 [-P pattern] [-I pattern] [-o filename] [--version] [--help] [--inodes] 4 [--device] [--noreport] [--nolinks] [--dirsfirst] [--charset charset] 5 [--filelimit[=]#] [--si] [--timefmt[=]<f>] [<directory list>] 6 ------- Listing options ------- 7 -a All files are listed. 8 -d List directories only. 9 -l Follow symbolic links like directories. 10 -f Print the full path prefix for each file. 11 -x Stay on current filesystem only. 12 -L level Descend only level directories deep. 13 -R Rerun tree when max dir level reached. 14 -P pattern List only those files that match the pattern given. 15 -I pattern Do not list files that match the given pattern. 16 --noreport Turn off file/directory count at end of tree listing. 17 --charset X Use charset X for terminal/HTML and indentation line output. 18 --filelimit # Do not descend dirs with more than # files in them. 19 --timefmt <f> Print and format time according to the format <f>. 20 -o filename Output to file instead of stdout. 21 --du Print directory sizes. 22 --prune Prune empty directories from the output. 23 -------- File options --------- 24 -q Print non-printable characters as '?'. 25 -N Print non-printable characters as is. 26 -Q Quote filenames with double quotes. 27 -p Print the protections for each file. 28 -u Displays file owner or UID number. 29 -g Displays file group owner or GID number. 30 -s Print the size in bytes of each file. 31 -h Print the size in a more human readable way. 32 --si Like -h, but use in SI units (powers of 1000). 33 -D Print the date of last modification or (-c) status change. 34 -F Appends '/', '=', '*', '@', '|' or '>' as per ls -F. 35 --inodes Print inode number of each file. 36 --device Print device ID number to which each file belongs. 37 ------- Sorting options ------- 38 -v Sort files alphanumerically by version. 39 -r Sort files in reverse alphanumeric order. 40 -t Sort files by last modification time. 41 -c Sort files by last status change time. 42 -U Leave files unsorted. 43 --dirsfirst List directories before files (-U disables). 44 ------- Graphics options ------ 45 -i Don't print indentation lines. 46 -A Print ANSI lines graphic indentation lines. 47 -S Print with ASCII graphics indentation lines. 48 -n Turn colorization off always (-C overrides). 49 -C Turn colorization on always. 50 ------- XML/HTML options ------- 51 -X Prints out an XML representation of the tree. 52 -H baseHREF Prints out HTML format with baseHREF as top directory. 53 -T string Replace the default HTML title and H1 header with string. 54 --nolinks Turn off hyperlinks in HTML output. 55 ---- Miscellaneous options ---- 56 --version Print version and exit. 57 --help Print usage and this help message and exit. 58 59 60[root@lhy ~]# man tree 61 62TREE(1) General Commands Manual TREE(1) 63 64NAME 65 tree - list contents of directories in a tree-like format. 66 67SYNOPSIS 68 tree [-acdfghilnpqrstuvxACDFQNSUX] [-L level [-R]] [-H baseHREF] [-T title] [-o filename] [--nolinks] [-P pat‐ 69 tern] [-I pattern] [--inodes] [--device] [--noreport] [--dirsfirst] [--version] [--help] [--filelimit #] [--si] 70 [--prune] [--du] [--timefmt format] [directory ...] 71 72DESCRIPTION 73 Tree is a recursive directory listing program that produces a depth indented listing of files, which is col‐ 74 orized ala dircolors if the LS_COLORS environment variable is set and output is to tty. With no arguments, tree 75 lists the files in the current directory. When directory arguments are given, tree lists all the files and/or 76 directories found in the given directories each in turn. Upon completion of listing all files/directories 77 found, tree returns the total number of files and/or directories listed. 78 79 By default, when a symbolic link is encountered, the path that the symbolic link refers to is printed after the 80 name of the link in the format: 81 82 name -> real-path 83 84 If the `-l' option is given and the symbolic link refers to an actual directory, then tree will follow the path 85 of the symbolic link as if it were a real directory. 86 87OPTIONS 88 Tree understands the following command line switches: 89 90LISTING OPTIONS 91 -a All files are printed. By default tree does not print hidden files (those beginning with a dot `.'). In 92 no event does tree print the file system constructs `.' (current directory) and `..' (previous direc‐ 93 tory). 94 95 -d List directories only. 96 97 -l Follows symbolic links if they point to directories, as if they were directories. Symbolic links that 98 will result in recursion are avoided when detected. 99 100 -f Prints the full path prefix for each file. 101 102 -x Stay on the current file-system only. Ala find -xdev. 103 104 -L level 105 Max display depth of the directory tree. 106 107 -R Recursively cross down the tree each level directories (see -L option), and at each of them execute tree 108 again adding `-o 00Tree.html' as a new option. 109 110 -P pattern 111 List only those files that match the wild-card pattern. Note: you must use the -a option to also con‐ 112 sider those files beginning with a dot `.' for matching. Valid wildcard operators are `*' (any zero or 113 more characters), `?' (any single character), `[...]' (any single character listed between brackets 114 (optional - (dash) for character range may be used: ex: [A-Z]), and `[^...]' (any single character not 115 listed in brackets) and `|' separates alternate patterns. 116 117 -I pattern 118 Do not list those files that match the wild-card pattern. 119 120 --prune 121 Makes tree prune empty directories from the output, useful when used in conjunction with -P or -I. See 122 BUGS AND NOTES below for more information on this option. 123 124 --noreport 125 Omits printing of the file and directory report at the end of the tree listing. 126 127 --charset charset 128 Set the character set to use when outputting HTML and for line drawing. 129 130 --filelimit # 131 Do not descend directories that contain more than # entries. 132 133 134 --timefmt format 135 Prints (implies -D) and formats the date according to the format string which uses the strftime(3) syn‐ 136 tax. 137 138 -o filename 139 Send output to filename. 140 141FILE OPTIONS 142 -q Print non-printable characters in filenames as question marks instead of the default. 143 144 -N Print non-printable characters as is instead of as escaped octal numbers. 145 146 -Q Quote the names of files in double quotes. 147 148 -p Print the file type and permissions for each file (as per ls -l). 149 150 -u Print the username, or UID # if no username is available, of the file. 151 152 -g Print the group name, or GID # if no group name is available, of the file. 153 154 -s Print the size of each file in bytes along with the name. 155 156 -h Print the size of each file but in a more human readable way, e.g. appending a size letter for kilobytes 157 (K), megabytes (M), gigabytes (G), terabytes (T), petabytes (P) and exabytes (E). 158 159 --si Like -h but use SI units (powers of 1000) instead. 160 161 --du For each directory report its size as the accumulation of sizes of all its files and sub-directories (and 162 their files, and so on). The total amount of used space is also given in the final report (like the 'du 163 -c' command.) This option requires tree to read the entire directory tree before emitting it, see BUGS 164 AND NOTES below. Implies -s. 165 166 -D Print the date of the last modification time or if -c is used, the last status change time for the file 167 listed. 168 169 -F Append a `/' for directories, a `=' for socket files, a `*' for executable files, a `>' for doors 170 (Solaris) and a `|' for FIFO's, as per ls -F 171 172 -F Append a `/' for directories, a `=' for socket files, a `*' for executable files, a `>' for doors 173 (Solaris) and a `|' for FIFO's, as per ls -F 174 175 --inodes 176 Prints the inode number of the file or directory 177 178 --device 179 Prints the device number to which the file or directory belongs 180 181SORTING OPTIONS 182 -v Sort the output by version. 183 184 -r Sort the output in reverse alphabetic order. 185 186 -t Sort the output by last modification time instead of alphabetically. 187 188 -c Sort the output by last status change instead of alphabetically. Modifies the -D option (if used) to 189 print the last status change instead of modification time. 190 191 -U Do not sort. Lists files in directory order. Disables --dirsfirst. 192 193 --dirsfirst 194 List directories before files. This is a meta-sort that alters the above sorts. This option is disabled 195 when -U is used. 196 197GRAPHICS OPTIONS 198 -i Makes tree not print the indentation lines, useful when used in conjunction with the -f option. 199 200 -A Turn on ANSI line graphics hack when printing the indentation lines. 201 202 -S Turn on ASCII line graphics (useful when using Linux console mode fonts). This option is now equivalent 203 to `--charset=IBM437' and may eventually be depreciated. 204 205 -n Turn colorization off always, over-ridden by the -C option. 206 207 -C Turn colorization on always, using built-in color defaults if the LS_COLORS environment variable is not 208 set. Useful to colorize output to a pipe. 209 210XML/HTML OPTIONS 211 -X Turn on XML output. Outputs the directory tree as an XML formatted file. 212 213 -H baseHREF 214 Turn on HTML output, including HTTP references. Useful for ftp sites. baseHREF gives the base ftp loca‐ 215 tion when using HTML output. That is, the local directory may be `/local/ftp/pub', but it must be refer‐ 216 enced as `ftp://hostname.organization.domain/pub' (baseHREF should be `ftp://hostname.organiza‐ 217 tion.domain'). Hint: don't use ANSI lines with this option, and don't give more than one directory in the 218 directory list. If you wish to use colors via CCS style-sheet, use the -C option in addition to this 219 option to force color output. 220 221 -T title 222 Sets the title and H1 header string in HTML output mode. 223 224 --nolinks 225 Turns off hyperlinks in HTML output. 226 227MISC OPTIONS 228 --help Outputs a verbose usage listing. 229 230 --version 231 Outputs the version of tree. 232 233FILES 234 /etc/DIR_COLORS System color database. 235 ~/.dircolors Users color database. 236 237 238ENVIRONMENT 239 LS_COLORS Color information created by dircolors 240 TREE_COLORS Uses this for color information over LS_COLORS if it is set. 241 TREE_CHARSET Character set for tree to use in HTML mode. 242 LC_CTYPE Locale for filename output. 243 LC_TIME Locale for timefmt output, see strftime(3). 244 TZ Timezone for timefmt output, see strftime(3). 245 246AUTHOR 247 Steve Baker (ice@mama.indstate.edu) 248 HTML output hacked by Francesc Rocher (rocher@econ.udg.es) 249 Charsets and OS/2 support by Kyosuke Tokoro (NBG01720@nifty.ne.jp) 250 251BUGS AND NOTES 252 Tree does not prune "empty" directories when the -P and -I options are used by default. Use the --prune option. 253 254 The -h and --si options round to the nearest whole number unlike the ls implementations which rounds up always. 255 256 Pruning files and directories with the -I, -P and --filelimit options will lead to incorrect file/directory 257 count reports. 258 259 The --prune and --du options cause tree to accumulate the entire tree in memory before emitting it. For large 260 directory trees this can cause a significant delay in output and the use of large amounts of memory. 261 262 The timefmt expansion buffer is limited to a ridiculously large 255 characters. Output of time strings longer 263 than this will be undefined, but are guaranteed to not exceed 255 characters. 264 265 XML trees are not colored, which is a bit of a shame. 266 267 Probably more. 268 269SEE ALSO 270 dircolors(1), ls(1), find(1), du(1), strftime(3) 271 272Tree 1.6.0 273 274 Manual page tree(1) line 1 (press h for help or q to quit)
可以看到用-L参数可以设置最深搜索层数,-d只显示文件夹。
1[root@lhy ~]# tree / -L 2 -d 2/ 3├── bin -> usr/bin 4├── boot 5│ ├── efi 6│ ├── grub 7│ └── grub2 8├── dev 9│ ├── block 10│ ├── bsg 11│ ├── bus 12│ ├── char 13│ ├── cpu 14│ ├── disk 15│ ├── dri 16│ ├── fd -> /proc/self/fd 17│ ├── hugepages 18│ ├── input 19│ ├── mapper 20│ ├── mqueue 21│ ├── net 22│ ├── pts 23│ ├── raw 24│ ├── shm 25│ ├── snd 26│ └── vfio 27├── etc 28│ ├── alternatives 29│ ├── audisp 30│ ├── audit 31│ ├── bash_completion.d 32│ ├── binfmt.d 33│ ├── chkconfig.d 34│ ├── cron.d 35│ ├── cron.daily 36│ ├── cron.hourly 37│ ├── cron.monthly 38│ ├── cron.weekly 39│ ├── dbus-1 40│ ├── default 41│ ├── depmod.d 42│ ├── dhcp 43│ ├── dracut.conf.d 44│ ├── firewalld 45│ ├── gcrypt 46│ ├── gnupg 47│ ├── groff 48│ ├── grub.d 49│ ├── gss 50│ ├── init.d -> rc.d/init.d 51│ ├── iproute2 52│ ├── kernel 53│ ├── krb5.conf.d 54│ ├── ld.so.conf.d 55│ ├── libnl 56│ ├── logrotate.d 57│ ├── modprobe.d 58│ ├── modules-load.d 59│ ├── my.cnf.d 60│ ├── NetworkManager 61│ ├── openldap 62│ ├── opt 63│ ├── pam.d 64│ ├── pkcs11 65│ ├── pki 66│ ├── plymouth 67│ ├── pm 68│ ├── polkit-1 69│ ├── popt.d 70│ ├── postfix 71│ ├── ppp 72│ ├── prelink.conf.d 73│ ├── profile.d 74│ ├── python 75│ ├── rc0.d -> rc.d/rc0.d 76│ ├── rc1.d -> rc.d/rc1.d 77│ ├── rc2.d -> rc.d/rc2.d 78│ ├── rc3.d -> rc.d/rc3.d 79│ ├── rc4.d -> rc.d/rc4.d 80│ ├── rc5.d -> rc.d/rc5.d 81│ ├── rc6.d -> rc.d/rc6.d 82│ ├── rc.d 83│ ├── rpm 84│ ├── rsyslog.d 85│ ├── rwtab.d 86│ ├── sasl2 87│ ├── security 88│ ├── selinux 89│ ├── sgml 90│ ├── skel 91│ ├── ssh 92│ ├── ssl 93│ ├── statetab.d 94│ ├── sudoers.d 95│ ├── sysconfig 96│ ├── sysctl.d 97│ ├── systemd 98│ ├── terminfo 99│ ├── tmpfiles.d 100│ ├── tuned 101│ ├── udev 102│ ├── vmware-tools 103│ ├── wpa_supplicant 104│ ├── X11 105│ ├── xdg 106│ ├── xinetd.d 107│ ├── xml 108│ ├── yum 109│ └── yum.repos.d 110├── home 111│ └── lhy01 112├── lib -> usr/lib 113├── lib64 -> usr/lib64 114├── media 115├── mnt 116├── opt 117├── proc 118│ ├── 1 119│ ├── 10 120│ ├── 11 121│ ├── acpi 122│ ├── asound 123│ ├── bus 124│ ├── driver 125│ ├── fs 126│ ├── irq 127│ ├── mpt 128│ ├── net -> self/net 129│ ├── scsi 130│ ├── self -> 1879 131│ ├── sys 132│ ├── sysvipc 133│ └── tty 134├── root 135│ └── openscap_data 136├── run 137│ ├── console 138│ ├── dbus 139│ ├── faillock 140│ ├── firewalld 141│ ├── initramfs 142│ ├── lock 143│ ├── log 144│ ├── mount 145│ ├── netreport 146│ ├── NetworkManager 147│ ├── plymouth 148│ ├── sepermit 149│ ├── setrans 150│ ├── sudo 151│ ├── systemd 152│ ├── tmpfiles.d 153│ ├── tuned 154│ ├── udev 155│ ├── user 156│ └── vmware 157├── sbin -> usr/sbin 158├── srv 159├── sys 160│ ├── block 161│ ├── bus 162│ ├── class 163│ ├── dev 164│ ├── devices 165│ ├── firmware 166│ ├── fs 167│ ├── hypervisor 168│ ├── kernel 169│ ├── module 170│ └── power 171├── tmp 172│ ├── systemd-private-72a51b409754493b803ada2e9f1e8ca6-vgauthd.service-SJRZXu 173│ ├── systemd-private-72a51b409754493b803ada2e9f1e8ca6-vmtoolsd.service-Ct0xiS 174│ ├── systemd-private-b5d827de47c64188ae996c7b05c8f1b2-vgauthd.service-SHMZTz 175│ └── systemd-private-b5d827de47c64188ae996c7b05c8f1b2-vmtoolsd.service-LXMW2A 176├── usr 177│ ├── bin 178│ ├── etc 179│ ├── games 180│ ├── include 181│ ├── lib 182│ ├── lib64 183│ ├── libexec 184│ ├── local 185│ ├── sbin 186│ ├── share 187│ ├── src 188│ └── tmp -> ../var/tmp 189└── var 190 ├── adm 191 ├── cache 192 ├── crash 193 ├── db 194 ├── empty 195 ├── games 196 ├── gopher 197 ├── kerberos 198 ├── lib 199 ├── local 200 ├── lock -> ../run/lock 201 ├── log 202 ├── mail -> spool/mail 203 ├── nis 204 ├── opt 205 ├── preserve 206 ├── run -> ../run 207 ├── spool 208 ├── tmp 209 └── yp 210 211370 directories
目录/usr/bin/ /usr/sbin/ /bin/ /sbin/ 这几个目录中保存的是一系列的命令。为什么直接敲命令而不需要执行具体目录下的文件,这是因为环境变量PATH的作用,这点之后再讲。
/sbin/下的命令一般是root用户的命令,普通用户下的命令一般是/bin/下的。
1[root@lhy ~]# ls /sbin/ 2accessdb e2fsck ip nl-link-list sestatus 3addgnupghome e2image ip6tables nl-pktloc-lookup setcap 4addpart e2label ip6tables-restore nl-qdisc-add setenforce 5adduser e2undo ip6tables-save nl-qdisc-delete setfiles 6agetty e4defrag ipmaddr nl-qdisc-list setpci 7aide eapol_test iprconfig nologin setsebool 8alternatives ebtables iprdbg nstat sfdisk 9anacron ebtables-restore iprdump ownership shutdown 10applygnupgdefaults ebtables-save iprinit packer slattach 11arp ether-wake iprsos pam_console_apply sln 12arpd ethtool iprupdate pam_tally2 smtp-sink 13arping faillock ipset pam_timestamp_check smtp-source 14audispd fdformat iptables parted ss 15auditctl fdisk iptables-restore partprobe sshd 16auditd filefrag iptables-save partx sshd-keygen 17augenrules findfs iptunnel pidof sulogin 18aureport firewalld irqbalance ping6 sushell 19ausearch fixfiles kdump pivot_root swaplabel 20authconfig fsck kexec plipconfig swapoff 21authconfig-tui fsck.btrfs killall5 plymouthd swapon 22autrace fsck.cramfs kpartx plymouth-set-default-theme switch_root 23avcstat fsck.ext2 lchage postalias sysctl 24badblocks fsck.ext3 ldattach postcat sys-unconfig 25biosdecode fsck.ext4 ldconfig postconf tc 26biosdevname fsck.minix lgroupadd postdrop telinit 27blkdeactivate fsck.xfs lgroupdel postfix tracepath 28blkdiscard fsfreeze lgroupmod postkick tracepath6 29blkid fstrim lid postlock tune2fs 30blockdev fxload lnewusers postlog tuned 31bridge genhomedircon lnstat postmap tuned-adm 32btrfs genhostid load_policy postmulti udevadm 33btrfsck genl logrotate postqueue unix_chkpwd 34btrfs-convert genl-ctrl-list logsave postsuper unix_update 35btrfs-debug-tree getcap losetup poweroff update-alternatives 36btrfs-find-root getenforce lpasswd ppp-watch update-pciids 37btrfs-image getpcaps lsmod pwck useradd 38btrfs-map-logical getsebool lspci pwconv userdel 39btrfs-select-super glibc_post_upgrade.x86_64 luseradd pwhistory_helper usermod 40btrfstune groupadd luserdel pwunconv usernetctl 41btrfs-zero-log groupdel lusermod rdisc vigr 42build-locale-archive groupmems makedumpfile readprofile vipw 43cacertdir_rehash groupmod matchpathcon reboot virt-what 44capsh grpck mii-diag resize2fs visudo 45cbq grpconv mii-tool resizepart vmcore-dmesg 46cfdisk grpunconv mkdict restorecon vpddecode 47chcpu grub2-bios-setup mkdumprd rmmod weak-modules 48chkconfig grub2-get-kernel-settings mke2fs route wipefs 49chpasswd grub2-install mkfs routef wpa_cli 50chroot grub2-mkconfig mkfs.btrfs routel wpa_passphrase 51clock grub2-ofpathname mkfs.cramfs rsyslogd wpa_supplicant 52clockdiff grub2-probe mkfs.ext2 rtacct xfs_admin 53consoletype grub2-reboot mkfs.ext3 rtcwake xfs_bmap 54cracklib-check grub2-rpm-sort mkfs.ext4 rtmon xfs_copy 55cracklib-format grub2-set-default mkfs.minix rtpr xfs_db 56cracklib-packer grub2-setpassword mkfs.xfs rtstat xfs_estimate 57cracklib-unpacker grub2-sparc64-setup mkhomedir_helper runlevel xfs_freeze 58create-cracklib-dict grubby mklost+found runuser xfs_fsr 59crond halt mkswap sasldblistusers2 xfs_growfs 60ctrlaltdel hardlink modinfo saslpasswd2 xfs_info 61ctstat hwclock modprobe sefcontext_compile xfs_io 62debugfs iconvconfig mount.fuse selabel_digest xfs_logprint 63delpart iconvconfig.x86_64 nameif selabel_lookup xfs_mdrestore 64depmod ifcfg netreport selabel_lookup_best_match xfs_metadump 65devlink ifconfig NetworkManager selabel_partial_match xfs_mkfile 66dhclient ifdown new-kernel-pkg selinuxconlist xfs_ncheck 67dhclient-script ifenslave newusers selinuxdefcon xfs_quota 68dmfilemapd ifstat nl-class-add selinuxenabled xfs_repair 69dmidecode ifup nl-class-delete selinuxexeccon xfs_rtcp 70dmsetup init nl-classid-lookup selinux_restorecon xtables-multi 71dmstats insmod nl-class-list semodule zdump 72dracut install-info nl-cls-add sendmail zic 73dumpe2fs installkernel nl-cls-delete sendmail.postfix zramctl 74e2freefrag intel-microcode2ucode nl-cls-list service 75[root@lhy ~]# ls /bin/ 76[ groups nl-link-set sotruss 77a2p grub2-editenv nl-link-stats splain 78addr2line grub2-file nl-list-caches split 79alias grub2-fstest nl-list-sockets sprof 80apropos grub2-glue-efi nl-monitor sqlite3 81ar grub2-kbdcomp nl-neigh-add ssh 82arch grub2-menulst2cfg nl-neigh-delete ssh-add 83as grub2-mkfont nl-neigh-list ssh-agent 84aserver grub2-mkimage nl-neightbl-list ssh-copy-id 85aulast grub2-mklayout nl-pktloc-lookup ssh-keygen 86aulastlog grub2-mknetdir nl-qdisc-add ssh-keyscan 87ausyscall grub2-mkpasswd-pbkdf2 nl-qdisc-delete ssltap 88auvirt grub2-mkrelpath nl-qdisc-list stat 89awk grub2-mkrescue nl-route-add stdbuf 90base64 grub2-mkstandalone nl-route-delete strings 91basename grub2-script-check nl-route-get strip 92bash grub2-syslinux2cfg nl-route-list stty 93bashbug gsettings nl-rule-list su 94bashbug-64 gsoelim nl-tctree-list sudo 95bg gtar nl-util-addr sudoedit 96bond2team gtbl nm sudoreplay 97bootctl gtroff nmcli sum 98busctl gunzip nm-online sync 99c2ph gzexe nmtui systemctl 100cal gzip nmtui-connect systemd-analyze 101ca-legacy h2ph nmtui-edit systemd-ask-password 102captoinfo hdsploader nmtui-hostname systemd-cat 103cat head nohup systemd-cgls 104catchsegv hexdump nproc systemd-cgtop 105catman hostid nroff systemd-coredumpctl 106cd hostname nsenter systemd-delta 107centrino-decode hostnamectl numfmt systemd-detect-virt 108certutil i386 objcopy systemd-escape 109c++filt iconv objdump systemd-firstboot 110chacl id od systemd-hwdb 111chage idiag-socket-details oldfind systemd-inhibit 112chattr idn open systemd-loginctl 113chcon igawk openssl systemd-machine-id-setup 114chfn info openvt systemd-notify 115chgrp infocmp oscap systemd-nspawn 116chmod infokey os-prober systemd-path 117chown infotocap p11-kit systemd-run 118chrt install passwd systemd-stdio-bridge 119chsh ionice paste systemd-sysv-convert 120chvt ipcalc pathchk systemd-tmpfiles 121cksum ipcmk pchrt systemd-tty-ask-password-agent 122clear ipcrm perl tabs 123cmp ipcs perl5.16.3 tac 124cmsutil iptables-xml perlbug tail 125col isosize perldoc tailf 126colcrt jobs perlthanks tar 127colrm join pflags taskset 128column journalctl pgawk tbl 129comm kbdinfo pgrep teamd 130command kbd_mode pic teamdctl 131coredumpctl kbdrate piconv teamnl 132cp kdumpctl pinentry tee 133cpio kernel-install pinentry-curses test 134cpupower kill ping testgdbm 135crlutil kmod ping6 tic 136crontab last pinky timedatectl 137csplit lastb pk12util timeout 138csslint-0.6 lastlog pkaction tload 139curl lchfn pkcheck tmon 140cut lchsh pkexec toe 141date ld pkg-config top 142db_archive ld.bfd pkill touch 143db_checkpoint ldd pkla-admin-identities tput 144db_deadlock ld.gold pkla-check-authorization tr 145db_dump less pkttyagent tracepath 146db_dump185 lessecho pl2pm tracepath6 147db_hotbackup lesskey pldd tree 148db_load lesspipe.sh plymouth troff 149db_log_verify lexgrog pmap true 150db_printlog link pod2html truncate 151db_recover linux32 pod2man trust 152db_replicate linux64 pod2text tset 153db_stat linux-boot-prober pod2usage tsort 154db_tuner ln post-grohtml tty 155db_upgrade loadkeys powernow-k8-decode turbostat 156dbus-binding-tool loadunimap pr tzselect 157dbus-cleanup-sockets locale preconv udevadm 158dbus-daemon localectl pre-grohtml ul 159dbus-monitor localedef printenv ulockmgr_server 160dbus-send logger printf umask 161dbus-uuidgen login prlimit umount 162db_verify loginctl ps unalias 163dd logname psed uname 164deallocvt look psfaddtable unexpand 165df ls psfgettable unicode_start 166dgawk lsattr psfstriptable unicode_stop 167diff lsblk psfxtable uniq 168diff3 lscpu pstruct unlink 169dir lsinitrd ptaskset unshare 170dircolors lsipc ptx unxz 171dirname lslocks pwd update-ca-trust 172dmesg lslogins pwdx update-mime-database 173dnsdomainname lsns pwmake uptime 174domainname lsscsi pwscore urlgrabber 175dracut lua pydoc users 176du luac python usleep 177dumpkeys machinectl python2 usx2yloader 178dwp mailq python2.7 utmpdump 179echo mailq.postfix ranlib uuidgen 180egrep make raw vdir 181eject makedb read VGAuthService 182elfedit man readelf vi 183env mandb readlink view 184envsubst manpath realpath vim 185eqn mapscrn recode-sr-latin vimdiff 186ex mcookie rename vimtutor 187expand md5sum renice vlock 188expr mesg reset vmhgfs-fuse 189factor mixartloader resizecons vmstat 190fallocate mkdir rev vm-support 191false mkfifo rm vmtoolsd 192fc mkinitrd rmail vmware-checkvm 193fg mknod rmail.postfix vmware-guestproxycerttool 194fgconsole mktemp rmdir vmware-hgfsclient 195fgrep modutil rpcgen vmware-namespace-cmd 196file more rpm vmware-rpctool 197find mount rpm2cpio vmware-toolbox-cmd 198find2perl mountpoint rpmdb vmware-vgauth-cmd 199findmnt msgattrib rpmkeys vmware-xferlogs 200fipscheck msgcat rpmquery vxloader 201fipshmac msgcmp rpmverify w 202firewall-cmd msgcomm rsyslog-recover-qi.pl wait 203firewall-offline-cmd msgconv runcon wall 204flock msgen run-parts watch 205fmt msgexec rvi watchgnupg 206fold msgfilter rview wc 207free msgfmt rvim wdctl 208fusermount msggrep s2p whatis 209gapplication msghack scp whereis 210gawk msginit script which 211gdbus msgmerge scriptreplay whiptail 212gencat msgunfmt sdiff who 213genl-ctrl-list msguniq secon whoami 214geoiplookup mv sed write 215geoiplookup6 namei seq x86_64 216geoipupdate ndptool setarch x86_energy_perf_policy 217geqn neqn setfacl xargs 218getconf netstat setfont xgettext 219getent newaliases setkeycodes xmlcatalog 220getfacl newaliases.postfix setleds xmllint 221getkeycodes newgrp setmetamode xmlsec1 222getopt nf-ct-add setpriv xmlwf 223getopts nf-ct-list setsid xsltproc 224gettext nf-exp-add setterm xxd 225gettext.sh nf-exp-delete setup-nsssysinit xz 226gio nf-exp-list setup-nsssysinit.sh xzcat 227gio-querymodules-64 nf-log setvtrgb xzcmp 228glib-compile-schemas nf-monitor sftp xzdec 229gmake nf-queue sg xzdiff 230gneqn ngettext sh xzegrep 231gnroff nice sha1sum xzfgrep 232gpasswd nisdomainname sha224sum xzgrep 233gpg nl sha256sum xzless 234gpg2 nl-addr-add sha384sum xzmore 235gpg-agent nl-addr-delete sha512sum yes 236gpgconf nl-addr-list showconsolefont ypdomainname 237gpg-connect-agent nl-class-add showkey yum 238gpg-error nl-class-delete shred zcat 239gpgparsemail nl-classid-lookup shuf zcmp 240gpgsplit nl-class-list signtool zdiff 241gpgv nl-cls-add signver zegrep 242gpgv2 nl-cls-delete size zfgrep 243gpg-zip nl-cls-list skill zforce 244gpic nl-fib-lookup slabtop zgrep 245gprof nl-link-enslave sleep zless 246grep nl-link-ifindex2name slogin zmore 247groff nl-link-list snice znew 248grops nl-link-name2ifindex soelim zsoelim 249grotty nl-link-release sort
/boot/下的文件是启动相关的文件,比如grub文件。比如删除了vmlinuz-3.10.0-693.el7.x86_64这些文件,你就不能正常启动这个系统了。
1[root@lhy ~]# ls /boot/ 2config-3.10.0-693.el7.x86_64 initramfs-3.10.0-693.el7.x86_64kdump.img 3efi initrd-plymouth.img 4grub symvers-3.10.0-693.el7.x86_64.gz 5grub2 System.map-3.10.0-693.el7.x86_64 6initramfs-0-rescue-7b83625f83564e1691eca0a488be153c.img vmlinuz-0-rescue-7b83625f83564e1691eca0a488be153c 7initramfs-3.10.0-693.el7.x86_64.img vmlinuz-3.10.0-693.el7.x86_64
/dev/文件是linux系统的特有的设备文件,鼠标、键盘、显示器等文件都保存在这里。
1[root@lhy ~]# ls /dev/ 2agpgart dmmidi log port shm tty14 tty27 tty4 tty52 tty8 vcs vfio 3autofs dri loop-control ppp snapshot tty15 tty28 tty40 tty53 tty9 vcs1 vga_arbiter 4block fb0 mapper ptmx snd tty16 tty29 tty41 tty54 ttyS0 vcs2 vhci 5bsg fd mcelog pts sr0 tty17 tty3 tty42 tty55 ttyS1 vcs3 vhost-net 6btrfs-control fd0 mem random stderr tty18 tty30 tty43 tty56 ttyS2 vcs4 vmci 7bus full midi raw stdin tty19 tty31 tty44 tty57 ttyS3 vcs5 vsock 8cdrom fuse mqueue rtc stdout tty2 tty32 tty45 tty58 uhid vcs6 zero 9char hidraw0 net rtc0 tty tty20 tty33 tty46 tty59 uinput vcsa 10console hpet network_latency sda tty0 tty21 tty34 tty47 tty6 urandom vcsa1 11core hugepages network_throughput sda1 tty1 tty22 tty35 tty48 tty60 usbmon0 vcsa2 12cpu hwrng null sda2 tty10 tty23 tty36 tty49 tty61 usbmon1 vcsa3 13cpu_dma_latency initctl nvram sda3 tty11 tty24 tty37 tty5 tty62 usbmon2 vcsa4 14crash input oldmem sg0 tty12 tty25 tty38 tty50 tty63 usbmon3 vcsa5 15disk kmsg parport0 sg1 tty13 tty26 tty39 tty51 tty7 usbmon4 vcsa6
/etc/文件夹是系统的配置文件所在的位置。
1[root@lhy ~]# ls /etc/sysconfig/network-scripts/ifcfg-ens33 2/etc/sysconfig/network-scripts/ifcfg-ens33 3[root@lhy ~]# ls /etc/ssh/sshd_config 4/etc/ssh/sshd_config 5[root@lhy ~]# ls /etc/ 6adjtime ethertypes ld.so.conf popt.d skel 7aide.conf exports ld.so.conf.d postfix ssh 8aliases favicon.png libaudit.conf ppp ssl 9aliases.db filesystems libnl prelink.conf.d statetab 10alternatives firewalld libuser.conf printcap statetab.d 11anacrontab fstab locale.conf profile subgid 12asound.conf fuse.conf localtime profile.d subuid 13audisp gcrypt login.defs protocols sudo.conf 14audit GeoIP.conf logrotate.conf python sudoers 15bash_completion.d GeoIP.conf.default logrotate.d rc0.d sudoers.d 16bashrc gnupg machine-id rc1.d sudo-ldap.conf 17binfmt.d GREP_COLORS magic rc2.d sysconfig 18centos-release groff makedumpfile.conf.sample rc3.d sysctl.conf 19centos-release-upstream group man_db.conf rc4.d sysctl.d 20chkconfig.d group- mke2fs.conf rc5.d systemd 21cron.d grub2.cfg modprobe.d rc6.d system-release 22cron.daily grub.d modules-load.d rc.d system-release-cpe 23cron.deny gshadow motd rc.local terminfo 24cron.hourly gshadow- mtab redhat-release tmpfiles.d 25cron.monthly gss my.cnf resolv.conf tuned 26crontab host.conf my.cnf.d rpc udev 27cron.weekly hostname NetworkManager rpm vconsole.conf 28crypttab hosts networks rsyslog.conf vimrc 29csh.cshrc hosts.allow nsswitch.conf rsyslog.d virc 30csh.login hosts.deny nsswitch.conf.bak rwtab vmware-tools 31dbus-1 init.d openldap rwtab.d wpa_supplicant 32default inittab opt sasl2 X11 33depmod.d inputrc os-release securetty xdg 34dhcp iproute2 pam.d security xinetd.d 35DIR_COLORS issue passwd selinux xml 36DIR_COLORS.256color issue.net passwd- services yum 37DIR_COLORS.lightbgcolor kdump.conf pkcs11 sestatus.conf yum.conf 38dracut.conf kernel pki sgml yum.repos.d 39dracut.conf.d krb5.conf plymouth shadow 40e2fsck.conf krb5.conf.d pm shadow- 41environment ld.so.cache polkit-1 shells 42
/home/是用户的家目录,存用户的文件,类比于/root/
1[root@lhy ~]# ls /home/ 2lhy01
/lib/ /lib64/等文件夹存的是库文件。库文件类似于Windows下的×.dll文件。可以用ldd命令查看某个命令的依赖库。
1[root@lhy ~]# ldd /bin/ls 2 linux-vdso.so.1 => (0x00007ffd4e88f000) 3 libselinux.so.1 => /lib64/libselinux.so.1 (0x00007feffcfcf000) 4 libcap.so.2 => /lib64/libcap.so.2 (0x00007feffcdca000) 5 libacl.so.1 => /lib64/libacl.so.1 (0x00007feffcbc0000) 6 libc.so.6 => /lib64/libc.so.6 (0x00007feffc7fd000) 7 libpcre.so.1 => /lib64/libpcre.so.1 (0x00007feffc59b000) 8 libdl.so.2 => /lib64/libdl.so.2 (0x00007feffc396000) 9 /lib64/ld-linux-x86-64.so.2 (0x00005636e812b000) 10 libattr.so.1 => /lib64/libattr.so.1 (0x00007feffc191000) 11 libpthread.so.0 => /lib64/libpthread.so.0 (0x00007feffbf75000)
CentOS7之后,CentOS操作系统就没有32位系统了。32位和64位系统的最大的区别就在于识别的内存大小不一样。如果是32位的系统,只能识别4GB内存,由于操作系统本身内存占用以及地址保留,实际可以使用的内存空间为3.2G左右。
/media/目录是媒介目录,默认是空的。如果插入优盘、硬盘,系统会自动挂载到/media目录。
/mnt/是挂载目录 ,默认也为空,可以把想要的文件系统挂载到此处。
/opt/默认也是空目录,是按完系统后你又需要安装其他的应用软件,一般是源码包的软件,可以自己指定路径,管理员习惯性的把软件按在这,你也可以安装在其他位置。
/proc/存放的是进程文件,每一个进程都有一个目录,文件夹名为PID
1[root@lhy ~]# ls /proc/ 21 16 265 291 304 319 332 346 399 55 641 acpi filesystems mdstat softirqs 310 17 267 292 305 32 333 347 40 56 642 asound fs meminfo stat 411 18 268 293 306 320 334 3535 400 57 644 buddyinfo interrupts misc swaps 5111 1805 27 294 307 321 335 372 401 580 645 bus iomem modules sys 612 2 272 295 308 322 336 373 4018 581 647 cgroups ioports mounts sysrq-trigger 71202 20 273 296 309 323 337 380 41 582 653 cmdline irq mpt sysvipc 81203 21 274 297 31 324 338 383 42 583 666 consoles kallsyms mtrr timer_list 91204 22 2763 298 311 325 339 391 4259 584 679 cpuinfo kcore net timer_stats 101269 23 28 299 312 326 34 392 43 585 7 crypto keys pagetypeinfo tty 111288 24 285 3 313 327 340 393 468 586 76 devices key-users partitions uptime 121293 25 287 30 314 328 341 394 470 587 77 diskstats kmsg sched_debug version 1313 258 288 300 315 329 342 395 491 610 8 dma kpagecount schedstat vmallocinfo 141346 260 289 301 316 33 343 396 5 634 9 driver kpageflags scsi vmstat 1515 263 29 302 317 330 344 397 51 636 969 execdomains loadavg self zoneinfo 161525 264 290 303 318 331 345 398 53 637 970 fb locks slabinfo
查看某一个PID进程的文件,比如/proc/285/。其中有一个cwd,这个是进程所在的路径。比如我对于某个进程不熟悉,我就根据PID来查看这个进程是从哪执行,执行什么命令(comm文件)。
1[root@lhy ~]# ls -l /proc/285/ 2ls: cannot read symbolic link /proc/285/exe: No such file or directory 3total 0 4dr-xr-xr-x. 2 root root 0 Jun 2 23:57 attr 5-rw-r--r--. 1 root root 0 Jun 2 23:57 autogroup 6-r--------. 1 root root 0 Jun 2 23:57 auxv 7-r--r--r--. 1 root root 0 Jun 2 23:57 cgroup 8--w-------. 1 root root 0 Jun 2 23:57 clear_refs 9-r--r--r--. 1 root root 0 Jun 2 23:36 cmdline 10-rw-r--r--. 1 root root 0 Jun 2 23:57 comm 11-rw-r--r--. 1 root root 0 Jun 2 23:57 coredump_filter 12-r--r--r--. 1 root root 0 Jun 2 23:57 cpuset 13lrwxrwxrwx. 1 root root 0 Jun 2 23:57 cwd -> / 14-r--------. 1 root root 0 Jun 2 23:57 environ 15lrwxrwxrwx. 1 root root 0 Jun 2 23:57 exe 16dr-x------. 2 root root 0 Jun 2 23:57 fd 17dr-x------. 2 root root 0 Jun 2 23:57 fdinfo 18-rw-r--r--. 1 root root 0 Jun 2 23:57 gid_map 19-r--------. 1 root root 0 Jun 2 23:57 io 20-r--r--r--. 1 root root 0 Jun 2 23:57 limits 21-rw-r--r--. 1 root root 0 Jun 2 23:57 loginuid 22dr-x------. 2 root root 0 Jun 2 23:57 map_files 23-r--r--r--. 1 root root 0 Jun 2 23:57 maps 24-rw-------. 1 root root 0 Jun 2 23:57 mem 25-r--r--r--. 1 root root 0 Jun 2 23:57 mountinfo 26-r--r--r--. 1 root root 0 Jun 2 23:57 mounts 27-r--------. 1 root root 0 Jun 2 23:57 mountstats 28dr-xr-xr-x. 5 root root 0 Jun 2 23:57 net 29dr-x--x--x. 2 root root 0 Jun 2 23:57 ns 30-r--r--r--. 1 root root 0 Jun 2 23:57 numa_maps 31-rw-r--r--. 1 root root 0 Jun 2 23:57 oom_adj 32-r--r--r--. 1 root root 0 Jun 2 23:57 oom_score 33-rw-r--r--. 1 root root 0 Jun 2 23:57 oom_score_adj 34-r--r--r--. 1 root root 0 Jun 2 23:57 pagemap 35-r--r--r--. 1 root root 0 Jun 2 23:57 personality 36-rw-r--r--. 1 root root 0 Jun 2 23:57 projid_map 37lrwxrwxrwx. 1 root root 0 Jun 2 23:57 root -> / 38-rw-r--r--. 1 root root 0 Jun 2 23:57 sched 39-r--r--r--. 1 root root 0 Jun 2 23:57 schedstat 40-r--r--r--. 1 root root 0 Jun 2 23:57 sessionid 41-rw-r--r--. 1 root root 0 Jun 2 23:57 setgroups 42-r--r--r--. 1 root root 0 Jun 2 23:57 smaps 43-r--r--r--. 1 root root 0 Jun 2 23:57 stack 44-r--r--r--. 1 root root 0 Jun 2 23:57 stat 45-r--r--r--. 1 root root 0 Jun 2 23:57 statm 46-r--r--r--. 1 root root 0 Jun 2 23:36 status 47-r--r--r--. 1 root root 0 Jun 2 23:57 syscall 48dr-xr-xr-x. 3 root root 0 Jun 2 23:57 task 49-r--r--r--. 1 root root 0 Jun 2 23:57 timers 50-rw-r--r--. 1 root root 0 Jun 2 23:57 uid_map 51-r--r--r--. 1 root root 0 Jun 2 23:57 wchan
/run/是进程产生的临时文件,关机就会消失。
1[root@lhy ~]# ls /run/ 2auditd.pid cron.reboot firewalld log NetworkManager setrans syslogd.pid tuned utmp 3console dbus initramfs mount plymouth sshd.pid systemd udev vmware 4crond.pid faillock lock netreport sepermit sudo tmpfiles.d user xtables.lock
/srv/文件夹默认是空的,存系统服务产生的一些文件。
/sys/存系统内核相关的文件,一般我们不去修改它们。
/tmp/是临时文件夹,任何用户都可以向其中添加文件,权限宽泛,但是普通用户之间的文件自己管理,有特殊权限,之后会讲。
/usr/是系统用户的目录,类似于根目录。
/var/目录存储的日志文件。比如系统日志存在/var/log/messages里面。
2.3 ls命令
ls命令可以列出当前目录的文件和文件夹,这是一个非常常用的一个命令,下面会介绍一下其常用参数。
列出文件的详细信息,使用参数-l
1[root@lhy ~]# ls -l 2total 4 3-rw-------. 1 root root 1622 May 29 14:05 anaconda-ks.cfg 4drwxr-xr-x. 2 root root 40 May 29 14:04 openscap_data
第一列是文件类型与权限,第二列表示有多少文件使用了相同的inode,inode记录的是这个文件的存储位置。inode指向的是固定的一个存储块,如果两个文件inode号相同,那么它们存储的位置就是相同的,这个和后续的硬链接有关,暂且不表。第三列表示所有者,第四列表示所属组。第五列是文件大小,单位是Byte。后面就是创建时间和文件名。
查看某一文件的inode使用-i参数。
1[root@lhy ~]# ls -i anaconda-ks.cfg 267145602 anaconda-ks.cfg
使用-h可以更人性化的查看文件大小。
1[root@lhy ~]# ls -lh 2total 4.0K 3-rw-------. 1 root root 1.6K May 29 14:05 anaconda-ks.cfg 4drwxr-xr-x. 2 root root 40 May 29 14:04 openscap_data
使用-a可以查看所有文件,包括隐藏文件、隐藏目录。
1[root@lhy ~]# ls -la 2total 36 3dr-xr-x---. 4 root root 184 Jun 1 11:53 . 4dr-xr-xr-x. 17 root root 245 May 31 15:43 .. 5-rw-------. 1 root root 1622 May 29 14:05 anaconda-ks.cfg 6-rw-------. 1 root root 3206 Jun 1 13:52 .bash_history 7-rw-r--r--. 1 root root 18 Dec 29 2013 .bash_logout 8-rw-r--r--. 1 root root 176 Dec 29 2013 .bash_profile 9-rw-r--r--. 1 root root 176 Dec 29 2013 .bashrc 10-rw-r--r--. 1 root root 100 Dec 29 2013 .cshrc 11drwxr-xr-x. 2 root root 40 May 29 14:04 openscap_data 12drwx------. 2 root root 80 May 31 16:47 .ssh 13-rw-r--r--. 1 root root 129 Dec 29 2013 .tcshrc 14-rw-------. 1 root root 6877 Jun 1 11:53 .viminfo
每个目录下面都会有两个目录叫做当前目录(./)上一级目录(../),下面显示的就是为什么/root/的inode是4,因为有四个相同的目录指向同一个位置。一般来说对于目录来说,这个inode的个数和其下子目录数相同。
1[root@lhy ~]# ls -i /root/ 2 67145602 anaconda-ks.cfg 101110119 openscap_data 3[root@lhy ~]# ls -i . 4 67145602 anaconda-ks.cfg 101110119 openscap_data 5[root@lhy ~]# ls -i .ssh/.. 6 67145602 anaconda-ks.cfg 101110119 openscap_data 7[root@lhy ~]# ls -i openscap_data/.. 8 67145602 anaconda-ks.cfg 101110119 openscap_data 9 10 11[root@lhy ~]# ls -ld /root 12dr-xr-x---. 4 root root 184 Jun 1 11:53 /root 13[root@lhy ~]# ls -a /root 14. anaconda-ks.cfg .bash_logout .bashrc openscap_data .tcshrc 15.. .bash_history .bash_profile .cshrc .ssh .viminfo
使用-t选项可以按照时间降序排列。
1[root@lhy ~]# ls -lt .. 2total 20 3drwxrwxrwt. 11 root root 4096 Jun 3 03:10 tmp 4drwxr-xr-x. 22 root root 580 Jun 2 23:55 run 5drwxr-xr-x. 3 root root 19 Jun 2 23:49 home 6drwxr-xr-x. 76 root root 8192 Jun 2 23:49 etc 7drwxr-xr-x. 19 root root 3260 Jun 2 23:36 dev 8dr-xr-xr-x. 13 root root 0 Jun 2 23:36 sys 9dr-xr-xr-x. 178 root root 0 Jun 2 23:36 proc 10dr-xr-x---. 4 root root 184 Jun 1 11:53 root 11dr-xr-xr-x. 5 root root 4096 May 29 14:21 boot 12drwxr-xr-x. 19 root root 267 May 29 14:21 var 13drwxr-xr-x. 13 root root 155 May 29 14:01 usr 14lrwxrwxrwx. 1 root root 9 May 29 14:01 lib64 -> usr/lib64 15lrwxrwxrwx. 1 root root 8 May 29 14:01 sbin -> usr/sbin 16lrwxrwxrwx. 1 root root 7 May 29 14:01 lib -> usr/lib 17lrwxrwxrwx. 1 root root 7 May 29 14:01 bin -> usr/bin 18drwxr-xr-x. 2 root root 6 Nov 5 2016 media 19drwxr-xr-x. 2 root root 6 Nov 5 2016 mnt 20drwxr-xr-x. 2 root root 6 Nov 5 2016 opt 21drwxr-xr-x. 2 root root 6 Nov 5 2016 srv
使用-d选项仅显示目录,不显示其他。
1[root@lhy ~]# ls -ld / 2dr-xr-xr-x. 17 root root 245 May 31 15:43 / 3[root@lhy ~]# ls -lt / 4total 20 5drwxrwxrwt. 11 root root 4096 Jun 3 03:10 tmp 6drwxr-xr-x. 22 root root 580 Jun 2 23:55 run 7drwxr-xr-x. 3 root root 19 Jun 2 23:49 home 8drwxr-xr-x. 76 root root 8192 Jun 2 23:49 etc 9drwxr-xr-x. 19 root root 3260 Jun 2 23:36 dev 10dr-xr-xr-x. 13 root root 0 Jun 2 23:36 sys 11dr-xr-xr-x. 178 root root 0 Jun 2 23:36 proc 12dr-xr-x---. 4 root root 184 Jun 1 11:53 root 13dr-xr-xr-x. 5 root root 4096 May 29 14:21 boot 14drwxr-xr-x. 19 root root 267 May 29 14:21 var 15drwxr-xr-x. 13 root root 155 May 29 14:01 usr 16lrwxrwxrwx. 1 root root 9 May 29 14:01 lib64 -> usr/lib64 17lrwxrwxrwx. 1 root root 8 May 29 14:01 sbin -> usr/sbin 18lrwxrwxrwx. 1 root root 7 May 29 14:01 lib -> usr/lib 19lrwxrwxrwx. 1 root root 7 May 29 14:01 bin -> usr/bin 20drwxr-xr-x. 2 root root 6 Nov 5 2016 media 21drwxr-xr-x. 2 root root 6 Nov 5 2016 mnt 22drwxr-xr-x. 2 root root 6 Nov 5 2016 opt 23drwxr-xr-x. 2 root root 6 Nov 5 2016 srv 24
之前也提过,使用man命令可以查看ls的所有参数,我们只需要记住常用的,按需查询即可。
最后,使用别名可以方便输入命令,比如给目录自动添加颜色需要--color=auto的参数,而想只需要ls就能实现,这个会在2.5节讲到。
1[root@lhy ~]# which ls 2alias ls='ls --color=auto' 3 /usr/bin/ls
2.4 文件类型
上一小节讲到使用ls -l查看文件的时候第一列显示的是文件的类型与权限。文件类型就是第一个字符表示的。
1[root@lhy ~]# ls -la 2total 36 3dr-xr-x---. 4 root root 184 Jun 1 11:53 . 4dr-xr-xr-x. 17 root root 245 May 31 15:43 .. 5-rw-------. 1 root root 1622 May 29 14:05 anaconda-ks.cfg 6drwxr-xr-x. 2 root root 40 May 29 14:04 openscap_data 7drwx------. 2 root root 80 May 31 16:47 .ssh 8-rw-------. 1 root root 6877 Jun 1 11:53 .viminfo
d表示这个“文件“是一个目录。’-‘表示这个”文件“是普通文本文档。不管是普通文本文档还是二进制文件,都会显示为’-‘ 。
c表示字符串设备。
1[root@lhy ~]# ls -l /dev/tty0 2crw--w----. 1 root tty 4, 0 Jun 2 23:36 /dev/tty0
l表示软连接文件,相当于Windows的快捷方式
1[root@lhy ~]# ls -l /dev/stderr 2lrwxrwxrwx. 1 root root 15 Jun 2 23:36 /dev/stderr -> /proc/self/fd/2
b表示块设备,比如光盘,硬盘等。
1[root@lhy ~]# ls -l /dev/sda* 2brw-rw----. 1 root disk 8, 0 Jun 2 23:36 /dev/sda 3brw-rw----. 1 root disk 8, 1 Jun 2 23:36 /dev/sda1 4brw-rw----. 1 root disk 8, 2 Jun 2 23:36 /dev/sda2 5brw-rw----. 1 root disk 8, 3 Jun 2 23:36 /dev/sda3
s表示socket文件,用于进程、服务之间通信所用的文件。
1[root@lhy ~]# ls -l /dev/log 2srw-rw-rw-. 1 root root 0 Jun 2 23:36 log
2.5 alias命令
ls和ll命令其实都是有别名的,我们可以用alias命令查看。
1[root@lhy ~]# alias ls 2alias ls='ls --color=auto' 3[root@lhy ~]# alias ll 4alias ll='ls -l --color=auto' 5[root@lhy ~]# alias yum 6-bash: alias: yum: not found 7[root@lhy ~]# alias which 8alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
如果存在别名就会显示别名,如果不存在会返回not found。我们发现which的别名中就有alias命令,所以查看一个命令来源可以直接使用which命令。
如果想看所有的有别名命令,直接使用alias即可。
1[root@lhy ~]# alias 2alias cp='cp -i' 3alias egrep='egrep --color=auto' 4alias fgrep='fgrep --color=auto' 5alias grep='grep --color=auto' 6alias l.='ls -d .* --color=auto' 7alias ll='ls -l --color=auto' 8alias ls='ls --color=auto' 9alias mv='mv -i' 10alias rm='rm -i' 11alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
不希望使用别名而想直接应用命令,使用绝对路径即可。
1[root@lhy ~]# /bin/ls . 2anaconda-ks.cfg openscap_data
下面介绍一个系统的环境变量PATH
1[root@lhy ~]# echo $PATH 2/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
可以看到PATH中使用:分割了很多文件目录,只要是在这些目录里的可执行文件都可以直接输入文件名而执行,which查询命令就是在PATH中查询的。
现在,我们创建一个别名aming,比如让它变为ls -lha,使用如下方法
1[root@lhy ~]# alias aming='ls -lha' 2[root@lhy ~]# aming 3total 36K 4dr-xr-x---. 4 root root 184 Jun 1 11:53 . 5dr-xr-xr-x. 17 root root 245 May 31 15:43 .. 6-rw-------. 1 root root 1.6K May 29 14:05 anaconda-ks.cfg 7-rw-------. 1 root root 3.2K Jun 1 13:52 .bash_history 8-rw-r--r--. 1 root root 18 Dec 29 2013 .bash_logout 9-rw-r--r--. 1 root root 176 Dec 29 2013 .bash_profile 10-rw-r--r--. 1 root root 176 Dec 29 2013 .bashrc 11-rw-r--r--. 1 root root 100 Dec 29 2013 .cshrc 12drwxr-xr-x. 2 root root 40 May 29 14:04 openscap_data 13drwx------. 2 root root 80 May 31 16:47 .ssh 14-rw-r--r--. 1 root root 129 Dec 29 2013 .tcshrc 15-rw-------. 1 root root 6.8K Jun 1 11:53 .viminfo 16[root@lhy ~]# which aming 17alias aming='ls -lha' 18 /usr/bin/ls
取消别名的方法也很简单,使用unalias + 别名 即可。
1[root@lhy ~]# unalias aming 2[root@lhy ~]# aming 3-bash: aming: command not found