0

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'

2 Answers 2

2

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
-rw-r--r--
drwxr-xr-x

in tour case because you don't the first character

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

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .