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

Re: List ALL files modified in last 24hrs OR list atleast 10 recent files



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



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