ls -a Command

The ls -a command in Linux is used to list all files and directories, including those that are hidden. In Unix-like systems, files and directories whose names start with a dot (.) are considered hidden and are not displayed by default with the regular ls command.

Syntax

ls -a [OPTION]... [FILE]...

Description

The -a (or --all) option forces ls to show all entries, including the implicit entries representing the current directory (.) and the parent directory (..), as well as any other files or directories whose names begin with a dot.

Key aspects of ls -a:

  • Reveals configuration files (dotfiles) in your home directory.
  • Shows the . and .. entries, which represent the current and parent directories, respectively.
  • Essential for comprehensive file management and troubleshooting.

Common Options

Option Description
-l Use a long listing format (often combined with -a as -la).
-A, --almost-all Do not list implicit . and .. entries.
-h, --human-readable With -l, print sizes in human readable format (e.g., 1K, 234M, 2G).
-R, --recursive List subdirectories recursively.

Examples

List all files including hidden ones

ls -a
# Example Output: # . .. .bashrc .config file.txt my_directory

Displays all files and directories in the current location, including dotfiles and the . and .. entries.

Long listing of all files

ls -la

Combines the long listing format with the display of all files, providing detailed information for hidden files as well.

List almost all files (excluding . and ..)

ls -A
# Example Output: # .bashrc .config file.txt my_directory

Similar to -a, but omits the current directory (.) and parent directory (..) entries.

List hidden files in a specific directory

ls -a /home/user/

Displays all files, including hidden ones, within the /home/user/ directory.

See also