本經驗均在CentOS release 6.7 (Final)下操作:
用ls 命令查看目錄/var顯示:
# ls /var/
account crash db games local log nis preserve spool yp
cache cvs empty lib lock mail opt run tmp
為了更直觀的顯示文件目錄,我們用tree命令來顯示:
# yum install tree
Loaded plugins: fastestmirror, security
Setting up Install Process
base | 3.7 kB 00:00
base/primary_db | 4.7 MB 02:22
extras | 3.4 kB 00:00
extras/primary_db | 37 kB 00:00
updates | 3.4 kB 00:00
updates/primary_db | 89 kB 00:01
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.5.3-3.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================
Package Arch Version Repository Size
===============================================================================
Installing:
tree x86_64 1.5.3-3.el6 base 36 k
Transaction Summary
===============================================================================
Install 1 Package(s)
Total download size: 36 k
Installed size: 65 k
Is this ok [y/N]: y
Downloading Packages:
tree-1.5.3-3.el6.x86_64.rpm | 36 kB 00:00
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Importing GPG key 0xC105B9DE:
Userid : CentOS-6 Key (CentOS 6 Official Signing Key) <[email protected]>
Package: centos-release-6-7.el6.centos.12.3.x86_64 (@anaconda-CentOS-201508042137.x86_64/6.7)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : tree-1.5.3-3.el6.x86_64 1/1
Verifying : tree-1.5.3-3.el6.x86_64 1/1
Installed:
tree.x86_64 0:1.5.3-3.el6
Complete!
tree命令安裝完畢!
顯示/var目錄的一級目錄和文件:
# tree -L 1 /var
/var
a”a”a” account
a”a”a” cache
a”a”a” crash
a”a”a” cvs
a”a”a” db
a”a”a” empty
a”a”a” games
a”a”a” lib
a”a”a” local
a”a”a” lock
a”a”a” log
a”a”a” mail -> spool/mail
a”a”a” nis
a”a”a” opt
a”a”a” preserve
a”a”a” run
a”a”a” spool
a”a”a” tmp
a””a”a” yp
19 directories, 0 files
顯示亂碼,產生亂碼的原因就是:當前用戶的環境LANG變量與crt的字符編碼沒有保持一致。
Linux的字符集查看:
# echo $LANG
en_US.UTF-8
將CRT的字符集設置UTF-8即可 :
顯示/var目錄的一級目錄和文件:正常
# tree -L 1 /var
/var
├── account
├── cache
├── crash
├── cvs
├── db
├── empty
├── games
├── lib
├── local
├── lock
├── log
├── mail -> spool/mail
├── nis
├── opt
├── preserve
├── run
├── spool
├── tmp
└── yp
19 directories, 0 files
tree的系統幫助:
# tree --help
usage: tree [-adfghilnpqrstuvxACDFNS] [-H baseHREF] [-T title ] [-L level [-R]]
[-P pattern] [-I pattern] [-o filename] [--version] [--help] [--inodes]
[--device] [--noreport] [--nolinks] [--dirsfirst] [--charset charset]
[--filelimit #] [<directory list>]
-a All files are listed.
-d List directories only.
-l Follow symbolic links like directories.
-f Print the full path prefix for each file.
-i Don't print indentation lines.
-q Print non-printable characters as '?'.
-N Print non-printable characters as is.
-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.
-D Print the date of last modification.
-F Appends '/', '=', '*', or '|' as per ls -F.
-v Sort files alphanumerically by version.
-r Sort files in reverse alphanumeric order.
-t Sort files by last modification time.
-x Stay on current filesystem only.
-L level Descend only level directories deep.
-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.
-P pattern List only those files that match the pattern given.
-I pattern Do not list files that match the given pattern.
-H baseHREF Prints out HTML format with baseHREF as top directory.
-T string Replace the default HTML title and H1 header with string.
-R Rerun tree when max dir level reached.
-o file Output to file instead of stdout.
--inodes Print inode number of each file.
--device Print device ID number to which each file belongs.
--noreport Turn off file/directory count at end of tree listing.
--nolinks Turn off hyperlinks in HTML output.
--dirsfirst List directories before files.
--charset X Use charset X for HTML and indentation line output.
--filelimit # Do not descend dirs with more than # files in them.
本文出自 “tao” 博客,請務必保留此出處http://xtao16.blog.51cto.com/911643/1784146