Print indentations with whitespace only in tree command

sedtree

I want to list the subdirectories of a directory using tree command. But I don't want to print indentation lines. I only want to have the whitespaces instead.

I couldn't find the correct parameter in man page. Maybe I can pipe the output of tree to sed to remove the lines.

Best Answer

So you want something like this:

tree | sed 's/├\|─\|│\|└/ /g'

It replaces all those "line" characters with spaces.


See:

$ tree
.
├── dir1
│   ├── file1
│   └── file2
└── dir2
    ├── file1
    └── file2

2 directories, 4 files
$ tree | sed 's/├\|─\|│\|└/ /g'
.
    dir1
        file1
        file2
    dir2
        file1
        file2

2 directories, 4 files
Related Question