Re: script line not working as its supposed to, but why?
Sharon Kimble writes:
> But there is no consistency with the creation date, the menu itself is
> regenerated whenever I install a new programme, and the old menu is
> saved with the suffix of the date and time.
> I want to delete the 'menu-*' files if there are more than 7, and
> the command is parsed when I have 'set -x' at the head of the
> script but this line does nothing! It runs but doesn't achieve
> anything.
The find command is not your friend here, I think.
If you have a single directory where these menu are regenerated
automatically, you could exploit the fact that lines like
menu-20131209-11:05
have an asciibetic order (order based on the ASCII code) that matches
the age order, but reversed, I mean newer backups come last. The
option -t of ls fixes this.
I would try with something like this:
if [ `ls -1 menu-* | wc -l` -gt 7 ]
then
ls -t menu-* | tail $((7-`ls | wc -l`)) | xargs rm
fi
The first test ensures that you have more than 7 files.
Then you list the files in reverse asciibetical order (that is older
last), then the expression
$((7-`ls | wc -l`))
does the magic to compute the option to pass to tail so that it shows
the last (number of files - 7). And finally xargs feeds rm. You can
use rm -v to see them being deleted :)
I hope this helps.
--
/\ ___ Ubuntu: ancient
/___/\_|_|\_|__|___Gian Uberto Lauri_____ African word
//--\| | \| | Integralista GNUslamico meaning "I can
\/ coltivatore diretto di software not install
già sistemista a tempo (altrui) perso... Debian"
Warning: gnome-config-daemon considered more dangerous than GOTO
Reply to: