How do I tell lsof I need to list only physical files (not sockets, not TCP/IP connections, only physical files)?

link|improve this question

feedback

2 Answers

up vote 10 down vote accepted

Just looked through some man pages, it appears you use the command:

sudo lsof /

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:

lsof -a -d 1-999 -c <command name> /
lsof -a -d 1-999 -p <pid> /

1-999 limits it to files with a file handle number.

link|improve this answer
Will include FIFOs as well. – Kyle Brandt Jan 26 '10 at 14:35
1  
Nice and simple. If you need just the last column you could append | awk {'print $9'} Interesting. I don't get fifo in my output either. Fedora 12 and CentOS 5.3 – egorgry Jan 26 '10 at 14:37
CentOS 5.2 and Ubuntu 9.04 return the fifo's for me, could be a change, but are you sure there are fifos? I would grep for it first and make sure it is there, than try the / – Kyle Brandt Jan 26 '10 at 18:20
Also, I was just nitpicking, it sounds like he just doesn't want the noise, and there probably won't be very many fifos. – Kyle Brandt Jan 26 '10 at 18:23
1  
lsof / only includes files on the root filesystem. If you have multiple filesystems mounted, they won't appear in the output. I find the best way is to just use grep. – James Jan 26 '10 at 23:18
feedback

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.

link|improve this answer
4  
There might be a switch, but the manpage reads like someone's phd thesis... :) – Andrew H Jan 26 '10 at 14:27
Yea... lsof man is extremly hard to read... ;p) – FractalizeR Jan 26 '10 at 14:31
+1 that comment. :) – egorgry Jan 26 '10 at 14:39
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.