How to find the size of file in MB in UNIX command line?
|
|
If your
|
||||
|
|
|
I tend to use 'du -k myfile' to get kbytes and visually drop the last three digits, but I'm just looking for approximate size. Turns out that du often (always?) has -m option for MB. Keep in mind that how large the file likely differs slightly from the amount of diskspace used, as the disk allocation occurs in blocks, not bytes. If you are looking for 'fat' files because of low diskspace, that would be a more enlightening question, as the solutions would be more varied. |
||||
|
|
|
OR
EDIT this answer is wrong since it can report size also in Gb/Kb, depending on the file's size. Please remove upvotes. |
|||||||||||||
|
|
using -lh option will give you sizes in human readable form, e.g if your file is of size 1025 M it will output 1G,
otherwise you can use ls --block-size=1024K -s it will give size in nearest integer in MBs.
ls -l | awk '/d|-/{printf("%.3f %s\n",$5/(1024*1024),$9)}'
|
|||||
|
|
that give it to you in bytes. You can use bash's arithmetic to calculate the megabytes:
(but it rounds it down in this case) |
|||||||||||
|
|
You can use a tiny Python script:
|
||||
|
|