HowTo: Linux / Unix See File Size Command

by on June 9, 2011 · 1 comment· LAST UPDATED June 9, 2013

in , ,

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
DifficultyEasy (rss)
Root privilegesNo
Requirementsls/du/stat
Estimated completion 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
TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 1 comment… read it below or add one }

1 Pranab kumar Das April 5, 2014 at 11:17 am

Very Helpfull !! Thanks a lot !!!

Reply

Leave a Comment

Tagged as: , , ,

Previous Faq:

Next Faq: