You could use an arbitrary command like ls
to check for the files and delete them in one line
ls /tmp/bbsnode{1,2,3,4} &>/dev/null && rm /tmp/bbsnode{1,2,3,4}
Note that in general it's unsafe to do such things in /tmp because any other user could create conflicting files with the same names.
A short explanation:
The return value of ls
is non-zero if one of the files does not exist. The {1,2,3,4}
is brace expansion: it expands to a string for each number: so /tmp/bbsnode{1,2,3,4}
is the same as /tmp/bbsnode1 /tmp/bbsnode2 /tmp/bbsnode3 /tmp/bbsnode4
. The &&
executes the next command only if the previous command has a zero return value, and so here rm
is only executed if all 4 files exist. Finally, the &> /dev/null
suppresses the output of ls
(&>
redirected both stdout
and stderr
, /dev/null
gets rid of it).
Below another solution with shell builtins only. It's similar to what others have answered but without an extra function or script:
set -- /tmp/bbsnode{1,2,3,4}
(for f; do test -f "$f" || exit; done) && rm -- "$@"