Reputation: 510
I have some files whose name is postfixed by (copy), which I want to remove. For example: f1.jpg, f1(copy).jpg, f2.jpg, f2(copy).jpg. What command can I Use to remove all copy files?
Upvotes: 0
Views: 182
Reputation: 46813
Or find
with its wonderful (non-POSIX) -delete
switch:
find . -maxdepth 1 -name '*(copy).jpg' -type f -delete
This can be superior to globs in case you have a lot of files, where globs would yield a Argument list too long error. It might be faster too in case of lots of files. The -maxdepth 1
switch (not POSIX) to avoid recursion into subdirectories. The -type f
switch to only deal with files. You can add the -print
switch if you want to see which files are deleted.
Upvotes: 2
Reputation: 123410
You can use the rm
command to remove files:
rm *\(copy\)*
The \
s are needed because parentheses are special to the shell. Alternatively, rm *copy*
.
Upvotes: 4