How Do I See Open Files in Linux?
Contents

How can I see what process has a file open?

Using lsof to display the processes using the most file handles

  1. lsof – Run the lsof to display all open files and send output to the awk.
  2. awk ‘{print $1}’ – Display first field i.e. process name only.
  3. uniq -c – Omit duplicate lines while prefix lines by the number of occurrences.
  4. sort -r – Reverse sort.

27 авг. 2020 г.

How do I close all open files in Linux?

If you want to find only close the open file descriptors, you can use the proc filesystem on systems where it exists. E.g. on Linux, /proc/self/fd will list all open file descriptors. Iterate over that directory, and close everything >2, excluding the file descriptor that denotes the directory you are iterating over.

Robert Thorne

Robert Thorne

Automotive & Future Transportation Editor

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.

Share this article
Twitter Facebook Pinterest