Linux CentOS 目录结构为树?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5732696/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CentOS directory structure as tree?
提问by nsfyn55
Is there an equivalent to tree on CentOS?
CentOS 上是否有等效于 tree 的东西?
采纳答案by Carlos Tasada
回答by bash-o-logist
You can make your own primitive "tree" ( for fun :) )
您可以制作自己的原始“树”(为了好玩:))
#!/bin/bash
# only if you have bash 4 in your CentOS system
shopt -s globstar
for file in **/*
do
slash=${file//[^\/]}
case "${#slash}" in
0) echo "|-- ${file}";;
1) echo "| |-- ${file}";;
2) echo "| | |-- ${file}";;
esac
done
回答by Mattias Ohlsson
You have tree in the base repo.
你在基础仓库中有树。
Show it (yum list package-name):
显示它(yum list package-name):
# yum list tree
Available Packages
tree.i386 1.5.0-4 base
Install it:
安装它:
yum install tree
(verified on CentOS 5 and 6)
(已在 CentOS 5 和 6 上验证)
回答by Sventek
If tree is not installed on your Centos system (I typically recommend server setups to use minimal install disk anyhow) you should type the following at your command line:
如果你的 Centos 系统上没有安装 tree(我通常建议服务器设置使用最少的安装磁盘)你应该在你的命令行中输入以下内容:
# yum install tree -y
If this doesn't install it's because you don't have the proper repository. I would use the Dag Wieers repository:
如果这没有安装,那是因为您没有正确的存储库。我会使用 Dag Wieers 存储库:
http://dag.wieers.com/rpm/FAQ.php#B
http://dag.wieers.com/rpm/FAQ.php#B
After that you can do your install:
之后,您可以进行安装:
# yum install tree -y
Now you're ready to roll. Always read the man page: http://linux.die.net/man/1/tree
现在你准备好开始了。始终阅读手册页:http: //linux.die.net/man/1/tree
So quite simply the following will return a tree:
所以很简单,以下将返回一棵树:
# tree
Alternatively you can output this to a text file. There's a ton of options too.. Again, read your man page if you're looking for something other than default output.
或者,您可以将其输出到文本文件。还有很多选项。如果您正在寻找除默认输出之外的其他内容,请再次阅读您的手册页。
# tree > recursive_directory_list.txt
(^^ in a text file for later review ^^)
(^^ 在文本文件中供以后查看 ^^)
回答by Sabrina
Since tree
is not installed by default in CentOS ...
由于tree
在 CentOS 中默认未安装...
[user@CentOS test]$ tree
-bash: tree: command not found
[user@CentOS test]$
You can also use the following ls
command to produce almost similar output with tree
您还可以使用以下ls
命令产生几乎相似的输出tree
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
Example:
例子:
[user@CentOS test]$ ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
.
|-directory1
|-directory2
|-directory3
[user@CentOS directory]$