码迷,mamicode.com
首页 > 系统相关 > 详细

linux 用树形命令tree 显示文件目录结构及处理CRT显示乱码问题

时间:2016-05-29 01:03:49      阅读:1721      评论:0      收藏:0      [点我收藏+]

标签:linux   crt   tree   乱码   

本经验均在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) <centos-6-key@centos.org>
 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.


本文出自 “evil” 博客,请务必保留此出处http://evil001.blog.51cto.com/911643/1784146

linux 用树形命令tree 显示文件目录结构及处理CRT显示乱码问题

标签:linux   crt   tree   乱码   

原文地址:http://evil001.blog.51cto.com/911643/1784146

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!