Chapter 2. Linux Key Commands

Ls (List Contents of Directory)

Ls (List Contents of Directory)
Tag:

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.

Command Line - INPUT
ls
Command Line - RESPONSE
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.

Command Line - INPUT
ls /
Command Line - RESPONSE
bin dev home lib32 libx32 media opt root  ....

-a option

With the -a option, you can list up directory contents including hidden files.

Command Line - INPUT
ls -a
Command Line - RESPONSE
. .. .bash_history .bash_logout .bashrc .cache. .profile .ssh ...

-l option

With the -l option, you can list directory contents with detailed information.

Command Line - INPUT
ls -l
Command Line - RESPONSE
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 .

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.

Command Line - INPUT
ls
Command Line - RESPONSE
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.

Command Line - INPUT
ls /
Command Line - RESPONSE
bin dev home lib32 libx32 media opt root  ....

-a option

With the -a option, you can list up directory contents including hidden files.

Command Line - INPUT
ls -a
Command Line - RESPONSE
. .. .bash_history .bash_logout .bashrc .cache. .profile .ssh ...

-l option

With the -l option, you can list directory contents with detailed information.

Command Line - INPUT
ls -l
Command Line - RESPONSE
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 .

Tag: