Rm to Match Multiple File Extensions

How to merge these two commands together

rm *.html
rm *.xml

3 Answers

Simply rm *.html *.xml

Also see the man pages for Linux (or macOS) or try tldr which currently gives this output:

$ tldr rm

rm

Remove files or directories.

- Remove files from arbitrary locations:
    rm path/to/file path/to/another/file

- Recursively remove a directory and all its subdirectories:
    rm -r path/to/folder

- Forcibly remove a directory, without prompting for confirmation or showing error messages:
    rm -rf path/to/folder

- Interactively remove multiple files, with a prompt before every removal:
    rm -i file(s)

- Remove files in verbose mode, printing a message for each removed file:
    rm -v path/to/folder/*

$
2

Simply use

rm *.html *.xml

It’s the shell that interprets the wildcard pattern(s) to carry out the filename expansion – not the rm command.

If you experience an error with the accepted answer, when there are no .html files, you could also chain the commands instead like: rm *.html; rm *.xml

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Marcus Vance

Marcus Vance

Cybersecurity & Digital Privacy Researcher

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.

Share this article
Twitter Facebook Pinterest