I recently had to delete and recreate an NFS directory to shrink its size after it had previously bloated. In the process, I found a fairly efficient way to do this using rsync and hard links. This method avoids copying the actual files, while still accomplishing the goal of recreating the directory with the same contents. 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.
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?
It's simple. Use ls
command for files and du
command for directories.
Checking File Sizes
ls
command will not list the actual size of directories(why?). Therefore, we use du
for this purpose.
Checking Directory sizes
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
There is du
command.
Size of a directory and/or file:
--apparent-size
command line switch makes it measure apparent sizes (what ls
shows) rather than actual disk usage.
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.
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.
There is also a great ncdu
utility - it can show directory size with detailed info about subfolders and files.
Ubuntu:
Just type ncdu [path]
in the command line. After a few seconds for analyzing the path, you will see something like this:
Delete the currently highlighted element with d, exit with CTRL + c
Martin Thomals -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.
You can use below command to get list of files in easily human readable format.
ls -lrtsh
To get the total size of directory or the total size of file use,
Suraj RaoIf you are using it in a script, use stat
.
That will give you size in bytes. See man stat
for more output format options.
The OSX/BSD equivalent is:
Bruno BronoskyBruno BronoskyYou 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.
If you want a more compact view for a directory, you can use ls -ls
, which will give you usage in 1KiB units.
Also du
will give you real disk usage, in 1KiB units, or dutree with the -u
flag.
Example: usage of a 1 byte file
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
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:
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:
Use ls command with -h argument: [root@hots19 etc]# ls -lh
h : for human readable.
Go to the chosen directory and execute:
where:
You'll see like that:
you can use ls -sh in linux you can do sort alsoyou need to go to dir where you want to check the size of files
This question already has an answer here:
I have a website on my server and I own it.
The size of the website is around a whopping 170GB. This shouldn't be this much. At most, it should be around 20GB. I don't know what makes it that big.
I am trying to figure out which directory has such a large size, but I am not able too.
I checked the DB size and it is around 500 MB.
Please help me to find out the main directory responsible for this.
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Under any linux system, you want to use the command du
. (Disk Usage)
Sniper fury controls windows 10. Common usage is : du -sh file(s) name(s)
or du -sh /path/to/dir/*
-s
stand for 'summary' which will give you the size of each argument instead of detailing th size of each elements of the file tree underneath.
Replace 'h' by 'k','m' or 'g' for Kilobytes, Megabytes and Gigabytes instead of human-readable. With k/m/g switches, you can then pipe the output to sort -n
(numeric sort instead of lexicographic) to get the sorted by size list of files in a directory. sort
even has a -h
filter on latest versions.
If you still have a big difference, you may want to try the --apparent-size
switch to du
which will allow you to diagnose sparse files. (files with empty space inside, to be simple)
For more information, see the manual page of du