1

I am a non admin user of a linux server, where multiple users/employees store data. When we run out of disk space (i.e. when we notice data transfer failure etc..), someone of us runs a df command to determine that there is an actual lack of space:

df -h /store/*

This is followed by a du command to determine top users, which are then "requested" publicly to optimize their usage:

du -hs /store/dir1 | sort -h

Now, on another server (say newstore, where we usually didn't have issues until now!) we have multiple directory structures within the same "appliance/cluster", which necessitates multiple runs of du

du -hs /newstore/dir1 | sort -h
du -hs /newstore/dir2/levelchange | sort -h
du -hs /newstore/dir3/new/old | sort -h

Then I copy the output to excel and "stitch" together a userwise view. I'm looking for a simpler solution.

This process has to be done by a non-admin user with standard privileges (as admin is remote and frankly we won't know her/him); thus it would not be possible to install additional programs.

I'm looking for a solution where, I can get information storage used by each user/owner, aggregated across the multiple directories, where I would just specify the top level directory (In this case /newstore).

Linux version of server: Red Hat Enterprise Linux

Edit 1: Each directory has a user as owner, one user may have multiple directories.

4
  • 1
    Could you check your commands? There isn't much to sort after a du -hs /newstore/dir1. Or maybe show part of the output? Apr 1, 2020 at 19:24
  • I'm looking for directory ownership wise aggregate disk usage by each user. Using du I've to do it one directory at a time and then add manually.
    – DS R
    Apr 1, 2020 at 19:26
  • Yes, what I mean is that those du commands you posted should return a single line, why would you sort that? And it is not very clear (to me) how you tie that to specific users. Or does each user own one of the dir1/dir2/...? Apr 1, 2020 at 19:29
  • @Eduardo Thanks for your comments, I've made an edit to clarify. Yes, each directory is owned by a particular user, but there could be multiple levels as I show in the edited example above.
    – DS R
    Apr 1, 2020 at 19:42

1 Answer 1

1

Try (for each user):

find $topdir -type d -user $user -print0 | du -hsc --files0-from -

In slo-mo

  • find $topdir -type d -user $user -print0 produces a null-terminated list of directories owned by $user
  • this list is piped to du
  • --files0-from makes du compute the size of null-separated files read from stdin (-)

You can make it easier to spot the troublesome directories by sorting the output:

find $topdir -type d -user $user -print0 | du -msc --files0-from - | sort -n
2
  • Thanks for this, I will now create a loop in shell script, where your command would loop over usernames
    – DS R
    Apr 2, 2020 at 9:20
  • Upvoting is nice, accepting is even better (marks the question as answered).
    – xenoid
    Apr 2, 2020 at 9:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .