rm with pattern code example Example: how to remove all files in a directory matching a regex pattern shell ls | grep -P "^A.*[0-9]{2}$" | xargs -d"\n" rm