Home > File & Directory Management > ls

ls: List files and directories in detail (-l option focus)

ls is the most basic command in Linux for listing files and directories. The -l option, in particular, is essential for system administration and file analysis as it outputs detailed information such as file permissions, owner, group, size, and last modification time in a long format. This guide focuses on the usage of the -l option with the ls command.

Overview

ls -l displays file system entries in detail, helping to grasp the attributes of each item at a glance. This is useful for checking security settings, disk usage, recent changes, and more.

Key Features

The key information obtainable through the ls -l option is as follows:

  • View detailed permissions for files and directories
  • Display file owner and group information
  • Check file size and last modification time
  • Show the number of hard links

Key Options

These are commonly used options with the ls command. They are particularly useful when combined with the -l option.

Display/Format

Generated command:

Try combining the commands.

Description:

`ls` Executes the command.

Combine the above options to virtually execute commands with AI.

Usage Examples

Various usage examples of the ls -l option.

View detailed list of the current directory

ls -l

The most basic usage of ls -l, which displays detailed information about files and directories in the current directory.

View detailed list with human-readable sizes

ls -lh

Adds the -h option to display file sizes in K, M, G units for improved readability.

View detailed list including hidden files

ls -la

Adds the -a option to display hidden files and directories starting with a dot (.) in detail.

View detailed list of a specific directory

ls -l /var/log

Displays detailed information about files and directories in the specified path.

View detailed list sorted by last modified time

ls -lt

Adds the -t option to list files sorted by their last modification time, from newest to oldest.

Tips & Notes

The output of ls -l contains a lot of important information, so understanding the meaning of each field is crucial.

Explanation of ls -l output fields

The information represented by each column in the ls -l command output is as follows:

  • First character: File type (d: directory, -: regular file, l: symbolic link, c: character device, b: block device, p: named pipe, s: socket)
  • Next 9 characters: File permissions (read(r)/write(w)/execute(x) permissions for owner/group/others, respectively)
  • Third field: Number of hard links (for directories, this includes the number of subdirectories + 2)
  • Fourth field: File owner's username
  • Fifth field: File group name
  • Sixth field: File size in bytes (human-readable with -h option)
  • Seventh field: Last modification month, day, time (or year)
  • Last field: File or directory name

Usage Tips

ls -l can be combined with other commands to achieve powerful functionalities.

  • The output of ls -l is often used with pipes (|) to filter or sort specific information by combining it with other commands like `grep`, `awk`, `sort`, etc.
  • To check the total block usage of a directory, refer to the `total` value in the first line of the `ls -l` output.

Same category commands