Tutorial: How to view a specific file size in a human readable format (Linux)
Linux users will most commonly use the command "ls -l" to display a list of the files in the current they are in. Sometimes even "ls -a -l" to display ALL files, including any hidden ones. This works just fine but sometimes you have files that are several hunder megabytes or even gigabytes. The "ls -l" command displays the file list with a size in "bytes". I don't know about you, but I am not a human calculator and it just turns into a long number that I have to translate to figure out how many megabytes or gigabytes the file may be.
I now introduce the command
du -h <filename>
With this command it will display the file you specifiy in a 'human readable" format. For example:
du – h file.tar.gz
This will return:
5.8G file.tar.gz
Now that's what I can a human readble file size! Check out the man page below for "du".
du man page
NAME
du – estimate file space usage
du [OPTION]… [FILE]…
DESCRIPTION
Summarize disk usage of each FILE, recursively for directories.
Mandatory arguments to long options are mandatory for short options too.
-a, –all
write counts for all files, not just directories
-B, –block-size=SIZE use SIZE-byte blocks
-b, –bytes
print size in bytes
-c, –total
produce a grand total
-D, –dereference-args
dereference FILEs that are symbolic links
-h, –human-readable
print sizes in human readable format (e.g., 1K 234M 2G)
-H, –si
likewise, but use powers of 1000 not 1024
-k
like –block-size=1K
-l, –count-links
count sizes many times if hard linked
-L, –dereference
dereference all symbolic links
-S, –separate-dirs
do not include size of subdirectories
-s, –summarize
display only a total for each argument
-x, –one-file-system
skip directories on different filesystems
-X FILE, –exclude-from=FILE
Exclude files that match any pattern in FILE.
–exclude=PATTERN Exclude files that match PATTERN.
–max-depth=N
print the total for a directory (or file, with –all) only if it is N or fewer levels below the command line argument; –max-depth=0 is the same as –summarize
–help
display this help and exit
–version
output version information and exit
