1

I am looking for a command that would list me number of open files for each user, sorted descending.

For example lsof -u postgres | wc - would list them only for the postgres user, but I do want to see on which user I may loose handlers.

Note: some question may apply to PIDs instead of user names, but still, I am looking for a one liner.

1

If you are open to pipe's, how about this:

lsof | perl -pe 's/\s\s+/ /g' | cut -d' ' -f3 | grep -v ^USER | sort | uniq -c | sort -rn

I tested this on MacOS 10.10.2 (Yosemite), OEL 6.6, and Ubuntu 10.04.01.

| improve this answer | |
1

I ran Warren Lavallee's script, and found it difficult to interpret.

Instead, I extended the original script to step through all the users to give the following:-

for f in $(sed</etc/passwd 's/:.*$//g'); do ( echo -n $f ' '; lsof -u $f 2>/dev/null | wc -l ); done | grep -v ' 0$'

This works fine on Ubuntu 14.04. The final grep removes the zero entries, as a lot of the users will not have active processes. You can also add | sort -rnk 2 to the end of the command to sort into descending file count order.

You will need to be in a root shell to make sure you can see the files from all users.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.