Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
$ 7z l ~/Downloads/Tab

How to make the resulting list to be sorted by date, not by name?

I currently use special script to list N most recent files in a given directory (and copy the filename manually into command line), but want to make it seamless and more convenient.

share|improve this question
Easy in zsh. I don't know if it's possible in bash. – Gilles Sep 16 '13 at 22:41
Do you want to just see the files listed by date or will you want to somehow add them to the archive in order of date? – terdon Sep 16 '13 at 23:32
There are many various files in "Downloads" directory, and I want to access the recently downloaded file (maybe unpack it, maybe move somewhere, etc.). – Vi. Sep 17 '13 at 11:15

I don't think bash is able to do that, so you might try out zsh. I'm not a zsh user though but I think this configuration should work:

autoload -U compinit
zstyle ':completion:*' file-sort modification reverse

(reverse here to see newest files in the end of the list, because the upper part might not be visible on the screen.)

share|improve this answer

Occasionally I need to find the most recently downloaded file in my Downloads directory but may not know the exact file name. Here is how I do it.

ls -rt ~/Downloads

ls -t lists the files by time not name, with the most recent being displayed first. Since my Downloads directory contains so many files I don't want to scroll to the top of the list to see the most recent. ls -rt reverses the order of the list, displaying the most recent file at the bottom of the list.

From there you can do what you need quite easily. For example:

unzip $(ls -rt ~/Downloads | tail -n1)


mv $(ls -rt ~/Downloads | tail -n1) *some_other_location*

Your original question could be done like this:

7z l $(ls -rt ~/Downloads | tail -n1)

I realize this is not adhering to the Tab completion method but it may be suitable for your needs.

share|improve this answer
Not saves typing. Actually I alredy have a script rl with ls -lhtc "$@" | head -n $N do to this. – Vi. Sep 19 '13 at 17:35
The question is how to intergate this or other script into <kbd>Tab</kbd> making think seamless. – Vi. Sep 19 '13 at 17:36
Your snippet also tends to break on some tricky filenames, as typical for downloaded files. – Vi. Sep 19 '13 at 17:42

I will do the following steps for it

  1. First I will find the files and their timestamps
  2. Sort them reversely
  3. Take top N
  4. Get the filenames
  5. Zip it or do whatever u like

And the script looks like this (May be complex)

find ~/Downloads/ -type f -printf '%TY-%Tm-%Td %TT %p\n' | sort -r | head -N | cut -d' ' -f3 | xargs 7z l
share|improve this answer
I already have similar script, named rl (recent list). But I need to explicitly call it, then copy&paste. I want it to be more integrated with tab completion. – Vi. Mar 3 '14 at 14:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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