Using lsof to get a list of file names
EDIT 1
I'm having problems using the arguments given. Maybe it is the way I'm passing my arguments through NSTask? Any suggestions as to how I can do this?
NSTask *file_Task = [NSTask new];开发者_开发问答
[file_Task setLaunchPath:@"/usr/sbin/lsof"];
[file_Task setArguments:[NSArray arrayWithObjects:@"+p", the_Pid, nil]];
Good Afternoon Fellow Coders....
I'm using the following command:
lsof +p 13812
to get the list of a files accessed by a process. The thing is it is giving me a lot of additional information that I don't want such as TYPE, DEVICE, etc.
Is there an argument that I can add to the above command so that I get ONLY the NAME?
Thank you, thank you thank you! :)
Eric
You can use:
lsof -Fn +p 12345
This will output a list of lines, with the first being p
followed by the process ID,
and all following lines consisting of n
followed by the file name.
If you'd like to quickly preprocess this, you can do something similar to the following:
lsof -Fn +p 12345 | tail -n +2 | cut -c2-
See the lsof
man page for more information, specifically under the OUTPUT FOR OTHER PROGRAMS
heading.
try:
lsof | tr -s ' ' | cut -d' ' -f9
lsof +p 9174 | awk '{ print $9 }'
Listing the currently playing song (nfs file, accessed by user mpd):
$ sudo lsof -N -a -u mpd -Fn |
sed '/n/!d; s/^n//'
/R/audio/[...] Jay-Jay Johanson , So Tell The Girls That I Am Back.mp3
The sed part deletes any lines not starting with n and removes n in the final output.
精彩评论