Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to `ls` only one level deep?

Tags:

bash

ls

I have lots subdirectories containing data, and I want a short list of which jobs (subdirectories) I have. I'm not happy with the following command.

$ ls H2* H2a: energy.dat overlap.dat  norm.dat zdip.dat ... (much more) H2b: energy.dat overlap.dat norm.dat zdip.dat ...  (much more) 

This needless clutter defeats the purpose of the wildcard (limiting the output). How can I limit the output to one level deep? I'd like to see the following output

H2a/ H2b/ H2z/ 

Thanks for your help, Nick

like image 893
Nick Vence Avatar asked Feb 07 '11 16:02

Nick Vence


1 Answers

Try this

ls -d H2*/ 

The -d option is supposed to list "directories only", but by itself just lists

. 

which I personally find kind of strange. The wildcard is needed to get an actual list of directories.

UPDATE: As @Philipp points out, you can do this even more concisely and without leaving bash by saying

echo H2*/ 

The difference is that ls will print the items on separate lines, which is often useful for piping to other functions.

like image 51
harpo Avatar answered Oct 21 '22 08:10

harpo