I'm trying to assign the permissions, owner and group of a file to seperate variables, but using
ls -l filename | awk '{print $1 "\t" $3 "\t" $4}'
gives the owner as tom.ja instead of tom.james
Is there any way to expand it so i get the full name, or is there an easier way to get them into variables?
Also, i'm processing the permissions into a table ie Owner has READ and EXECUTE permissions, Group has... etc. I was thinking to use a shift to deal with each permission, is there any way to now seperate each permission? ie.
-rwxr-x-r-- into
r w x r - x - r - -
it doesn't have to be whitespace, but just so i can process each one.
Thanks Apoorva, this works great! As for the first question, if the owner name isn't cut short with you, maybe the columns are too small on mine, is there any way to widen them so i get the full username?
Dhruva, could you explain what f1, f3 and f4 do? As when i tried your code the only output is from $perm which is
-rwxr-xr-x
And i'm afraid John-Pierre that yours only prints out the | !!
I have not faced any colmn size problem so far. Still if you think so, you can also try 'printf' function. As far as f1,f2...are concern they just indecate the respective fields.