Skip to content

ls – list directory contents

The ls command is one of the most basic and commonly used commands in Linux. It is used to list the files and directories in a directory. Here is a tutorial on how to use the ls command:

  1. Open a terminal window: To access the Linux command line, you can use the terminal application, which is usually found in the “Utilities” or “System Tools” section of the application menu.
  2. Change to the directory you want to list: To change to a different directory, use the cd command followed by the path to the directory you want to change to. For example, to change to the /home directory, you would run the following command:
cd /home
  1. List the contents of the directory: To list the contents of the current directory, simply run the ls command without any arguments:
ls

This will display a list of all files and directories in the current directory.

  1. List the contents of a specific directory: To list the contents of a specific directory, you can specify the path to the directory after the ls command:
ls /path/to/directory
  1. Display detailed information about files and directories: To display detailed information about files and directories, you can use the ls -l option:
ls -l

This will display a long list of information about each file and directory, including the file permissions, owner, group, size, and modification time.

  1. Display hidden files: By default, the ls command does not display hidden files and directories. To display hidden files, you can use the ls -a option:
ls -a
  1. Sort the output: By default, the ls command sorts the output alphabetically. To sort the output by other criteria, such as modification time or file size, you can use the ls -t or ls -S options, respectively:
ls -t
ls -S

These are just a few examples of how to use the ls command. There are many other options and variations that you can use to customize the output and display the information you need. To learn more about the ls command and its options, you can consult the ls manual page by running the following command:

man ls