Re: Find and sort by date
From: Stephane CHAZELAS (this.address_at_is.invalid)
Date: 11/25/03
- Previous message: Chistian: "Find and sort by date"
- In reply to: Chistian: "Find and sort by date"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 25 Nov 2003 15:35:20 +0100
2003-11-25, 05:45(-08), Chistian:
> I`m writing a php script using a standard unix command on my RH 8 box.
> What I want to do is to search trought my music directories and
> display the 5-10 last modified files.
zsh -c 'print -rl -- /usr/ftp/music/Mp3/**/*(D.om[5,10])'
Or, as you've got a GNU system:
find /usr/ftp/music/Mp3 -type f -printf '%Ts %p\0' \
| tr '\0\n' '\n\0' | sort -rn | head -n 10 \
| tail -n +5 | cut -d' ' -f2- | tr '\0' '\n'
And if you want to postprocess that list:
find /usr/ftp/music/Mp3 -type f -printf '%Ts %p\0' \
| tr '\0\n' '\n\0' | sort -rn | head -n 10 \
| tail -n +5 | cut -d' ' -f2- | tr '\0\n' '\n\0' \
| xargs -r0 sh -c 'shift "$1"
for file; do
# whatever with "$file"
done
' 2 1
With zsh:
for file (/usr/ftp/music/Mp3/**/*(D.om[5,10])) {
# whatever with $file
}
-- Stéphane ["Stephane.Chazelas" at "free.fr"]
- Previous message: Chistian: "Find and sort by date"
- In reply to: Chistian: "Find and sort by date"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|