zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: "zsh-users@zsh.org" <zsh-users@zsh.org>
Subject: Re: List ALL files modified in last 24hrs OR list atleast 10 recent files
Date: Tue, 11 Mar 2014 23:36:56 -0700	[thread overview]
Message-ID: <140311233656.ZM12220@torch.brasslantern.com> (raw)
In-Reply-To: <1394533556.43856.YahooMailNeo@web194603.mail.sg3.yahoo.com>

On Mar 11,  6:25pm, Amm wrote:
}
} Case 1)
} If there are more than 10 files modified in 24hrs
} then list them all (not just 10)
} 
} Case 2)
} If there are, say 7, files modified in last 24hrs
} then list those 7 + 3 other most recent files

So you don't really want to OR the patterns, you want to take the union
of the results.  You have the right idea here:

} ls -rlU --sort=time *(.mh-24) *(.Om[-10,-1])
} 
} But this causes duplicate entries, plus it fails
} if there is nofile modified in last 24hrs.

You can avoid the failure by adding an N to each of the glob qualifiers:

    ls -rlU --sort=time *(N.mh-24) *(N.Om[-10,-1])

Combining the -U (unsorted) and --sort=time options doesn't sense here?
Your original statement of the problem implies you want the files from
the last 24 hours sorted by name followed by any other recent files
sorted by time.  

To remove the duplicates, you can assign the results to an array, then
expand only the uniqe elements with ${(u)array}.  In recent versions of
zsh you can do this with an anonymous function:

    (){ ls -lU "${(u)@}" } *(N.mh-24Om) *(N.Om[-10,-1])

In older versions you'll have to define the function and then call it:
    
    _(){ ls -lU "${(u)@}" };_ *(N.mh-24Om) *(N.Om[-10,-1])

Aside:  It's somewhat unfortunate that:

    typeset -U var <=> ${(u)var}
    typeset -u var <=> ${(U)var}

I've forgotten how we ended up with that situation ...


  parent reply	other threads:[~2014-03-12  6:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-11 10:25 Amm
2014-03-12  0:02 ` Ray Andrews
2014-03-12  7:17   ` Amm
2014-03-12  6:36 ` Bart Schaefer [this message]
2014-03-12  7:13   ` Amm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=140311233656.ZM12220@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).