So I was writing a python script and my goal was to use lsof to list all open files under a specific directory (my home folder) for the local user and only output the 'uniq' entries.
My script looked like this:
import os, sys, getpass
user = getpass.getuser()
cmd = "lsof -u " + user + " +d ~ | sort | uniq"
os.system(cmd)
This kind of does what I want it to do, it does lsof for the current local user, but it fails to look specifically in the home directory that i specified. Instead it does lsof on the root directory and lists all lsof for the entire file system for the user. However, when I do the same command without the -u user
it looks specifically in the home directory. I've been looking into why this is exactly, and yes I have tried using +d /home/
and +d ~/home/
instead of just +d ~
to get this to work with no success, so I am kind of stumped. Any advice would be great :)