Monday, November 18, 2019

Error: grep: find: Is a directory

Error: grep: find: Is a directory

EmailThis Premium lets you save unlimited bookmarks, PDF, DOCX files, PPTs and images. It also gives you a PDF copy of every page that you save. Upgrade to Premium →

I am new to Linux and going through some tutorials and samples. I created a file called test and put alex and alexander in it. I'm trying to find instances of just alex.

If I do grep alex * I get the error:

grep: find: Is a directory. 

If I do cat test | grep alex then I get (as expected)

alex alexander (with alex in red) 

Why does the first cause an error, and the second produce expected results?

jww

70.5k4646 gold badges263263 silver badges577577 bronze badges

asked Jul 12 '17 at 1:31

AdoytAdoyt

17511 gold badge22 silver badges1111 bronze badges

If you want to grep phrase from specific file use:

# grep "alex" test 

In case you use grep alex * it will search through all files inside the current work directory. In case subdirectory will be met it will tell you something like grep: find: Is a directory
If you want to perform a recursive search use -r key. For example

# grep -r "alex" /some/folder/ 

In this case all files and files inside subdirectories from /some/folder/ will be checked.
And you can always use man grep.

answered Jul 12 '17 at 1:39

Elvis PleskyElvis Plesky

2,33511 gold badge77 silver badges1919 bronze badges

Correct answer would be: grep -d skip alex /etc/*

answered Sep 27 '17 at 8:43

Setting the environmental variable GREP_OPTIONS to include the value "--directories=skip" should suppress that "Is a directory" message (i.e. enter GREP_OPTIONS="--directories=skip" or add that line to one of your login initialization files like .bashrc to make that behavior permanent).

> cat test alex alexander  > grep alex *     grep: mysql_data: Is a directory grep: sql_updates: Is a directory test:alex test:alexander grep: tmp_files: Is a directory  > GREP_OPTIONS="--directories=skip"  > grep alex *                       test:alex test:alexander 

Also since there is a command named "test" and another named "find" it's usually not advisable to use those as file or directory names. That shouldn't be a problem here but it can lead to other conflicts.

answered Jul 28 '17 at 23:34

Or using grep with -l flag or -w flag

$ grep -l alex /etc/*  

To return list of files containing word "alex" in the /etc directory

$ grep -w alex /etc/* 

To return list of lines from files in the /etc directory containing "alex" word

answered Jul 25 '17 at 18:27

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

Source: https://stackoverflow.com/questions/45046873/error-grep-find-is-a-directory

Please check the attached file.

EmailThis was not able to extract useful content from the website. Hence, we have saved the webpage to a PDF file. You can find that attached along with this email.

Upgrade to Premium Plan

✔ Save unlimited bookmarks.

✔ Save PDFs, DOCX files, images and Excel sheets as email attachments.

✔ Get priority support and access to latest features.

Upgrade to Premium

No comments: