ls (List Contents of Directory)
The ls
(LiSt directory) command is used to list the contents of a directory. On the GUI (Graphic User Interface), you can see what directories and files are contained under a directory. On the CUI (Character User Interface), you need to use your keyboard to list up the directory contents.
List up Working Directory contents
When you run the ls
command without specifying a directory path, you get a list of the contents of your working directory like the one below.
ls
application media sample.txt
List up directory contents under a specific location
You can specify a file path to execute the ls command. This is an example of listing up the root directory contents.
ls /
bin dev home lib32 libx32 media opt root ....
-a option
With the -a
option, you can list up directory contents including hidden files.
ls -a
. .. .bash_history .bash_logout .bashrc .cache. .profile .ssh ...
-l option
With the -l
option, you can list directory contents with detailed information.
ls -l
drwxr-xr-x 3 usr_a staff 4096 Jul 16 2020 media
-rwxr-xr-x 15 usr_b staff 3180 Dec 21 12:53 sample.txt
Here is the list of information
- Directory or file (
d
= directory,-
= file) - Access mode or permission (
r
= read,w
= write,x
= execute)- The first three letters: owner's access mode
- Next three letters: owner group's access mode
- The last three letters: others' access mode
- Number of hard links
- Owner of the directory or file
- Owner group of the directory or file
- The latest date and time of modification
- Name of directory or file
Note: To learn about the access mode, check Permission (Access Mode) by Owner Status.