Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question

2 Answers 2

up vote 16 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.

share|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
2  
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

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.

share|improve this answer
8  
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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