The Linux LS Command – How to List Files in a Directory

The “ls” command is a basic command in Linux that allows you to list the files and directories in a directory. In this tutorial, we will explain how to use the “ls” command and its various options.

  1. Basic ls Command To use the basic “ls” command, open the terminal and navigate to the directory you want to list the files for. Type the following command and press Enter:
bash
ls

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

  1. List Files with Details To list the files with more details, including the file size, owner, permissions, and creation date, use the “-l” option:
bash
ls -l

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

  1. List Hidden Files By default, the “ls” command does not display hidden files (files that start with a dot). To display hidden files, use the “-a” option:
bash
ls -a

This will list all files and directories, including hidden files.

  1. List Files by Size You can also use the “ls” command to list files by size. To do this, use the “-S” option:
bash
ls -S

This will list all the files in the current directory in descending order of size.

  1. List Files by Date You can also use the “ls” command to list files by date. To do this, use the “-t” option:
bash
ls -t

This will list all the files in the current directory in descending order of modification time.

  1. List Files Recursively If you want to list all the files in a directory and its subdirectories, use the “-R” option:
bash
ls -R

This will list all the files and directories in the current directory and its subdirectories.

By using the various options with the “ls” command, you can customize the way you list the files in a directory and make it easier to find the files you need.