I would like to write a list of files opened for read or write to fileX.txt including only the pathname of each file in the output. Here is my command:lsof / -FDu >> fileX.txt When I checked the contents of fileX.txt, it contains more information than I want on each output. How can I manipulate my output to be only the pathname of each output?

  • 1
    I assume by "pathname" you actually mean filename?
    – Panki
    Aug 17, 2021 at 14:38
  • Also, are you sure you don't have this the wrong way? Your command throws lsof: status error on -FDu: No such file or directory. You probably want lsof -FDu /.
    – Panki
    Aug 17, 2021 at 14:43
  • Thanks, Panki but no! '$ lsof -FDu /' displays some wired output. My initial command is to what I meant because I get seemingly meaningful output albeit more information than I want. The issue is that I need a way to extract only the path of the files displayed.
    – WildGTX
    Aug 17, 2021 at 14:52
  • Your command makes no sense. lsof / -FDu will print info about the files named / and -FDu. lsof -FDu (as suggested by panki) will ask it to print info about / in a special format "suitable for other programs" (the -F flag), but including only the file type (by default), the major/minor number (D) and user the id (u). Have you simply copy-pasted that from somewhere and expected it to work, because why?
    – user313992
    Aug 20, 2021 at 14:35
  • If you want a list of all the opened files, one per line, then ask that Q directly and specify what should happen with 1. paths containing newlines 2. paths which are not accessible (they're hidden by a mount, inside a separate namespace, they were removed, etc). 3. sockets, pipes and other files which have no paths.
    – user313992
    Aug 20, 2021 at 14:40

1 Answer 1


If I am understanding your question correctly, you could try piping your output through awk, like so:

lsof / -FDu | awk '{print $9}' | grep -Ev '/$' 

The awk command is to isolate the path column and the grep part is to eliminate the lines that just have '/' with trailing space after them.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .