8
$ 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.

  • 3
    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
2

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
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.)

0

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)

or

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.

  • 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
0

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
  • 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 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.