Having trouble creating an alias for grep

Hi,

I'm using Mac 10.9.1. I would like to create an alias for grep so that it won't print out messages like "grep: /Users/davea/workspace/myproject/subdir/: Is a directory" all the time. So in my terminal, I opened ~/.profile and entered

alias grep='grep -s'

However, when I close and re-open my terminal and then enter

find ~/workspace/myproject/ -name "*" | xargs grep 'mytoken'

I still get the above messages. What else do I need to do to make these messages go away by default?

Thanks, - Dave

find ~/workspace/myproject/ -type f -exec grep 'mytoken' {} \;

Try using the full power of find. -type f restricts the search to regular files, so it excludes directories. The "*" is not needed because find looks at all files by default. if you wanted filenames that end in dat, then -name '*dat' would be required.

Thanks, although my question has less to do with find and more to do with why the grep alias isn't working. Do you know why that is? I just used the find as an example, but maybe I should dig up another example that doens't involve find so as not to distract from the problem.

  • Dave

man bash :

That's why none of your longer commands will be working...

Is there anotehr way I can make "grep -s" the default behavior for my grep command assuming the "alias" I specified isn't an option?

man again, here man grep :

1 Like