There might be a switch, but if you don't mind filtering it through grep, you could do sudo lsof | egrep 'REG|DIR' , assuming by "physical files" you mean regular files and directories.
See the OUTPUT :: TYPE section of the man page man lsof for all the types that might be in that column.
The -F n option to lsof will cause it to only print out the names of the open files. Each output line that has the name of an open file will start with the single character n followed immediately by the name. Regular files will always be the absolute, fully-qualified name of the file. The grep ^n/ will select only those lines with a name starting with a / (meaning an absolute, fully-qualified file name); thus eliminating things like open ports, sockets, pipe (like FIFOs), etc. The cut -c2- will eliminate the first character, the n, leaving only the file name. Then finally, the sort -u will eliminate any duplicate entries.
One caveat, this will include files that are not regular as long as their name starts with a /. For example, all files starting with the following would be included:
If you use lsof / it will just list open files on filesystems mounted DIRECTLY under / - that is, if you have /home mounted under /, its contents will be ignored. I tried various combination of options for lsof, but all had problems. The best I could come up is this:
lsof `readlink -f /dev/block/*`
This uses readlink -f to get all block devices and feed them as a list to search. lsof ignores the ones that are not mounted.
If you have any other options to limit the search, for instance a pid, remember to end the lsof command with an -a to AND them with the list of block devices:
Just looked through some man pages, it appears you use the command:
This will list all open files in the / directory, which is everything on a Linux filesystem. Just tested and it shows only REG and DIR.
More examples:
0-999 limits it to files with a file descriptor number.
There might be a switch, but if you don't mind filtering it through grep, you could do
sudo lsof | egrep 'REG|DIR'
, assuming by "physical files" you mean regular files and directories.See the OUTPUT :: TYPE section of the man page
man lsof
for all the types that might be in that column.This is what I did which worked perfectly for me:
The
-F n
option tolsof
will cause it to only print out the names of the open files. Each output line that has the name of an open file will start with the single character n followed immediately by the name. Regular files will always be the absolute, fully-qualified name of the file. Thegrep ^n/
will select only those lines with a name starting with a/
(meaning an absolute, fully-qualified file name); thus eliminating things like open ports, sockets, pipe (like FIFOs), etc. Thecut -c2-
will eliminate the first character, then
, leaving only the file name. Then finally, thesort -u
will eliminate any duplicate entries.One caveat, this will include files that are not regular as long as their name starts with a
/
. For example, all files starting with the following would be included:And there may be others depending on your OS.
If you use
lsof /
it will just list open files on filesystems mounted DIRECTLY under / - that is, if you have /home mounted under /, its contents will be ignored. I tried various combination of options for lsof, but all had problems. The best I could come up is this:This uses readlink -f to get all block devices and feed them as a list to search. lsof ignores the ones that are not mounted.
If you have any other options to limit the search, for instance a pid, remember to end the lsof command with an
-a
to AND them with the list of block devices:this works fine on mac os:
i like it like this 'cause it's fast. it's faster if you specify -p