我使用的是redhat,可以联网的,用yum是比较方便的,一条命令搞定:

yum -y install tree

如果没有联网,也可以的:

假定你的ISO文件在光盘上或者已经在Linux系统里:

1,mkdir -p /mnt/cdrom
2,mount -o loop iso/to/path/centos.iso /mnt/cdrom
备份一下这个文件夹,以后有网络时,恢复。
3,mv /etc/yum.repos.d /etc/yum.repos.d.bak
3,mkdir -p /etc/yum.repos.d
4,cd /etc/yum.repos.d
5,vi iso.repo
添加内容:
[base]
name=centos
baseurl=file:///mnt/cdrom
enable=1
gpgcheck=0
进去这个目录里可以看到的。补齐下面的。
gpgkey=file:///mnt/cdrom/RPM-GPG....

完成后,
yum clean all
yum -y install tree

当然还另外的办法:

1. 在网上下载tree命令对应的源文件, 然后tar解压。

2. 执行make命令进行编译, 生成tree文件(可执行文件)

3. 把tree文件拷贝到/bin中

具体如下:

  1. [root@localhost test]# ls
  2. a.txt  b.txt  tree-1.7.0.tgz
  3. [root@localhost test]# tar zxvf tree-1.7.0.tgz
  4. tree-1.7.0/CHANGES
  5. tree-1.7.0/INSTALL
  6. tree-1.7.0/LICENSE
  7. tree-1.7.0/Makefile
  8. tree-1.7.0/README
  9. tree-1.7.0/TODO
  10. tree-1.7.0/color.c
  11. tree-1.7.0/hash.c
  12. tree-1.7.0/html.c
  13. tree-1.7.0/json.c
  14. tree-1.7.0/strverscmp.c
  15. tree-1.7.0/tree.c
  16. tree-1.7.0/tree.h
  17. tree-1.7.0/unix.c
  18. tree-1.7.0/xml.c
  19. tree-1.7.0/doc/tree.1
  20. tree-1.7.0/doc/tree.1.fr
  21. tree-1.7.0/doc/xml.dtd
  22. [root@localhost test]# cd tree-1.7.0
  23. [root@localhost tree-1.7.0]# make
  24. gcc -ggdb -Wall -DLINUX -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -c -o tree.o tree.c
  25. gcc -ggdb -Wall -DLINUX -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -c -o unix.o unix.c
  26. gcc -ggdb -Wall -DLINUX -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -c -o html.o html.c
  27. gcc -ggdb -Wall -DLINUX -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -c -o xml.o xml.c
  28. gcc -ggdb -Wall -DLINUX -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -c -o json.o json.c
  29. gcc -ggdb -Wall -DLINUX -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -c -o hash.o hash.c
  30. gcc -ggdb -Wall -DLINUX -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -c -o color.o color.c
  31. gcc  -o tree tree.o unix.o html.o xml.o json.o hash.o color.o
  32. [root@localhost tree-1.7.0]# cp tree /bin
  33. [root@localhost tree-1.7.0]# tree ../ -L 1
  34. ../
  35. ├── a.txt
  36. ├── b.txt
  37. ├── tree-1.7.0
  38. └── tree-1.7.0.tgz
  39. 1 directory, 3 files
  40. [root@localhost tree-1.7.0]# tree ../ -L 2
  41. ../
  42. ├── a.txt
  43. ├── b.txt
  44. ├── tree-1.7.0
  45. │   ├── CHANGES
  46. │   ├── color.c
  47. │   ├── color.o
  48. │   ├── doc
  49. │   ├── hash.c
  50. │   ├── hash.o
  51. │   ├── html.c
  52. │   ├── html.o
  53. │   ├── INSTALL
  54. │   ├── json.c
  55. │   ├── json.o
  56. │   ├── LICENSE
  57. │   ├── Makefile
  58. │   ├── README
  59. │   ├── strverscmp.c
  60. │   ├── TODO
  61. │   ├── tree
  62. │   ├── tree.c
  63. │   ├── tree.h
  64. │   ├── tree.o
  65. │   ├── unix.c
  66. │   ├── unix.o
  67. │   ├── xml.c
  68. │   └── xml.o
  69. └── tree-1.7.0.tgz
  70. 2 directories, 26 files
  71. [root@localhost tree-1.7.0]#

OK, 一颗漂亮的tree就这样出来了, 如上是在root用户下的操作, 主要是因为往/bin中复制东西需要root权限。 复制之后, 普通用户也可以执行tree命令了。

yantaisolo

作者 yantaisolo