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?
22 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

- 18,356
- 16
- 68
- 108
-
8`ls` won't show you the total size of all contents of a directory. – Maxim Egorushkin Jun 23 '14 at 15:30
-
6how can I see the size in bytes (Mega, Giga,... ) ? – Francisco Corrales Morales Jul 22 '14 at 19:14
-
16@FranciscoCorralesMorales ls -lh will show you the size in kb MB GB etc. – Sandeep Aug 05 '15 at 03:25
-
7note that the `du` command shows the disk usage of the file, wich might be larger than the actual size of the file. You can use `du -d` to get the actual size as `ls` does. More info: https://unix.stackexchange.com/a/106278/155224 – Lucas Alonso Apr 19 '17 at 21:04
-
@mk.. `ls -l` will give u file size including the size of metadata? as it seems to be slightly 4kb bigger for one of file that i tried with – Jun Sep 13 '18 at 20:59
-
1@Jun No. Thats not metadata. `ls -l` generally shows 1 byte extra than the number of characters you see in the file. This extra character is generally a new line character. You can check it with `od -c
` In unix/Linux, a new line is stored at the end of each line. and the file will end with a new line(an empty file is an exception to this rule). In any case `od -c filename` will give you exact picture of what's in there.. – Sandeep Sep 18 '18 at 00:23 -
You can type du -d 1 -h | sort -h to get sorted outputs. – KocT9H Nov 21 '19 at 09:51
-
@LucasAlonso The command is acutally `du -b` (`-d` is for depth) – dCSeven May 20 '20 at 12:10
-
If your directory has just files and no directories, you can use this command: ```ls -FaGl
| awk '{ total += $4; print }; END { print total }'; }``` – Anmol Deep Jan 17 '22 at 11:46 -
@AnmolDeep if you want to know the total size of all the contents, just do `du -sh \`pwd\`` or do `du -sh
` from one level up. Knowing file sizes is a trivial operation and so we should be able to check them easily. – Sandeep Jan 18 '22 at 02:39 -
I work on a ubuntu-minimal cluster, here the du command is not available. – Anmol Deep Jan 19 '22 at 04:47
-
`ls -al *` will only give all files without a `.`, and files with a dot in subdirectorys. ls does not handle *; bash just says that * is all files without a . – jp_ Jul 16 '23 at 18:09
-
why not `ls -s`? – jp_ Jul 17 '23 at 13:23
There is du
command.
Size of an entire directory and/or file (-s
), with a total for multiple arguments (-c
), in a human-friendly way (-h
):
$ du -sch ~/.bashrc /tmp $XDG_RUNTIME_DIR
8.0K /home/max/.bashrc
358M /tmp
80K /run/user/1000
359M total
I memorised du -sch
as a German word dusch (English shower).
--apparent-size
command line switch makes it measure apparent sizes (what ls
shows) rather than actual disk usage.

- 131,725
- 17
- 180
- 271
-
4how can I see the size in bytes (Kilo, Mega, Giga,... ) ? – Francisco Corrales Morales Jul 22 '14 at 19:17
-
14@FranciscoCorralesMorales `-h` flag should do what you ask: _print sizes in human readable format (e.g., 1K 234M 2G)_ – Maxim Egorushkin Jul 22 '14 at 19:56
-
3I don't think this is right. What `du` does is _Summarize disk usage of the set of FILEs_ , that is if a file is very small (i.e. 2140 bytes) the output of "du" is (in my case) 4KB because that's the size of the cluster – mfloris Jun 20 '16 at 06:45
-
-
11I like `du -hs *` to see the size of all the files, and directories in the current directory. – Jordan Stewart Jan 20 '17 at 01:08
Use 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.

- 45,082
- 11
- 119
- 130
There is also a great ncdu
utility - it can show directory size with detailed info about subfolders and files.
Installation
Ubuntu:
$ sudo apt-get install ncdu
Usage
Just type 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

- 124,992
- 159
- 614
- 958

- 4,725
- 1
- 38
- 42
You can use:
ls -lh
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.

- 1,036
- 3
- 17
- 33

- 748
- 1
- 7
- 13
-
`ls -l` will give u file size including the metadata? as it seems to be slightly 4kb bigger for one of file that i tried with – Jun Sep 13 '18 at 20:58
Go to the chosen directory and execute:
$ du -d 1 -h
where:
-d 1 is the depth of the directories
-h is the human-readable option
You'll see like that:
0 ./proc
8.5M ./run
0 ./sys
56M ./etc
12G ./root
33G ./var
23M ./tmp
3.2G ./usr
154M ./boot
26G ./home
0 ./media
0 ./mnt
421M ./opt
0 ./srv
2.6G ./backups
80G .

- 3,743
- 1
- 26
- 27
File Size in MB
ls -l --b=M filename | cut -d " " -f5
File Size in GB
ls -l --b=G filename | cut -d " " -f5

- 3,447
- 2
- 21
- 22

- 2,162
- 4
- 24
- 36
-
-
1I recommend replacing repeating spaces with one with sed before using cut: ls -l filename | sed -E -e 's/ +/ /g' | cut -d " " -f5 – Israel Shainert Feb 02 '22 at 14:53
ls -l --block-size=M will give you a long format listing (needed to actually see the file size) and round file sizes up to the nearest MiB.
If you want MB (10^6 bytes) rather than MiB (2^20 bytes) units, use --block-size=MB instead.
If you don't want the M suffix attached to the file size, you can use something like --block-size=1M. Thanks Stéphane Chazelas for suggesting this.
This is described in the man page for ls; man ls and search for SIZE. It allows for units other than MB/MiB as well, and from the looks of it (I didn't try that) arbitrary block sizes as well (so you could see the file size as number of 412-byte blocks, if you want to).
Note that the --block-size parameter is a GNU extension on top of the Open Group's ls, so this may not work if you don't have a GNU userland (which most Linux installations do). The ls from GNU coreutils 8.5 does support --block-size as described above.

- 2,074
- 22
- 26
All you need is -l
and --block-size
flags
Size of all files and directories under working directory (in MBs)
ls -l --block-size=M
Size of all files and directories under working directory (in GBs)
ls -l --block-size=G
Size of a specific file or directory
ls -l --block-size=M my_file.txt
ls -l --block-size=M my_dir/
ls --help
-l
use a long listing format
--block-size=SIZE
: scale sizes bySIZE
before printing them; e.g.,'--block-size=M'
prints sizes in units of 1,048,576 bytes; seeSIZE
format below
SIZE
is an integer and optional unit (example: 10M is 10*1024*1024). Units are K, M, G, T, P, E, Z, Y (powers of 1024) or KB, MB, ... (powers of 1000).

- 36,235
- 20
- 134
- 156
If you are using it in a script, use stat
.
$ date | tee /tmp/foo
Wed Mar 13 05:36:31 UTC 2019
$ stat -c %s /tmp/foo
29
$ ls -l /tmp/foo
-rw-r--r-- 1 bruno wheel 29 Mar 13 05:36 /tmp/foo
That will give you size in bytes. See man stat
for more output format options.
The OSX/BSD equivalent is:
$ date | tee /tmp/foo
Wed Mar 13 00:54:16 EDT 2019
$ stat -f %z /tmp/foo
29
$ ls -l /tmp/foo
-rw-r--r-- 1 bruno wheel 29 Mar 13 00:54 /tmp/foo

- 66,273
- 12
- 162
- 149
You can use below command to get list of files in easily human readable format.
ls -lrtsh

- 438
- 5
- 5
You can use ncdu
disk usage analyzer here. It displays the size of the files and directories in an ncurses interface. You can navigate to each directory and see the files sizes from the same interface.
To install
$ sudo apt-get install ncdu
To analyze
$ ncdu <directory>

- 934
- 1
- 13
- 30
I do the following all the time:
$ du -sh backup-lr-May-02-2017-1493723588.tar.gz
NB:
-s, --summarize
display only a total for each argument
-h, --human-readable
print sizes in human readable format (e.g., 1K 234M 2G)

- 3,322
- 6
- 36
- 51
To get the total size of directory or the total size of file use,
du -csh <directory or filename*> | grep total

- 29,388
- 11
- 94
- 103

- 71
- 1
- 3
Use ls command with -h argument: [root@hots19 etc]# ls -lh
h : for human readable.
Exemple:
[root@CIEYY1Z3 etc]# ls -lh
total 1.4M
-rw-r--r--. 1 root root 44M Sep 15 2015 adjtime
-rw-r--r--. 1 root root 1.5K Jun 7 2013 aliases
-rw-r--r-- 1 root root 12K Nov 25 2015 aliases.db
drwxr-xr-x. 2 root root 4.0K Jan 11 2018 alternatives
-rw-------. 1 root root 541 Jul 8 2014 anacrontab
-rw-r--r--. 1 root root 55M Sep 16 2014 asound.conf
-rw-r--r--. 1 root root 1G Oct 6 2014 at.deny

- 2,025
- 1
- 16
- 14
I'm a Ubuntu 16.04 user myself and I find that the ll
command is by far the easiest way to see a directory's contents. I've noticed that not all Linux distributions support this command, but there's probably a workaround/install for each distro out there.
Example:
user@user-XPS-15-9560:/$ ll
total 188
drwxr-xr-x 27 root root 4096 Jan 26 09:13 ./
drwxr-xr-x 27 root root 4096 Jan 26 09:13 ../
drwxr-xr-x 2 root root 4096 Jan 22 15:13 bin/
drwxr-xr-x 4 root root 12288 Jan 29 11:35 boot/
drwxr-xr-x 2 root root 4096 Sep 3 18:14 cdrom/
drwxr-xr-x 20 root root 4440 Feb 5 08:43 dev/
drwxr-xr-x 153 root root 12288 Feb 2 15:17 etc/
drwxr-xr-x 4 root root 4096 Sep 3 18:15 home/
...
The biggest advantage for me is that it's quick and really intuitive to use.
UPDATE: what I didn't know was that on Ubuntu it's a pre-configured alias. You can easily set it yourself by executing alias ll="ls -la"
on the command line, or by adding this entry in your .bashrc config file:
sudo nano ~/.bashrc
...add line described above and save file by pressing Ctrl+X and Y...
source ~/.bashrc

- 97
- 2
- 11
ls -sh video.mp4 | sed s/video.mp4//g
output, 5.6M

- 409
- 5
- 13
-
1Could you please provide some context on why this answers the OP's question? For instance, explain what each command does. – António Ribeiro Jul 22 '20 at 14:22
-
-
2I was searching for the command to get exactly the size of the file which user input. And i found this stack useful. But, all commands given here displays the file name with it. So, as per my need i need only the size in output. like just `5.6M` So, i posted this, if anyone in same need may get helpful with this. `ls -sh video.mp4` to list the file size with the filename and i added `sed s/video.mp4//g` to replace the file name with empty. Ex : `sed s/$filename/empty/g` like that. Hope atleast someone will find it helpful who were in same need like mine. – Philip Jul 24 '20 at 05:59
You have to differenciate between file size and disk usage. The main difference between the two comes from the fact that files are "cut into pieces" and stored in blocks.
Modern block size is 4KiB, so files will use disk space multiple of 4KiB, regardless of how small they are.
If you use the command stat
you can see both figures side by side.
stat file.c
If you want a more compact view for a directory, you can use ls -ls
, which will give you usage in 1KiB units.
ls -ls dir
Also du
will give you real disk usage, in 1KiB units, or dutree with the -u
flag.
Example: usage of a 1 byte file
$ echo "" > file.c
$ ls -l file.c
-rw-r--r-- 1 nacho nacho 1 Apr 30 20:42 file.c
$ ls -ls file.c
4 -rw-r--r-- 1 nacho nacho 1 Apr 30 20:42 file.c
$ du file.c
4 file.c
$ dutree file.c
[ file.c 1 B ]
$ dutree -u file.c
[ file.c 4.00 KiB ]
$ stat file.c
File: file.c
Size: 1 Blocks: 8 IO Block: 4096 regular file
Device: 2fh/47d Inode: 2185244 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1000/ nacho) Gid: ( 1000/ nacho)
Access: 2018-04-30 20:41:58.002124411 +0200
Modify: 2018-04-30 20:42:24.835458383 +0200
Change: 2018-04-30 20:42:24.835458383 +0200
Birth: -
In addition, in modern filesystems we can have snapshots, sparse files (files with holes in them) that further complicate the situation.
You can see more details in this article: understanding file size in Linux

- 1,678
- 18
- 14
you can use ls -sh in linux you can do sort also you need to go to dir where you want to check the size of files

- 217
- 3
- 8
go to specific directory then run below command
# du -sh *
4.0K 1
4.0K anadb.sh --> Shell file
4.0K db.sh/ --> shell file
24K backup4/ --> Directory
8.0K backup6/ --> Directory
1.9G backup.sql.gz --> sql file

- 2,375
- 14
- 27