We help IT Professionals succeed at work.

List of opened files Linux

238 Views
Last Modified: 2017-12-11
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

Seth SimmonsLead Systems Administrator
CERTIFIED EXPERT

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
CERTIFIED EXPERT
Distinguished Expert 2019

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.
CERTIFIED EXPERT
Distinguished Expert 2019

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
CERTIFIED EXPERT
Distinguished Expert 2019

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
CERTIFIED EXPERT
Most Valuable Expert 2016
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions