Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unix command to check the filesize

Tags:

unix

I need to check the display the files my server with their sizes.Which command that I need to use. Any variants of ls command?

like image 887
Van Avatar asked Sep 15 '14 09:09

Van


People also ask

How do I check the size of a file in Unix?

don't worry we have a got a UNIX command to do that for you and command is "df" which displays the size of the file system in UNIX. You can run "df" UNIX command with the current directory or any specified directory.

How do you check file size in Linux?

Using the ls Command –l – displays a list of files and directories in long format and shows the sizes in bytes. –h – scales file sizes and directory sizes into KB, MB, GB, or TB when the file or directory size is larger than 1024 bytes. –s – displays a list of the files and directories and shows the sizes in blocks.

How do you check file size?

Locate the file or folder whose size you would like to view. Click the file or folder. Press Command + I on your keyboard. A window opens and shows the size of the file or folder.

How do I check the size of a file in Unix?

How to check file size in unix using wc command. The wc command shows the number of lines, words, and bytes contained in file. The syntax is as follows to get the file size: wc -c /path/to/file. wc -c /etc/passwd. Sample outputs:

How do I get the size of a file in Bash?

I am a new bash shell scripting user. How do I find out the size of a file in my bash shell script and store this file size in a bash shell variable? You can not get the size of a file in a bash script using an internal or built-in command. It would be best to use the stat and other commands under Linux to check the file size.

How do you measure the size of a file?

Two measurements are used in relation to file size. The first is the actual size of the file, which is the number of bytes of content that make up the file. The second is the effective size of the file on the hard disk. This is the number of file system blocks necessary to store that file.

What is a a file in Linux?

A file doesn’t include only text files, images, and compiled programs but also includes partitions, hardware device drivers, and directories. The following Linux commands can be used to check file size.


3 Answers

I hope ls -lah will do the job. Also if you are new to unix environment please go to http://www.tutorialspoint.com/unix/unix-useful-commands.htm

like image 146
Chanthu Avatar answered Oct 06 '22 20:10

Chanthu


stat -c %s file.txt

This command will give you the size of the file in bytes. You can learn more about why you should avoid parsing output of ls command over here: http://mywiki.wooledge.org/ParsingLs

like image 27
Parth Shah Avatar answered Oct 06 '22 19:10

Parth Shah


ls -l --block-size=M 

will give you a long format listing (needed to actually see the file size) and round file sizes up to the nearest MiB. If you want MB (10^6 bytes) rather than MiB (2^20 bytes) units, use --block-size=MB instead.

Or

ls -lah 

-h When used with the -l option, use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte in order to reduce the number of digits to three or less using base 2 for sizes.

man ls

http://unixhelp.ed.ac.uk/CGI/man-cgi?ls

like image 17
Zack Kaytranada Avatar answered Oct 06 '22 19:10

Zack Kaytranada