I get sometimes files with following ls output format:
/etc/cron.d:
-rw-r--r-- 1 root root 128 May 15 2020 0hourly
-rw------- 1 root root 235 Dec 17 2020 sysstat
/etc/cron.daily:
-rw------- 1 root root 235 Dec 17 2020 sysstat
Is there any chance using normal gnu tools or even clear bash internals to manipulate that content to:
-rw-r--r-- 1 root root 128 May 15 2020 /etc/cron.d/0hourly
-rw------- 1 root root 235 Dec 17 2020 /etc/cron.d/sysstat
-rw------- 1 root root 235 Dec 17 2020 /etc/cron.daily/sysstat
That would be great.
I mean the easiest is to remove the file paths like that:
cat <filename> | grep -v -E "^\/[a-z]"
But like I said how to move these paths down to the follow-up lines with the filenames?
The command that is the given is this one: ls -lR /etc/cron* > <filename>
.
I don't have influence to that output, but rather I get these command outputs executed by ls redirected to a separate file <filename>
that is transferred to me.
And what I like to do is manipulate it's content into the mentioned second result. basically obtaining the first line an appy the path to the files lines 2 and 3 and then take line 4 and apply it to line 5. And then configured that one as a general approach.
I think that should be possible using awk.
ls -l /etc/cron*/*
is what you are looking for, or evenls -ld /etc/cron*/*
. – Bib Mar 26 '24 at 22:01find
might be a better tool thanls
. E.g.find /etc/cron*
or if you need the other data fromls
pipe thefind
output. find /etc/cron* -type f | xargs ls -l
– cherdt Mar 26 '24 at 22:18find
,find /etc/cron* -type f -ls
. – Stephen Kitt Mar 26 '24 at 22:24stat
command, rather than falling into the trap of parsingls
output. Do an online search for "Parsing ls considered harmful". – waltinator Mar 27 '24 at 00:19