Aren't egrep, fgrep supposed to be aliases to grep?

Solution 1:

It depends on the OS and the version of the grep tools installed.

Some examples for systems I happen to have access to:

  • Ubuntu 11.04, GNU grep 2.6.3: /bin/grep, /bin/fgrep, and /bin/egrep are three distinct executable files with different sizes.

  • GNU grep 2.10 (just released a few days ago), built from source: the same.

  • Cygwin: the same.

  • CentOS 5.6 (a clone of Red Hat), GNU grep 2.5.1: /bin/egrep and /bin/fgrep are symlinks to /bin/grep.

  • GNU grep 2.5.1 built from source: egrep and fgrep are small shell scripts that invoke grep.

  • Solaris 9: three different files (Solaris tools, not GNU).

Solution 2:

They used to be separate executables, but these days it's usually a single executable with three hard links ("grep", "fgrep" & "egrep") all pointing to the same program: the program checks which name it was started as, and behaves accordingly.

So what you're running is an enhanced egrep with the features of the other two programs included: and calling it by different names, or with -E gives you the features you expect.

If you type

ls -i `which grep`

and the same for fgrep and egrep you may see that they all have the same inode number, which means they are all the same file.