Comment on Need help understanding a back-up script
doeknius_gloek@feddit.de 1 year ago
This line seems to list all dumps and then deletes the two oldest ones. It will also remove your most recent backup if the folder contains less than three files, so be careful.
In detail:
ls -1 /backup/*.dump
lists all files ending with .dump alphabetically inside the /backup directoryhead -n -2
returns the two filenames from the top of the list (this should also behead -n 2
orhead -2
, nothead -n -2
)xargs rm -f
passes the two filenames torm -f
to delete them
Take a look at explainshell.com.
klay@lemmy.world 1 year ago
I just looked up the man page, and actually
head -n -2
means “everything up to but not including the last two lines”, so this should always leave two files remaining.doeknius_gloek@feddit.de 1 year ago
You’re right, I edited my comment. Thanks!
mnmalst@lemmy.zip 1 year ago
Your xargs comment is still wrong tho. It deletes ALL but the most recent two files.
doeknius_gloek@feddit.de 1 year ago
Fixed, thanks.