« Back to File systems: Frequently Asked Questions

How to see the size of a file

How to see the size of a file on Linux?

Run the ls or stat command to see file size information.

ls -l /path/to/file

The ls command is the default command to see basic file properties, such as its name, ownership, file permissions, and file size. When using the -l the long listing format is used to see the details.

Showing file properties

# ls -l /etc/passwd
-rw-r--r-- 1 root root 1993 Feb  2  2024 /etc/passwd

When a file is more than a megabyte, it may help to use the --human-readable option. It show the size with a corresponding character (k=kilobyte, m=megabyte, g=gigabyte).

An alternative option is using the stat command. It will provide additional details in its default output, such as the initial creation date and inode.

# stat /etc/passwd
  File: /etc/passwd
  Size: 1993      	Blocks: 8          IO Block: 4096   regular file
Device: fd00h/64768d	Inode: 132674      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2024-11-10 19:17:01.327124248 +0000
Modify: 2024-02-02 19:14:45.316650111 +0000
Change: 2024-02-02 19:14:45.320650046 +0000
 Birth: 2024-02-02 19:14:45.316650111 +0000

Relevant commands in this article

Like to learn more about the commands that were used in this article? Have a look, for some there is also a cheat sheet available.

  • ls
  • stat

Other questions related to Linux file systems

Related articles

Like to learn more? Here is a list of articles within the same category or having similar tags.

Feedback

Small picture of Michael Boelen

This article has been written by our Linux security expert Michael Boelen. With focus on creating high-quality articles and relevant examples, he wants to improve the field of Linux security. No more web full of copy-pasted blog posts.

Discovered outdated information or have a question? Share your thoughts. Thanks for your contribution!

Mastodon icon