Gestionarea discului

Find Disk Space Used by Specific User Linux

Find Disk Space Used by Specific User Linux
Once in a while, you may need to take stock of the files owned by a specific user in a Linux system with several login users. This comes in handy when you want to free up some space and prevent your hard drive from getting depleted.  This is especially if some users have long since stopped using the system and their accounts have been disabled. So, how do you evaluate the disk space taken up by a specific user? Let's find out.

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:

$ find /path/to/directory/ -user username_whose_files_are_to_be_counted -type f -printf "%s\n" | awk 't+=$1ENDprint t'

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+=$1ENDprint 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.

$ find /home  -user james -type f -printf "%s\n" | awk 't+=$1ENDprint t'

If you are inside a directory, you can view the disk usage using the command shown,

$ find . -type f -printf "%u %s\n" \ | awk 'user[$1]+=$2; ENDfor(i in user) print i,user[i]'

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.

OpenTTD vs Simutrans
Creating your own transport simulation can be fun, relaxing and extremely enticing. That's why you need to make sure that you try out as many games as...
OpenTTD Tutorial
OpenTTD is one of the most popular business simulation games out there. In this game, you need to create a wonderful transportation business. However,...
SuperTuxKart for Linux
SuperTuxKart is a great title designed to bring you the Mario Kart experience free of charge on your Linux system. It is pretty challenging and fun to...