hpekristiansen
hpekristiansen

Reputation: 1070

In bash how do I use ls to list a single folder

I often use ls (in long format: ll) to list a single file, just to see the attributes. How do I list a single folder, without expanding the content.

Example

hpek@melda:~/temp/test$ ls
file.txt folder
hpek@melda:~/temp/test$ ls file.txt 
file.txt
hpek@melda:~/temp/test$ ls folder/
content.txt
hpek@melda:~/temp/test$ ls folder
content.txt
hpek@melda:~/temp/test$ 

Edit:

The answer is plainly written in man ls : use the -d option. But why is ls folder not working?

Upvotes: 10

Views: 5024

Answers (2)

Todd A. Jacobs
Todd A. Jacobs

Reputation: 84343

To see the attributes of a folder, use the --directory flag.

$ ls -lad /etc
drwxr-xr-x 191 root root 12288 2012-05-08 13:07 /etc

The -a flag isn't really necessary, but it doesn't hurt, and makes the command a little more mnemonic for me by spelling a word. That sort of thing can be very helpful in remembering certain invocations.

Upvotes: 2

cnicutar
cnicutar

Reputation: 182619

How do I list a single folder, without expanding the content.

Try passing the -d switch.

cnicutar@lemon:~$ ls -ld /etc
drwxr-xr-x 144 root root 12288 May  8 18:50 /etc

Upvotes: 13

Related Questions