grep only returns No such file or directory

Apparently I've done something that has altered how grep runs on my Ubuntu 16.04 machine. Regardless of what I input to it, it returns "No such file or directory", or something along those lines.

For example, if I create a file and then try and search it with grep, it doesn't work. Entering the two commands below produces the error.

$ echo 'dog eat dog' > dog
$ grep 'd' dog
grep: d: No such file or directory

Perhaps I've done something so that grep is looking in the wrong place?

5

2 Answers

  • Did you try it this way

    echo 'dog eat dog' > dog; /bin/grep 'd' ./dog

    If this works, your aliasing or other bashrc settings a wrong

  • Do you have write and read access in the directory where you call the command?

Your command is correct - something seems wrong with your environment

$ echo 'dog eat dog' > dog
$ grep 'd' dog
dog eat dog

Your error message suggests that it is considering "grep: d: " as a command and not "grep". The other possibility is that you do not have grep in the path. Try:

which grep

To find out where grep is installed. Also try a non-existing command such as grepx (which does not exist) to check your error message:

$ grepx 'd' dog
-bash: grepx: command not found

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like