I am able to use ripgrep to do things like this:

ps aux | rg 'process name'

I am able to search the output of the previous command. For some reason this doesn't work for me using regular grep. If I do:

ps aux | grep 'process name'

It ignores what I am trying to pipe into grep and searches the current working directory for the process I typed in.

This is the output of ps aux: ps aux output

If I would grep firefox for example it would not show it.

ps aux | rg firefox gives me this: ps aux with rg

EDIT: It seems to be because some sort of alias described here https://unix.stackexchange.com/a/500727/375504

This works: ps aux | \grep firefox

  • Can you add the output from ps aux and the name of a process that shows up in that output but cannot be found by grep? A copy from the terminal, with commands and everything would help a lot. – Eduardo Trápani Nov 12 '19 at 20:47
  • @EduardoTrápani, ilkkachu I added an example – Bas van der Linden Nov 12 '19 at 21:05
  • What do you get with type grep – schrodigerscatcuriosity Nov 12 '19 at 21:11
  • @guillermochamorro: grep is aliased to `grep -nRi ' – Bas van der Linden Nov 12 '19 at 21:14
  • 1
    @ilkkachu yeah I don't remember why and when I put that in there – Bas van der Linden Nov 12 '19 at 21:58

You say that when you use ps aux | grep 'process name' it (grep) ignores what I am trying to pipe into grep and searches the current working directory.

You also write that grep is aliased to grep -nRi.

When you look at the documentation for grep (man grep) you will find that the -R flag does exactly what you have described:

-r, --recursive Read all files under each directory, recursively, following symbolic links only if they are on the command line. [...]


-R, --dereference-recursive Read all files under each directory, recursively. Follow all symbolic links, unlike -r

With GNU grep, grep -r also by default starts from the current directory if a filename argument is not given. Some other versions of grep don't do that, but might instead warn about a "recursive search of stdin" while still reading stdin.

The solution is not to alias grep to something else. Instead create a new alias if you need specific functionality (rgrep could be an alternative here, for example).

| improve this answer | |

My problem was that I had aliased grep to grep -nRi $* in my bash aliases. Removing the alias or calling \grep fixes the issue.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.