Count the total disk space used by a particular user
To obtain the disk space used by a specific user, use the find command syntax as follows:
Let’s break down this command syntax:
The first section – find /path/to/directory/ – performs a search in the specified directory path.
The second section – -user username_whose_files_are_to_be_counted – restricts the search operation to a specific user only.
The third section – -type f – indicates that we are only searching for files and not directories. Empty directories usually take up 4kb, which is negligible.
The last section – -printf “%s\n” | awk ‘{t+=$1}END{print t}’
Prints out the size of the files.
Suppose you want to find out the disk usage of a user called james in the home directory. The command will be.
If you are inside a directory, you can view the disk usage using the command shown,
For example, I will navigate to the Downloads directory, located in my home directory, and check the disk space used by specific users. The output clearly displays the disk space summary where two users have files saved in the current directory, which is the /home/james/Downloads directory.
And there you go. We have successfully seen how you can find the disk space by specific users in Linux.