Here is the result of listing the files in a directory.

total 4
-rw-r--r-x 1 y_wc y_wc 6828641 dez 24 18:21 file1
-rw-rw-rw- 1 y_wc y_wc 2051577 dez 24 18:13 file2
-rw-rwxr-x 1 y_wc y_wc 1874334 dez 24 18:14 file3
-rw-rwxrwx 1 y_wc y_wc 2902856 dez 24 18:14 file4

I'd like to concatenate the permissions in one line by the same order by which they appear. Here permissions exclude the file type. The output should be rw-r--r-xrw-rw-rw-rw-rwxr-xrw-rwxrwx

I'd like solutions using coreutils and, separately, awk.

I'm close with the coreutils solution, but I'm unable to get rid of the file type character. Here's what I got

ls -l | tail -n+2 | cut -d" " -f1 | tr -d '\n'

ls has very poor options for formatting . stat has --printf option , to format has you want information about files .

a example :

root@linux:~# stat --printf  '%A\n' /etc/passwd /etc

in tour case because you don't the first character

root@linux:~# stat --printf  '%A\n' file*  | cut -c2-11 | tr -d '\n'
  • Thanks. But this is printing the file type. – y_wc Mar 23 at 20:29
  • The cut could be just cut -c 2-. – Kusalananda Mar 23 at 21:23

The first character can be removed with cut -c 2-

ls -l | tail -n+2 | cut -d" " -f1 | cut -c 2- | tr -d '\n'

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.