linux - How could I remove all directories except 10 recent with bash? -
i have following folders in base /var/www/.versions directory:
1435773881 jul 1 21:04 1435774663 jul 2 21:17 1435774856 jul 3 21:20 1435775432 jul 4 21:56 how remove directories except 10 recent bash script?
this should trick, believe?
rm -r $(ls -td /var/www/.versions/*/ | tac | head -n-10) the idea: list (with ls) directories ( that's -d /var/www/.versions/*/) sorted time -t (oldest shown last).
then, reverse output using tac oldest directories on top.
and show them except last 10 lines head , negative argument -n
please, test non-vital directories first ;-) can change rm -r echo see removed.
Comments
Post a Comment