欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

CentOS6.5下tree命令-bash: tree: command not found的解决办法

刚装好的CentOS6.5,使用tree命令时,提示tree: command not found,该如何解决呢,问题很明显,tree没有安装,直接安装一下

yum -y install tree

[root@promote html]# yum -y install tree
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
epel/metalink | 5.6 kB 00:00 
* base: mirrors.hust.edu.cn
* epel: ftp.sjtu.edu.cn
* extras: mirrors.hust.edu.cn
* updates: ftp.sjtu.edu.cn
base | 3.7 kB 00:00 ... 
epel | 4.4 kB 00:00 
epel/primary_db | 6.5 MB 00:04 
extras | 3.4 kB 00:00 ... 
updates | 3.4 kB 00:00 
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.5.3-2.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================
Package Arch Version Repository Size
==============================================================================================
Installing:
tree x86_64 1.5.3-2.el6 base 36 k

Transaction Summary
==============================================================================================
Install 1 Package(s)

Total download size: 36 k
Installed size: 65 k
Downloading Packages:
tree-1.5.3-2.el6.x86_64.rpm | 36 kB 00:03 
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : tree-1.5.3-2.el6.x86_64 1/1 
Verifying : tree-1.5.3-2.el6.x86_64 1/1

Installed:
tree.x86_64 0:1.5.3-2.el6

Complete!
[root@promote html]#

可见安装完成。

来自 http://www.91ctc.com/article/article-366.html


 

linux中缺少某些命令该怎么办呢?------以tree命令为例

  老伴喜欢玩扫雷游戏, 某次, 她发现自己的电脑里面没有扫雷程序, 就觉得系统有问题, 懂一点软件的我告诉她, 拷贝一个winmine.exe就行, 果然奏效。

        

        在本文中, 我们来聊聊这样一个常见的问题: 在linux中输入某命令后, 系统提示没有这个命令, 比如:bash: tree: command not found. 系统提示我们, 没有tree这个命令, 那该怎么办呢?

        首先我们必须明白linux命令的本质, 大家都知道, 在linux中, 一切都是文件, 所以命令也是文件。 在这里, 我们可以理解为执行tree命令就是执行tree文件(通常是可执行文件、脚本等), 然后我们想办法把tree文件拷贝到系统默认目录中(需要root权限)。最后, 万事大吉, tree命令可以用了。

       那问题是, 我们去哪里拷贝呢? 有两个方法:

       a. 从别的机器上拷贝;

       b. 编译tree对应的源代码, 生成对应的tree文件, 然后拷贝到对应的系统目录。


       在本文中, 我只介绍第二种方法,步骤如下:

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

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

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

        具体如下:


[plain] view plain copy
  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.   

  40. 1 directory, 3 files  

  41. [root@localhost tree-1.7.0]# tree ../ -L 2  

  42. ../  

  43. ├── a.txt  

  44. ├── b.txt  

  45. ├── tree-1.7.0  

  46. │   ├── CHANGES  

  47. │   ├── color.c  

  48. │   ├── color.o  

  49. │   ├── doc  

  50. │   ├── hash.c  

  51. │   ├── hash.o  

  52. │   ├── html.c  

  53. │   ├── html.o  

  54. │   ├── INSTALL  

  55. │   ├── json.c  

  56. │   ├── json.o  

  57. │   ├── LICENSE  

  58. │   ├── Makefile  

  59. │   ├── README  

  60. │   ├── strverscmp.c  

  61. │   ├── TODO  

  62. │   ├── tree  

  63. │   ├── tree.c  

  64. │   ├── tree.h  

  65. │   ├── tree.o  

  66. │   ├── unix.c  

  67. │   ├── unix.o  

  68. │   ├── xml.c  

  69. │   └── xml.o  

  70. └── tree-1.7.0.tgz  

  71.   

  72. 2 directories, 26 files  

  73. [root@localhost tree-1.7.0]#   





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



       本文虽然简单, 但至少可以让我们深入理解linux命令究竟是怎么回事。当然, 如果大家对tree的源代码有兴趣, 也不妨研究一下。 这也可以看做广义上的linux源码(扩展的源码)。


        我会把tree的源码放在自己的博客资源中供大家免费免积分下载, 有兴趣的朋友可以试试。 赶快去看看吧。

来自   http://blog.csdn.net/stpeace/article/details/49524273

普通分类: