Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Linux by (18.4k points)
retagged by
How can I see these sizes of files and directories in Linux? I  have used the df -m, then it shows the size of all these directories at the top level, but, for these directories and files inside the directory, how do I check the size?

1 Answer

0 votes
by (36.8k points)

Use the ls command for files and the du command for directories.

Checking File Sizes

ls -l filename   #Displays Size of this specified file

ls -l *          #Displays Size of All these files in the current directory

ls -al *         #Displays Size of All these files including hidden files in the current directory

ls -al dir/      #Displays Size of All these files including hidden files in the 'dir' directory

ls command will not list the actual size of directories(why?). Therefore, we use du for this purpose.

Checking the Directory sizes

du -sh directory_name    #Gives you the summarized(-s) size of the directory in the human-readable(-h) format

du -bsh *                #Gives you the apparent(-b) summarized(-s) size of all the files and directories in the current directory in the human-readable(-h) format

Including -h option in any of the above commands (for Ex: ls -lh * or du -sh) will give you the size in the human-readable format (kb, mb,gb, ...)

For more information see man ls and man du

Want to be a Linux expert? Come and join this linux course

Related questions

0 votes
0 answers
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...