How can I see the memory occupied by a file and folder and also entire directory from terminal?

I'm having some files and folders in the "My Documents" directory. What are the commands to see the size of a file and directory in a terminal?


Solution 1:

This will summarise the sizes of the directories:

du -h

PS: Although all computer storage is technically "memory", this term is usually reserved for non-persistent storage like RAM and CPU cache.

Solution 2:

To see the full size (including whole content) of a folder in a directory, use the command

du -hs YOUR_FOLDER_NAME

To see the full size (including whole content) of all folders and files in a directory, use the command

ls | xargs -I fileorfolder du -hs fileorfolder

Solution 3:

Try these commands,

cd ~/Documents
ls -shR