This question already has an answer here:

I want to write a script which gets the latest file from a list of zipped files and then unzip the file

I have tried ls -t1 | head -n 1 -exec unzip {} --> to get the latest zipped file. and unzipping it but it is not working

marked as duplicate by G-Man, mdpc, Archemar, Anthon, Networker Sep 8 '16 at 7:06

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • head doesn't have -exec parameter. – Ipor Sircer Sep 7 '16 at 21:05

You appear to be mixing up find syntax and using it in the wrong place.

Typically you want to pass the filename to unzip, so you would use the syntax

unzip "$(....code.to.generate.filename...)"

You have the ls and head commands so the result would be

unzip "$(ls -t | head -n 1)"

Note the " around $(...) so that if you have spaces in the filename they'll be kept consistent.

Of course this will break if the newest file is a directory or has a RETURN character in it :-)

Not the answer you're looking for? Browse other questions tagged or ask your own question.