On Tue, Oct 13, 2009 at 14:24 -0500, Israel Garcia wrote:
> Hi List,
>
> It's a simple question but difficult to me :-).
>
> How can I delete all files on a folder /xxxx but keeping only the two
> latest (newest) files?
Try the following script:
-- snip --
#!/bin/sh -e
# Removes all but the 2 youngest files from the current directory.
# Bails out if directory contains less than 2 files.
function skip() {
cnt=$1 ; shift
for i in $(seq $cnt); do shift ; done
echo $@
}
rm $(skip 2 $(ls -t))
-- snip --
HTH
Siggy
--
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org+
| 2 days until|bsb-at-psycho-dot-informationsanarchistik-dot-de|
|www.Ubucon.de|or: bsb-at-psycho-dot-i21k-dot-de|
+-------> ceterum censeo javascriptum esse restrictam <--------+
Attachment:
signature.asc
Description: Digital signature