I'd like to run a command line:
cd ~/www/tmp/; rm -P 2*
But I get an error if there are no files starting with 2.
You would think I would want to use -f
, however:
-f Attempt to remove the files without prompting for confirmation, regardless of the file's permissions. If the file does not exist, do not display a diagnostic message or modify the exit status to reflect an error.
And I do care about file permissions- if there's something weird going on, I'd prefer the command abort. I only want to suppress 'do not exist' errors.
I've looked at some other questions with 'rm errors', and found these two which seem (kinda) relevant:
Delete files and directories by their names. No such file or directory
But, I don't understand everything going on in the answers to this question, and don't know that I need it?
The touch
hack suggested in this question:
Have rm not report when a file is missing?
Seems workable, as I don't think I mind the performance hit (but what type of performance hit would you take? - ie: is this a reasonably scalable technique, or am I just learning very bad habits?)
I'm not sure how I'd do an if-then
within the command line.
Are there any other options for a simple command line cut-n-paste cleanup?
Would find -delete
work better for my case? If so, why?
error in question:
rm: 2*: No such file or directory
rm
, so you'll need to say what that is. – Michael Homer Jun 26 '18 at 05:49zsh
as your interactive shell? Are you getting aNo matches found
error? – Kusalananda Jun 26 '18 at 06:072*
to rm instead of expanding it to a list of files. Look at the error in question: it says that rm is complaining, not sh/bas/zsh/... – doneal24 Jun 26 '18 at 12:46