0

So I used:

getent passwd $2 | awk -F: '{print "|Username: " $1 "\n|Password: " $2 "\n|Uid: " $3 "\n|Gid: " $4 "\n|Comment: " $5 "\n|Home: " $6 "\n|Shell: " $7 "\n"}'

to pipe user info in to a neat list.

I wanted to do the same with folders. I want all the information from the ' ls -l' command but instead of it coming out like a block of test I wanted it listed piece by piece.

Can I use an awk command together with ls and can I use the same method I did earlier?

Paulo Tomé
  • 3,782
Fredrik
  • 11

1 Answers1

5

Since you are on Linux you should instead look into the stat command with a proper format (-c, --format). Little known feature, the format accepts C-style length specifiers, so try for instance:

stat -c 'File: %-40n Size: %6s Flags: %8A' * 

You can put arbitrary strings in the format, and you can even put linefeeds in it (using the $'string' syntax):

stat -c $'--------------\nFile:     %n\nSize:     %s\nFlags:    %A' /boot/*
--------------
File:     /boot/abi-4.13.0-45-generic
Size:     1501528
Flags:    -rw-r--r--
--------------
File:     /boot/config-4.13.0-45-generic
Size:     213220
Flags:    -rw-r--r--
--------------
File:     /boot/config-4.15.0-72-generic
Size:     217468
Flags:    -rw-r--r--
--------------
File:     /boot/config-4.15.0-74-generic
Size:     217503
Flags:    -rw-r--r--
--------------
File:     /boot/config-4.15.0-76-generic
Size:     217503
Flags:    -rw-r--r--
xenoid
  • 8,888