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 12, 12:06 PM Bart Schaefer wrote:

}} 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])

Great I did not know about N flag. That solved one problem.

} Combining the -U (unsorted) and --sort=time options doesn't sense here?

Yep, -U was typing mistake for that example.

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

No everything 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])

Actually today I was trying typeset like this.
lst() {
    typeset -U plst
    plst=($plst *(.mh-24))
    ls -lr --sort=time $plst
But now I can combine your two suggestions of N and (u)
plus anonymous function to make it a single command.

lst () {
    () {
        ls -lr --sort=time "${(u)@}"
    } *(N.mh-${1:-24}) *(N.Om[-${2:-10},-1])

Note: I have extended it so that I can pass parameters to
function. i.e. lst [hours] [nooflines]

Works perfect as per my requirement.

Thanks a lot for your solution.


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