HowTo: Linux / Unix See File Size Command

I am a new Linux user. How do I find and list file sizes on Linux? How can I find out file size under Linux using bash shell/terminal prompt?

You can use any one of the following command line options to display file size on Linux or Unix-like operating systems:

a] ls command – list directory contents.

Tutorial details
Difficulty level Easy
Root privileges No
Requirements ls/du/stat
Est. reading time Less than a one minute
b] du command – estimate file space usage.

c] stat command – display file or file system status.


To determine the size of a file called /bin/grep, enter:

ls -l /bin/grep

Sample outputs:

-rwxr-xr-x 1 root root 175488 May 13  2012 /bin/grep

In the above output example, the 175488 is the size of the file. For a more user friendly output, pass the -h option to the ls command:

ls -lh /bin/grep

Here is what we see:

-rwxr-xr-x 1 root root 172K May 13  2012 /bin/grep

In the above output example, the 172K is the size of the file. The du command provides the same output in a more user friendly way and it hides all other details too:
du -h /bin/grep
Now du command reporting file size on screen:

172K	/bin/grep

Finally, stat command also provide file size:
stat /bin/grep
Linux stat command outputs:

stat /bin/grep 
  File: `/bin/grep'
  Size: 175488    	Blocks: 344        IO Block: 4096   regular file
Device: 900h/2304d	Inode: 5505033     Links: 1
Access: (0755/-rwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2013-06-10 01:31:37.520022359 +0530
Modify: 2012-05-13 18:17:28.000000000 +0530
Change: 2013-05-17 02:16:17.138033825 +0530

The following commands are executed on Apple OS X Unix operating systems to file out the file size of the /usr/bin/vim binary file:
$ ls -l /usr/bin/vim
$ ls -lh /usr/bin/vim
$ stat -x /usr/bin/vim

Fig.01: Finding out file size using various command line options on OS X Unix OS

Summing up

You learned different Linux and Unix commands to display file size using the command-line option. You need to type these commands using the terminal application. One can execute them over remote ssh session too, using the ssh command:

## [1] first login to remote ec2 cloud server ##
## [2] now show file size for /etc/hosts
ls -l /etc/hosts
du -h /etc/hosts
stat /etc/hosts
## [3] OR we can run command directly with ssh ##
ssh ls -l /etc/passwd
ssh ls -l -- /etc/passwd

Finding file size using ssh command over the remote session (cloud server)

The double dash “--” means “end of command line options (flags)”. In other words, it tells ssh command (or any other valid Linux, macOS/BSD commands) not to try to parse what comes after command line options. See “What Does — (double dash) Mean In SSH Shell Command?” for more info. See the following man pages using the man command:
man du
man ls
man stat
man bash
man zsh
man ksh

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 5 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
5 comments… add one
  • Pranab kumar Das Apr 5, 2014 @ 11:17

    Very Helpfull !! Thanks a lot !!!

  • Yugo Jun 11, 2015 @ 11:12

    Thanks, made my day!

  • wilson Oct 21, 2015 @ 12:19

    Good stuff keep up.Many thanks.

  • Esmond Pearce May 4, 2021 @ 10:07

    I wanted to know how can we check the file size in Linux commands. I finally ended up doing:

    var=$(du -h /etc/passwd | awk '{ print $1}')
    echo $var

    Is this the best way to do it on Red Hat Enterprise Linux 7 server?

    • Ralph May 4, 2021 @ 10:11

      How about?

      var="$(stat -c "%s" /etc/passwd)"
      printf "Total file size in bytes: %s\n" "$var"

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum