In python I can easily list files in a directory with os.listdir('dir')
but how could I easily filter those files to those which belong to a specific group? This is simply done in unix with find . -group "foo"
For example, let's say I have the following three files:
-rwxrwxrwx 1 foo foo 0 Sep 15 08:57 foo.txt
-rwxrwxrwx 1 bar bar 0 Sep 15 08:34 bar.txt
-rwxrwxrwx 1 foo foo 0 Sep 15 08:57 faz.txt
How can I get only those files which belong to the 'group' foo
using python?
The files returned should be foo.txt
and faz.txt
ideally in a list
object.
This similar question addresses how to get the group/user after you know the file. I want to filter the list to only a specific group.