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
LVL 1
Jiří BenešIT SupportAsked:
Who is Participating?
 
Gerwin Jansen, EE MVEConnect With a Mentor Topic Advisor 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".
0
 
Seth SimmonsSr. Systems AdministratorCommented:
you could try by process

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

what is wrong with lsof?
0
 
Jiří BenešIT SupportAuthor Commented:
Well when we use lsof it gives back a lot of duplicities we would like to get only list opened files
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
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.
0
 
arnoldCommented:
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.
0
 
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.