I'd list as much as possible to replicate ls -l
with stat
so that I can see the octal numbers instead.
I have got quite close with stat -c '%a------- %h %U %G %5s %.16y %n' *
me@PC:/etc/apt$ ls -l
total 76
drwxr-xr-x 2 root root 4096 Sep 2 15:50 apt.conf.d
drwxr-xr-x 2 root root 4096 Apr 9 2020 auth.conf.d
drwxr-xr-x 2 root root 4096 Jul 28 03:26 keyrings
drwxr-xr-x 2 root root 4096 Jul 12 2021 preferences.d
-rw-rw-r-- 1 root root 2796 Aug 23 11:02 sources.list
drwxr-xr-x 2 root root 4096 Sep 2 15:50 sources.list.d
-rw-rw-r-- 1 root root 3071 Aug 23 11:02 sources.list.distUpgrade
-rw-rw-r-- 1 root root 3071 Jun 27 13:04 sources.list.save
-rw-r--r-- 1 root root 18951 Mar 27 17:15 trusted.gpg
-rw-r--r-- 1 root root 17320 Feb 7 2022 trusted.gpg~
drwxr-xr-x 2 root root 4096 Sep 2 15:50 trusted.gpg.d
me@PC:/etc/apt$ stat -c '%a------- %h %U %G %5s %.16y %n' *
755------- 2 root root 4096 2022-09-02 15:50 apt.conf.d
755------- 2 root root 4096 2020-04-09 06:21 auth.conf.d
755------- 2 root root 4096 2022-07-28 03:26 keyrings
755------- 2 root root 4096 2021-07-12 06:26 preferences.d
664------- 1 root root 2796 2022-08-23 11:02 sources.list
755------- 2 root root 4096 2022-09-02 15:50 sources.list.d
664------- 1 root root 3071 2022-08-23 11:02 sources.list.distUpgrade
664------- 1 root root 3071 2022-06-27 13:04 sources.list.save
644------- 1 root root 18951 2022-03-27 17:15 trusted.gpg
644------- 1 root root 17320 2022-02-07 22:44 trusted.gpg~
755------- 2 root root 4096 2022-09-02 15:50 trusted.gpg.d
All the data is there but the date format is slightly off.
Can it be piped through xargs and printf or something to reformat the date or is the closest I can get?
printf
, have you tried output formatting via the--printf
option? – Sotto Voce Sep 06 '22 at 22:17ls
always with long-iso timeformat) Good job btw, after octal code why do you add 6 dashes? – gabor.zed Sep 07 '22 at 13:16stat
you're using. Note that there are many different implementations of astat
command completely incompatible between each other. – Stéphane Chazelas Sep 07 '22 at 13:53ls
timestamp format also varies with the locale and system, and also whether the file was last modified in the last 6 months or earlier or in the future. – Stéphane Chazelas Sep 07 '22 at 13:55stat
you want%A
for the type and permissions in symbolic form. – Stéphane Chazelas Sep 07 '22 at 13:56ls
mishandles funny characters in filenames. See https://mywiki.wooledge.org/ParsingLs – waltinator Sep 08 '22 at 05:00