Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I use the tree command to list current directory as a tree?

If I do

tree -L 1

It only lists the directories, how can I get it to show the files as well?

share|improve this question
    
What OS is this for? /L is not a valid switch for Windows XP. –  Iszi Jan 9 '12 at 15:37
    
OS is Linux - Ubuntu. –  Nix Jan 9 '12 at 15:42
    
Well, that was a waste of an answer. Maybe my Ubuntu VM can help me top it off. –  Iszi Jan 9 '12 at 15:45
2  
tree -L 1 will list both file and directories. If you have no files in the current directory or hidden files (.* prefix), they will not show up by default. –  Herman Torjussen Jan 9 '12 at 16:27
    
My issue was hidden files.... ;( I can only hope it was an early morning Brain Fart... –  Nix Jan 10 '12 at 15:31
add comment

2 Answers

up vote 4 down vote accepted

For Windows XP or 7, the /F switch will also show filenames.

C:\>tree /?
Graphically displays the folder structure of a drive or path.

TREE [drive:][path] [/F] [/A]

   /F   Display the names of the files in each folder.
   /A   Use ASCII instead of extended characters.

However, I'm guessing you're on another OS since /L is not a valid switch on XP or 7.

On my Ubuntu VM (11.10), tree did not come pre-installed. sudo apt-get install tree fixed that quickly. Afterwards tree -L 1 worked just as you seem to want it to - it showed a tree of just the current directory, including files and directories. Adding the -a switch also included "hidden" files. It seems the default behavior of tree is to show both files and directories. This can be changed to directories only with the -d switch.

More details can be found in man tree or here: http://www.computerhope.com/unix/tree.htm

If you're having trouble, I suggest checking the ls of your pwd to make sure there actually are files in that directory. Also, check your file and folder permissions and view the man page for tree for more options.

share|improve this answer
    
+1 i was missing the -a switch. –  Nix Jan 10 '12 at 15:32
add comment

It lists both files and directories for me:

[ben@ben-x220 ~/tmp/test]$ tree --version
tree v1.5.3 (c) 1996 - 2009 by Steve Baker, Thomas Moore, Francesc Rocher, Kyosuke Tokoro 

[ben@ben-x220 ~/tmp/test]$ tree -L 1
.
├── dir1
├── file1
├── file2
└── file3

1 directory, 3 files

[ben@ben-x220 ~/tmp/test]$ tree
.
├── dir1
│   └── file4
├── file1
├── file2
└── file3

1 directory, 4 files
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.