2

I tried with

lsof -F c somefile

But I get

p1
cinit
p231
cmountall
p314
cupstart-udev-br
p317
cudevd

Instead of

init
mountall
...

Any way to get just the command?

Braiam
  • 35,991
kittie
  • 23

2 Answers2

3

This will select lines that begin with the c tag and print them out after removing the tag.

lsof -F c somefile | sed -n 's/^c//p'
terdon
  • 242,166
Mark Plotnick
  • 25,413
  • 3
  • 64
  • 82
  • 1
    I undeleted this since it is a perfectly good answer and indeed much simpler than using awk. If you really want to remove it I promise I won't undelete again but please leave it. – terdon Aug 06 '14 at 15:25
  • I deleted my answer because I saw it was a dup of a comment (by @Stéphane Chazelas , I think) and wanted to let the commenter post it as an answer. – Mark Plotnick Aug 06 '14 at 16:38
  • Answers posted as comments are fair game. If you want to be polite, you can mention the comment but it is perfectly fine to post as an answer something that someone else posted as a comment. Especially if you flesh it out a bit as you have done. – terdon Aug 08 '14 at 13:10
0

Man page says procces ID is always selected.

depending on your need, you may use awk to filter out process

lsof -F c somefile | awk '/^c/ { print substr($0,2)}' 
Archemar
  • 31,554