How can I see the size of files and directories in 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?
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
-h option in any of the above commands (for Ex:
ls -lh * or
du -sh) will give you size in human readable format (
For more information see
man ls and
Read more… Read less…
Size of a directory and/or file:
$ du -sh .bashrc /tmp
--apparent-size command line switch makes it measure apparent sizes (what
ls shows) rather than actual disk usage.
ls -s to list file size, or if you prefer
ls -sh for human readable sizes.
For directories use
du, and again,
du -h for human readable sizes.
You can use:
Using this command you'll see the apparent space of the directory and true space of the files and in details the names of the files displayed, besides the size and creation date of each.
There is also a great
ncdu utility - it can show directory size with detailed info about subfolders and files.
$ sudo apt-get install ncdu
ncdu [path] in the command line. After a few seconds for analyzing the path, you will see something like this:
$ ncdu 1.11 ~ Use the arrow keys to navigate, press ? for help --- / --------------------------------------------------------- . 96,1 GiB [##########] /home . 17,7 GiB [# ] /usr . 4,5 GiB [ ] /var 1,1 GiB [ ] /lib 732,1 MiB [ ] /opt . 275,6 MiB [ ] /boot 198,0 MiB [ ] /storage . 153,5 MiB [ ] /run . 16,6 MiB [ ] /etc 13,5 MiB [ ] /bin 11,3 MiB [ ] /sbin . 8,8 MiB [ ] /tmp . 2,2 MiB [ ] /dev ! 16,0 KiB [ ] /lost+found 8,0 KiB [ ] /media 8,0 KiB [ ] /snap 4,0 KiB [ ] /lib64 e 4,0 KiB [ ] /srv ! 4,0 KiB [ ] /root e 4,0 KiB [ ] /mnt e 4,0 KiB [ ] /cdrom . 0,0 B [ ] /proc . 0,0 B [ ] /sys @ 0,0 B [ ] initrd.img.old @ 0,0 B [ ] initrd.img @ 0,0 B [ ] vmlinuz.old @ 0,0 B [ ] vmlinuz
Delete the currently highlighted element with d, exit with CTRL + c
File Size in MB
ls -l --b=M filename | cut -d " " -f5
File Size in GB
ls -l --b=G filename | cut -d " " -f5