Home > Back-end >  Find owner of Linux DIRECTORY ONLY
Find owner of Linux DIRECTORY ONLY

Time:09-16

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:

/Downloads/SomeDirectory/

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

johndoe /Downloads/SomeDirectory/
OR
/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

CodePudding user response:

Do you mean something like this?

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