Say, I got a specific task to find files that are not open. I understand how to get a list of open files with lsof (lsof +D
). Furthermore I need to find them only in so called 1st level subdirectories. To do this i use find
command with maxdepth 1
operand.
smth like this: find -maxdepth 1 -type d -ls >dirlist
Then, in a while loop i am trying to use lsof to check the list of directories (parental and 1 level sub) for NOT open files but i am completely green to bash. Say i might be able to get a list of OPEN files, but it's not what i need. Any ideas are welcomed.
Thanks for any help-
cheers
Update: awk
might be helpful, as far as I understand. Also case
and shift
maybe?
Update 1: I figured out just now that I am supposed to call (use, invoke, not sure which word is correct) for lsof
once only, that's why my while
loop isn't a suitable solution. Moreover, I need to stdout a list of directories that have no open files, each in a separate line. It's not that hard, i kinda got it working, just trying to clarify what the tsak is. The problem is that i don't know how to redirect a list of directories to lsof
without a while
loop.
smth like this doesn't work the way i want it to:
file="path"; name=$(cat "$file")