Find owner of Linux DIRECTORY ONLY


I have a python program that makes a ssh query to a linux server like so:
find . -type d > myfile.txt

A single line of output looks something like:


I also need the owner name of the directory (only), and NOT files,listed next to the directory name, like so:

johndoe /Downloads/SomeDirectory/
/Downloads/SomeDirectory/ johndoe

I do NOT want the information of the files in the directories to be included in the file, just the directory owner and the paths like mentioned above.

My current approach is to make an ssh request for every single directory with ls -la directorypath and then parsing out the owner, but it takes a long time since I have thousands of directories.
How should I go about this? I do NOT want to make thousands of SSH requests.

Thank You


Do you mean something like this?

find . -type d -printf '%p %u\n' > myfile.txt
  • %p – file / directory name
  • %u – owner

Answered By – cornuz

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published