37

I am using SSH to connect to a CentOS server and I want to get the file in mb of some files and folders, how can I do it?

3 Answers 3

43

use the du command

du -m filename
4
  • 30
    If you use du -h instead, it'll chose (and print) the appropriate units.
    – Dentrasi
    Jun 22, 2010 at 21:28
  • 11
    If you use du -ms folder, it will report the size of the folder contents.
    – KeithB
    Jun 22, 2010 at 21:35
  • 1
    Is there a way where we can see the units - example mb, kb or any other information? Mar 25, 2013 at 9:58
  • 1
    @TheBlackBenzKid wc -c Nov 14, 2016 at 17:56
24
 du -msh FolderName 

will get the size with units. Unlike using -h, this will show a single size, while -h shows all the individual files within the folder.
e.g.

349M    FolderName 
2
  • 2
    much better than accepted solution
    – zookastos
    Aug 30, 2017 at 5:50
  • du -sh /yourpath/* to list all directories in a given path and summarized sizes of their contents
    – Fanky
    Oct 7, 2019 at 8:31
13

du is the primary tool for this, but if you're looking for something more interactive, I quite like ncdu

ncdu_screenshot

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .