CentOS directory structure as tree?

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:

# 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:

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

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 ^^)


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

Tags:

Linux

Bash

Centos