Harshit Jindal
Harshit Jindal

Reputation: 621

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:

/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

Upvotes: 0

Views: 41

Answers (1)

swingbit
swingbit

Reputation: 2745

Do you mean something like this?

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

Upvotes: 1

Related Questions