How to format output of command?

Hi how do you change the format of the output of

ls -lt -c -R $HOME | sed /^total/d

From:

/home/pikamon/Desktop:
-rwxr-xr-x 1 pikamon pikamon 35 Sep 18 14:25 fileModified.sh
-rwxr-xr-x 1 pikamon pikamon 87 Sep 18 14:25 fileModified.sh~

/home/darksky21/Downloads:
-rwxrw-rw- 1 pikamon pikamon 19889714 Sep 14 18:02 test.deb
-rwxrw-rw- 1 pikamon pikamon 127352 Sep 14 18:02 testing2

/home/pikamon/Documents:

/home/pikamon/Music:

To:

-rwxr-xr-x 1 pikamon pikamon 35 Sep 18 14:25 /home/pikamon/Desktop/fileModified.sh
-rwxr-xr-x 1 pikamon pikamon 87 Sep 18 14:25 /home/pikamon/Desktop/fileModified.sh~
-rwxrw-rw- 1 pikamon pikamon 19889714 Sep 14 18:02 /home/darksky21/Downloads/test.deb
-rwxrw-rw- 1 pikamon pikamon 127352 Sep 14 18:02 /home/darksky21/Downloads/testing2

using shell script. I would like to remove the path on the header and add it into the path of each directory

You may try the find command

find $HOME -type f -exec ls -l {} \;

or

ls -ltcR $HOME | awk '/^\// {dir=substr($0,1,length($0)-1)} /^-/{$9=dir"/"$9;print}'
1 Like

This might also be helpful to you.

ls -ltcR $HOME | grep -v "^total" | grep -v "^\/" | grep -v "^$"

Whenever you find yourself doing grep | grep | grep | grep | grep, it's time to learn awk:

ls -ltcR $HOME | awk '!/^total/ && !/\// && !/^$/'
1 Like

Try

ls -tlcR | awk '/^total|^$/ {next} NF==1 {D=$1} {$9=D $9; sub (":","/",$9)} 1'

Thx for all the help and reply still new to all this shell command