Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Copy newest file to newest directory



zzapper <david@xxxxxxxxxx>:
> I have some global aliases which call scripts such that I can write
> 
> > cp NF ND
> Where NF copies the newest file to ND the newest directory
> these are relative to current directory
> 
> I'd like to be able to generalise this ie
> 
> > cp /tmp/NF /store/ND
> 
> Obviously the above cannot work but any (lateral) ideas?

How about something like this:

[snip]
function cpn() {
  local nf nd
  nf=${1}/*(.om[1]N)
  nd=${2}/*(/om[1]N)
  [[ -n ${nd} && -n ${nf} ]] && command cp ${nf} ${nd}
}
[snap]

% cpn /tmp /store

Regards, Frank

-- 
In protocol design, perfection has been reached not when there is
nothing left to add, but when there is nothing left to take away.
                                                  -- RFC 1925



Messages sorted by: Reverse Date, Date, Thread, Author