how to get the last modified file . so that can use it as a argument in other commands i tried

unzip ls -ltr | tail -1

but this is not working


Be aware, parsing the output of ls might fail, read e.g. here or there.

As you have the zshtag in your question, here is a zsh specific solution:

First, put all entries (*) in the current directory into an array files, ordered (o) by modification time (m):


As * is a so-called globbing pattern, (om) are called Glob Qualifiers, which have an own section in man zshexpn with that title.

Now, you can use the first element of that array to reference the newest file

echo $files[1]

Read man zshparam for more info about arrays.

  • 1
    thank you . this solved my issue also could you share where from where to find this zsh specific shortcuts – Prinz Piuz Jun 24 '19 at 5:01
  • @PrinzPiuz: Yes, sorry, you are right -- I should have referenced the documentation. I edited my answer accordingly. – mpy Jun 24 '19 at 14:51

i found this

last_file=$(ls -lrt | tail -1) name=$(cut -d' ' -f10 <<< $last_file) echo $name

  • Hi, welcome to Super User! Where did you find this? Can you explain it? – bertieb Jun 21 '19 at 11:48
  • i myself tried and it worked (in my case ) – Prinz Piuz Jun 21 '19 at 12:16
  • Sorry for being unclear- can you edit your answer explain where you found the command you are using, and explain what each part does? This will help others who read your question and answer :) – bertieb Jun 21 '19 at 12:54
  • its not an effective solution each time we need to change feild value below answer solved my issue – Prinz Piuz Jun 24 '19 at 4:57

Your Answer

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

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