is it possible to use rm to remove files and directories matching a pattern recursively without using other commands?
To directly answer your question, "no - you can't do what you describe with
You can, however, do it you combine it with
For example, if you want to nuke all *~ files, you could so this:
To expand from a comment*:
Using Bash, with
Try it with e.g.
You set options through e.g.
Alternatively, a shorter
or for GNU
or another alternative for non-GNU
To also remove directories, as you ask for: just change
I would have asuumed " rm -rf " where is a combination of file names, and matching patterns such as * and ? etc (eg todays_log_2009????.log) . That will start from current Dir and work down recursively removing files that macth that pattern.
If you use zsh(1), turn on "extended globbing" with
% rm -rf **/< pattern >
However, if there are a lot of files to delete you should resort to find(1) with xargs(1) or -exec, and I also recommend doing that in shell scripts.