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:

ADVERTISEMENTS

a] ls command – list directory contents.

Tutorial details
DifficultyEasy (rss)
Root privilegesNo
Requirementsls/du/stat
TimeLess than a one minute
b] du command – estimate file space usage.

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

Examples

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

Sample outputs:

-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
Sample outputs:

172K	/bin/grep

Finally, stat command also provide file size:
stat /bin/grep
Sample 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

Sample outputs:

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

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

See also
  • ls(1)
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig 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 jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
3 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.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.