Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

linux command to get size of files and directories present in a particular folder? [closed]

Tags:

file

linux

How can I see the size of files and directories in Linux? If use df -m, then it shows the size of all the directory at the top level, but, for the directories and files inside the directory, how do I check the size?

like image 266
Advait Avatar asked Jul 30 '12 10:07

Advait


People also ask

How do you check the size of a specific folder in Linux?

To view the file size of a directory pass the -s option to the du command followed by the folder. This will print a grand total size for the folder to standard output. Along with the -h option a human readable format is possible.

How do you get the size of each directory within a directory Linux?

To get the total size of a directory in Linux, you can use the du (disk-usage) command.

What command can you use to display files and directories by file size?

Using the ls Command–l – displays a list of files and directories in long format and shows the sizes in bytes.

How the check the size of all files from a directory?

Right-click the file and click Properties. The image below shows that you can determine the size of the file or files you have highlighted from in the file properties window. In this example, the chrome. jpg file is 18.5 KB (19,032 bytes), and that the size on disk is 20.0 KB (20,480 bytes).


1 Answers

Use ls command for files and du command for directories.

Checking File Sizes

ls -l filename   #Displays Size of the specified file ls -l *          #Displays Size of All the files in the current directory ls -al *         #Displays Size of All the files including hidden files in the current directory ls -al dir/      #Displays Size of All the 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 Directory sizes

du -sh directory_name    #Gives you the summarized(-s) size of the directory in 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 human readable(-h) format 

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

For more information see man ls and man du

like image 177
Sandeep Avatar answered Sep 21 '22 21:09

Sandeep