Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

bash

ls

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?

like image 281
hpekristiansen Avatar asked May 08 '12 19:05

hpekristiansen


People also ask

How do I ls a specific directory?

To have ls list the files in a directory other than the current directory, pass the path to the directory to ls on the command line. You can also pass more than one directory to ls , and have them listed one after the other.

How do I list directories in Bash?

To see a list of all subdirectories and files within your current working directory, use the command ls .

How do I list only ls files?

ls is a Linux and Unix command that allows you to list all files and directories in a directory. You can also use ls -d to view only directories and use ls -f to view only files as shown above.


1 Answers

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
like image 54
cnicutar Avatar answered Sep 27 '22 00:09

cnicutar