I have some 10 files of particular pattern coming every day on my server in "tmp" directory like below:

  1. abc1.px.20200820034058.gz
  2. abc2.px.20200820062036.gz
  3. mno.px.20200819192323.gz

abc1.px , abc2.px, mno.px is common everday. Date part changes.

I want to pick up the latest ".gz" file of each pattern and decompress it without affecting the original zipped files. Then I want to send the name of each of these unzipped files into another file suppose "xyz.txt" in same "tmp" directory along with the path. So, my file xyz.txt should contain:

/tmp/abc1.px.20200820034058 /tmp/abc2.px.20200820062036 /tmp/mno.px.20200819192323

I tried using below command but it didn't work:

gzip -d | ls -t /tmp/abc1.gz*| head -1 > /tmp/abc.txt*

What can be the correct way to achieve this?

  • Please edit your question and use the provided formatting options. – Panki Aug 21 '20 at 13:29
  • how to edit ? I can't see any edit option here – komal mishra Aug 21 '20 at 13:43
  • There is a button labeled "edit" right under the question, below the tags. – Panki Aug 21 '20 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.