Avatar of Jiří Beneš
Jiří Beneš
 asked on

List of opened files Linux

Hello guys,

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

Thank you very much!

Regards

Jiri
Linux* CentOSLinux Distributions

Avatar of undefined
Last Comment
Gerwin Jansen

8/22/2022 - Mon
Seth Simmons

you could try by process

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

what is wrong with lsof?
Jiří Beneš

ASKER
Well when we use lsof it gives back a lot of duplicities we would like to get only list opened files
David Favor

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.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
arnold

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 Favor

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.
ASKER CERTIFIED SOLUTION
Gerwin Jansen

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question