How do I determine the total size of a directory (folder) from the command line?
The -h flag on sort will consider «Human Readable» size values.
If want to avoid recursively listing all files and directories, you can supply the —max-depth parameter to limit how many items are displayed. Most commonly, —max-depth=1
du -h --max-depth=1 /path/to/directory
I use du -sh or DOOSH as a way to remember it (NOTE: the command is the same, just the organization of commandline flags for memory purposes)
There is a useful option to du called the —apparent-size. It can be used to find the actual size of a file or directory (as opposed to its footprint on the disk) eg, a text file with just 4 characters will occupy about 6 bytes, but will still show up as taking up ~4K in a regular du -sh output. However, if you pass the —apparent-size option, the output will be 6. man du says: —apparent-size print apparent sizes, rather than disk usage; although the apparent size is usually smaller, it may be larger due to holes in (‘sparse’) files, internal fragmentation, indirect blocks
This works for OS X too! Thanks, I was really looking for a way to clear up files, both on my local machine, and my server, but automated methods seemed not to work. So, I ran du -hs * and went into the largest directory and found out which files were so large. This is such a good method, and the best part is you don’t have to install anything! Definitely deserved my upvote
@BandaMuhammadAlHelal I think there are two reasons: rounding ( du has somewhat peculiar rounding, showing no decimals if the value has more than one digit in the chosen unit), and the classical 1024 vs. 1000 prefix issue. du has an option -B (or —block-size ) to change the units in which it displays values, or you could use -b instead of -h to get the «raw» value in bytes.
Как посмотреть размер папки в Linux
Посмотреть занимаемое место конкретной директории на диске Linux получится через любой файловый менеджер. Достаточно открыть свойства файла. Но там информация отображается в кратком виде, а нередко нужны подробности. С помощью утилиты ls получить детальные сведения не получится. А вот утилита du для этих целей подойдет отлично.
В данной статье мы расскажем, как посмотреть размер папки в Linux с помощью du. Для этого разберем два примера ее использования.
Как посмотреть размер папки в Linux
Сначала мы опишем, как получить информацию об определенной папке, с учетом или без учета ее вложений. А потом перейдем к подпапкам в конкретном каталоге. Заодно упомянем несколько полезных нюансов работы с du, например, возможность сортировки данных.
1. Определённая папка
В качестве примера возьмем папку Downloads. Команда для вывода ее размера выглядит следующим образом:
sudo du -sh /home/root-user/Downloads
В результате выведется её занимаемое место на диске:
Второй полезный сценарий использования утилиты du заключается в выводе размера всех вложенных папок в определенной директории, без учета файлов внутри. Опять в качестве примера возьмем директорию Downloads. Вот нужная нам команда:
sudo du -h /home/root-user/Downloads
Выводы
В статье мы вкратце рассказали о том, как посмотреть размер папки в Linux и ее вложений с помощью утилиты du. Заодно упомянули возможность сортировки и другие важные нюансы. А если вам интересны еще сценарии использования du в терминале Linux, то ознакомьтесь с данной статьей. Там подробно разобран ее синтаксис, доступные опции и конкретные примеры.
Обнаружили ошибку в тексте? Сообщите мне об этом. Выделите текст с ошибкой и нажмите Ctrl+Enter.
Find the size of directory in unix
I am puzzled right now why I am getting that exception then as it clearly states above that I have space available.
What does that mean? Sorry I am not that much familiar with unix. Can you explain me what does that line means?
I believe the quota is how much space you’re allotted and diskspace consumed is how much you’ve used.
3 Answers 3
To see how much it uses now, but that you already saw.
To see how much total, free and used space is on the partition where /tmp resides you can use:
Note that filling up space is not the only thing that can prevent writing to filesystem.
Running out of inodes is another popular reason.
I got this error when I tried executing first command you gave me. bash-3.00$ du -sxh /tmp du: illegal option — x usage: du [-a] [-d] [-h|-k] [-r] [-o|-s] [-H|-L] [file . ] .
And with the third command you gave me, I am getting this exception- bash-3.00$ df -i /tmp df: unknown option: i Usage: df [-F FSType] [-abeghklntVvZ] [-o FSType-specific_options] [directory | block_device | resource] .
Which OS are you using? I was basing my answer on Linux, if you specify the OS I can give you the commands that will work on yours.
try this but it takes time if the size of dir is in GBs
Managing HDFS Space Quotas It’s important to understand that in HDFS, there must be enough quota space to accommodate an entire block. If the user has, let’s say, 200MB free in their allocated quota, they can’t create a new file, regardless of the file size, if the HDFS block size happens to be 256MB. You can set the HDFS space quota for a user by executing the setSpace-Quota command. Here’s the syntax:
$ hdfs dfsadmin –setSpaceQuota .
The space quota you set acts as the ceiling on the total size of all files in a directory. You can set the space quota in bytes (b), megabytes (m), gigabytes (g), terabytes (t) and even petabytes (by specifying p—yes, this is big data!). And here’s an example that shows how to set a user’s space quota to 60GB:
$ hdfs dfsadmin -setSpaceQuota 60G /user/alapati
You can set quotas on multiple directories at a time, as shown here:
$ hdfs dfsadmin -setSpaceQuota 10g /user/alapati /test/alapati