user12070463
user12070463

Reputation:

How write script that prints Filename and its Owner

Help to write script. How to Using Loop, print Filename and its Owner in current directory

Example:

 filename: file1, owner: sysadm
 filename: file2, Owner: sysadm```

Upvotes: 0

Views: 146

Answers (2)

William Pursell
William Pursell

Reputation: 212604

There's no need for a loop, but implementations of stat differ. On Linux, you can probably just do:

stat -c 'Filename: %-40N  owner: %U' *

On Macos, you may want to use:

stat -f 'Filename: %-40N  owner: %Su' *

Upvotes: 5

stark
stark

Reputation: 13189

awk implicitly loops over its input

ls -al |awk '/^-/ {print "Filename:",$9 ", Owner:",$3}'

Upvotes: 0

Related Questions