我使用的是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中
具体如下:
- [root@localhost test]# ls
- a.txt b.txt tree-1.7.0.tgz
- [root@localhost test]# tar zxvf tree-1.7.0.tgz
- tree-1.7.0/CHANGES
- tree-1.7.0/INSTALL
- tree-1.7.0/LICENSE
- tree-1.7.0/Makefile
- tree-1.7.0/README
- tree-1.7.0/TODO
- tree-1.7.0/color.c
- tree-1.7.0/hash.c
- tree-1.7.0/html.c
- tree-1.7.0/json.c
- tree-1.7.0/strverscmp.c
- tree-1.7.0/tree.c
- tree-1.7.0/tree.h
- tree-1.7.0/unix.c
- tree-1.7.0/xml.c
- tree-1.7.0/doc/tree.1
- tree-1.7.0/doc/tree.1.fr
- tree-1.7.0/doc/xml.dtd
- [root@localhost test]# cd tree-1.7.0
- [root@localhost tree-1.7.0]# make
- gcc -ggdb -Wall -DLINUX -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -c -o tree.o tree.c
- gcc -ggdb -Wall -DLINUX -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -c -o unix.o unix.c
- gcc -ggdb -Wall -DLINUX -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -c -o html.o html.c
- gcc -ggdb -Wall -DLINUX -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -c -o xml.o xml.c
- gcc -ggdb -Wall -DLINUX -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -c -o json.o json.c
- gcc -ggdb -Wall -DLINUX -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -c -o hash.o hash.c
- gcc -ggdb -Wall -DLINUX -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -c -o color.o color.c
- gcc -o tree tree.o unix.o html.o xml.o json.o hash.o color.o
- [root@localhost tree-1.7.0]# cp tree /bin
- [root@localhost tree-1.7.0]# tree ../ -L 1
- ../
- ├── a.txt
- ├── b.txt
- ├── tree-1.7.0
- └── tree-1.7.0.tgz
- 1 directory, 3 files
- [root@localhost tree-1.7.0]# tree ../ -L 2
- ../
- ├── a.txt
- ├── b.txt
- ├── tree-1.7.0
- │ ├── CHANGES
- │ ├── color.c
- │ ├── color.o
- │ ├── doc
- │ ├── hash.c
- │ ├── hash.o
- │ ├── html.c
- │ ├── html.o
- │ ├── INSTALL
- │ ├── json.c
- │ ├── json.o
- │ ├── LICENSE
- │ ├── Makefile
- │ ├── README
- │ ├── strverscmp.c
- │ ├── TODO
- │ ├── tree
- │ ├── tree.c
- │ ├── tree.h
- │ ├── tree.o
- │ ├── unix.c
- │ ├── unix.o
- │ ├── xml.c
- │ └── xml.o
- └── tree-1.7.0.tgz
- 2 directories, 26 files
- [root@localhost tree-1.7.0]#
OK, 一颗漂亮的tree就这样出来了, 如上是在root用户下的操作, 主要是因为往/bin中复制东西需要root权限。 复制之后, 普通用户也可以执行tree命令了。