0

I am looking for a command that will write the names of all directories, subdirectories and file names to a text file.

Example format:

directory1
|_subdirectory1
| |_filename1.mp4
|_subdirectory2
| |_filename2.txt
| |_filename3.jpg
|
directory2
|
...

So the text file will only just show what the directory, subdirectories and file names are. The lines dont have to exist but it graphically gives a better view. Not sure if that part is possible or not.

Thx!

2
  • Have you tried tree DirName | tee file.txt, tree DirName > file.txt or tree DirName -o file.txt? Feb 27 at 20:12
  • tree DirName > file.txt <---- this works! thanks. Feb 27 at 20:48

1 Answer 1

2

tree command with -o option.

For example to output contents of /home to file.txt

tree /home -o file.txt

You will probably need to install tree package, since it is usually not installed by default.

There are other options available which you can see with:

tree --help
4
  • Thanks. I see that the output file has this symbol "00' on top and '1B' on bottom (tried to copy and paste the symbol but it doesnt appear in the comment) in every line. How can that be removed? Feb 27 at 20:15
  • Not sure what you mean shows in file, can you paste part of the output to your question, to see how it looks
    – ralz
    Feb 27 at 20:19
  • I think he's talking about excape characters. When I use -o and open the result file in less, the output has escape chars all over; ESC[01;34m/usr/share/vimESC[00m. Redirecting with > doesn't produce those. Feb 27 at 20:53
  • Option -n disables the coloration.
    – Freddy
    Feb 27 at 21:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .