How to displays the owner privileges of the files in the current directory in linux os?

Viewed 59

I want to displays the owner privileges of the files in the current directory

For example the output like this :

rwx addr_ph.txt
rw- add.txt
rw- a.txt
rw- filename.txt
rwx g.txt
rwx script
rwx script.save

I'm trying to write this command , but the output is not correct :

ls -al | cut -d " "  -f1,9
2 Answers

You just do this command :

ls -al | sed '1d'| tr -s " " " " | cut -d" "  -f1,9 | cut -c2-4,11-

Using GNU awk and stat:

stat --printf "%n %A\n" * | awk '{ printf "%s",substr($NF,2,3);for (i=1;i<=NF-1;i++) { printf " %s",$i } printf "\n" }'

Use stat to print the filename (%n) and the human readable permissions (%A). Redirect the output into awk to print the second to 5th characters of the permissions in the last space delimited field (NF) plus the file names (any proceeding space delimited fields - taking account of any spaces in the filenames)

Related