This very first post of my new blog post series about useless use of some commands when writing shell scripts.

Let's start with find and grep. When I started with shell scriptig, I used to use find /path/to/dir | grep -E '\.ext$' in order to exclude files with .ext.

But, did you know find offers better way to exclude files? Try find /path/to/file ! -name '*.ext, the result will be the same, without spanning a new process.

How about exluding multiple extensions? One may ask. Just repeat ! -name ext like this: find /path/to/file ! -name '*.ext1' ! -name '*.ext2' ! -name '*.extN'. And depending on number files types/names to exlude, this may become unreadble. In this case, take advantage of operators offered by find: find /path/to/dir ! \( -name '*.ext1' -or -name '*.ext2' -or -name '*.extN' \)


I use bash since I started using Linux. Since then, I use few tricks to be more effcient. I started to write a simple page grouping few tricks I use every day. I will continue add some more as learn them. If you find this useful, you may also like: