How to get file/folder size with SSH on linux?

32

9

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?

fazpas

Posted 2010-06-22T21:13:16.050

Reputation: 1 353

Answers

39

use the du command

du -m filename

radius

Posted 2010-06-22T21:13:16.050

Reputation: 1 301

29If you use du -h instead, it'll chose (and print) the appropriate units. – Dentrasi – 2010-06-22T21:28:27.487

11If you use du -ms folder, it will report the size of the folder contents. – KeithB – 2010-06-22T21:35:49.780

1@TheBlackBenzKid wc -c – AbsoluteƵERØ – 2016-11-14T17:56:42.627

1Is there a way where we can see the units - example mb, kb or any other information? – TheBlackBenzKid – 2013-03-25T09:58:40.547

19

 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 

Abdalla Mohamed Aly Ibrahim

Posted 2010-06-22T21:13:16.050

Reputation: 341

1much better than accepted solution – zookastos – 2017-08-30T05:50:01.017

du -sh /yourpath/* to list all directories in a given path and summarized sizes of their contents – Fanky – 2019-10-07T08:31:21.383

10

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

ncdu_screenshot

Daenyth

Posted 2010-06-22T21:13:16.050

Reputation: 5 742