Управління дисками

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.

Remap your mouse buttons differently for different software with X-Mouse Button Control
Maybe you need a tool that could make your mouse's control change with every application that you use. If this is the case, you can try out an applica...
Microsoft Sculpt Touch Wireless Mouse Review
I recently read about the Microsoft Sculpt Touch wireless mouse and decided to buy it. After using it for a while, I decided to share my experience wi...
AppyMouse On-screen Trackpad and Mouse Pointer for Windows Tablets
Tablet users often miss the mouse pointer, especially when they are habitual to using the laptops. The touchscreen Smartphones and tablets come with m...