List of opened files Linux

Jiří Beneš
Jiří Beneš used Ask the Experts™
on
Hello guys,

is there any option to list all opened files in Linux without using lsof?

Thank you very much!

Regards

Jiri
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Seth SimmonsSr. Systems Administrator

Commented:
you could try by process

https://www.cyberciti.biz/faq/howto-linux-get-list-of-open-files/

what is wrong with lsof?
Jiří BenešIT Support

Author

Commented:
Well when we use lsof it gives back a lot of duplicities we would like to get only list opened files
David FavorFractional CTO
Distinguished Expert 2018

Commented:
Use lsof with grep or pass lsof options to prune output.

You can dig around in /proc + this is how lsof works, so you'll end up trying to duplicate a good big of lsof code.

Simple solution...

lsof | egrep " REG "

Open in new window


Add additional grep commands in your pipeline to prune additional data, till you have exactly what you're looking for.

You can also did into lsof + use lsof syntax (options) to do the same thing + I find lsof + grep pipelines way easier to read + understand.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Distinguished Expert 2017

Commented:
to see all files, one have to have elevated/root rights.
lsof /

the question does not reflect that everything on a linux system is seen as a "file"
an open socket is a "file" reference.
A definition of types of flies you are interested in seeing as David and Seth referenced.

Commonly, a question such as this suggests there is a discrepancy of drive space issues.
df -k points that a partion has all its space consumed (usage 100%)
while du -ks  on that partition reflects 40% of available space.
using lsof on the partiton will reveal the discrepancy as a running process that has a file handle in that location, but the file is no longer reflected within the file system listing, i.e. a logrotation, or other process was not set right, deleting the file entry without the notification to the process of the change. A low data process could take years to have this issue/impact show up.

lsof can run on per partition basis, per process basis, it all depends on what it is you are looking to achieve.

Qualifying your need might offer open opportunities one might not have considered before.
David FavorFractional CTO
Distinguished Expert 2018

Commented:
Arnold's comment is correct. If you're logged in as root at the machine level, you'll (for the most part) see all files + all files in all containers.

If you're inside a container, you'll only see files owned by that container.

Same with a non-root user (machine or container level).

You will only see files you have privilege to see.

Also, as Arnold suggested, provide the output of lsof + explain what's missing or how you'd like the output modified to be more useful + likely someone can assist.
Topic Advisor
Most Valuable Expert 2016
Commented:
You can filter what you see with lsof by using -c to specify a process name. You cannot filter for REGular files using an option, but you can filter using awk for example:

lsof -c bash | awk ' $5 == "REG" { print } '

This would show you all files opened by bash shell(s), filtering the output on the fifth column where it has "REG".

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial