Общее использование диска для конкретного пользователя

42303
Alex

Я хотел бы видеть общее использование диска для себя в определенной файловой системе. Я выполнил команду

du -h ~my_user_name 

Однако в этом списке перечислены все каталоги, которыми владеет my_user_name. Я хотел бы получить общую сумму всей этой информации. Какой вариант подходит для прохождения? Я старался

du -h -c ~my_user_name 

но это не сработало.

8

2 ответа на вопрос

10
Ignacio Vazquez-Abrams

Passing -s to du will restrict the output to only the items specified on the command line.

du -sh ~ 
8
Hennes

Du will only show you the totals per folder, not per user.

That might work if you want the total size of, say, /home/example_user/ and if only that example_user has files in that folder. If other users have files in them then this will not yield size of all files owned by you, but the total size of all files in that folder.

To get the information per user, either:

  1. If you have quota's enabled, use those commands.
  2. Use find to walk though all the directories you want to count your files in. Use the uid to only select your files and keep an associative array in awk to count the totals.

find /path/to/search/ -user username_whos_files_to_count -type f -printf "%s\n" | awk 'END'

Note, this uses a GNU find specific extension.

  • The first command searches past all files and directories in /path/to/search.
  • -type f makes sure you only select files, otherwise you are also counting the size of directories. (Try making an empty folder. It will probably use 4k diskspace).
  • -user username_whos_files_to_count only selects the results from one user
  • -printf "%s\n" will print the size.

If you just run the first part of this, you will get a list of numbers. Those are the file sizes. (Everything else is stripped, only the size is printed thanks to the %s print command.)

We can then add all those numbers to get a summary. In the example, this is down with awk.

+1 хороший момент, спасибо! ответ ниже на самом деле был именно то, что я хотел. различие между пользователем и папкой не имеет большого значения в моем случае Alex 10 лет назад 0
Ницца. `du -sch` - простая команда, часто используемая. Отследить, кому что принадлежало, когда все было смешано, намного сложнее, хотя это можно сделать в один прием. Я использовал это однажды, но у меня были проблемы с реконструкцией сегодня. Hennes 10 лет назад 0
Мне очень помогло, Идеальное объяснение Babin Lonston 10 лет назад 0