10

Say I have folder "foo" residing, the home directory. I want to get some info of it, owner, group, permissions, etc...

I then do this to try to get the information:

cd ~
ls -l foo

Of course it now lists the info of the contents of "foo"

Then I could do something like this

cd ~
dir=foo
ls -l $foo/.. | awk 'BEGIN { dir="'$foo'" } { if($9 == dir) { print $0 }  }'

But isn't there an easier way to do this?

migrated from stackoverflow.com Aug 19 '11 at 16:24

This question came from our site for professional and enthusiast programmers.

23

Try

ls -ld foo

And you will get what you want.

But also consider stat if you want to capture information. The output of ls is for human consumption only.

stat -c %U foo # get owner of foo
  • THANK YOU for this. It's been a while I've wanted the same -- Thank you @Tyilo for asking the question too, a long time ago lol. – juanmirocks Jan 30 '18 at 9:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.