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?

1
  • idk what do you mean by that Commented Aug 6, 2014 at 14:13

2 Answers 2

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' 
3
  • 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. Commented Aug 6, 2014 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. Commented Aug 6, 2014 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. Commented Aug 8, 2014 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)}' 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.