I have been trying to work on my own little backup script.
I am running into an issue when I run my script and the rm
command has nothing to do. I would still like to process the output (aka display different messages according to whether or not the operation has failed) but suppress the output natively generated by rm
.
Currently this:
ls -t | tail -n +$startnumber | xargs -d '\n' rm && echo "Removed old backup(s)." || echo "No more than $keepnumber files; nothing to do."
unfortunately outputs this:
rm: missing operand
Try 'rm --help' for more information.
No more than 14 files; nothing to do.
Where I would like to get rid of the first two lines and only output my own, "more legible" message.
I have tried using rm -f
but this will always (and falsely) trigger the successful output.
|
|||
|
These
This will prevent both the lines from printed on your terminal and only your customized message will appear. |
|||||
|
I would just save the file listing in a temporary file, and count the lines there, before trying to You could also redirect errors from Say
Of course, using |
||||
|