ls -s Command

The ls -s command in Linux is used to display the allocated size of each file in blocks. This can be useful for understanding the actual disk space consumed by files, which might differ from their apparent size due to filesystem block allocation.

Syntax

ls -s [OPTION]... [FILE]...

Description

The -s (or --size) option tells ls to print the size of each file in blocks before its name. The block size used by ls is typically 1KB (1024 bytes), but this can vary depending on the system and filesystem configuration. It's important to note that this is the *allocated* size, not necessarily the exact byte size of the file content.

Key aspects of ls -s:

  • Shows disk space allocated, not just file content size.
  • Useful for identifying files consuming more disk space than expected.
  • Often combined with -h for human-readable output.
  • Can be combined with -l for a detailed long listing including block size.

Common Options (with -s)

Option Description
-h, --human-readable With -l, print sizes in human readable format (e.g., 1K, 234M, 2G).
-l Use a long listing format (often combined with -s as -ls or -lsh).
-S Sort by file size, largest first (default for -S).
-r Reverse order while sorting.

Examples

Display file sizes in blocks

ls -s
# Example Output: # total 8 # 4 file1.txt 4 file2.log

Shows the size of each file in blocks (e.g., 4 blocks for each file).

Display file sizes in human-readable format

ls -sh
# Example Output: # total 8.0K # 4.0K file1.txt 4.0K file2.log

Combines -s with -h for easier-to-read sizes.

Long listing with human-readable block sizes

ls -lsh

Provides a detailed long listing, including file permissions, ownership, and human-readable block sizes.

Sort by size (largest first) and show blocks

ls -sS

Lists files sorted by size (largest first), showing their block usage.

See also