Today I Learned

A Hashrocket project

Ready to join Hashrocket? Find Openings here and apply today.

How to exclude files when using rm

rm has no built-in way to exclude files, but you can use a negative pattern:

$ ls
=> bar.txt  foo.txt  secrets.yml
$ rm !("bar.txt"|"secrets.yml")
$ ls
=> bar.txt  secrets.yml

This approach is very error-prone and could have unexpected results. There are safer alternatives.