I want to search for a string of text in all files in a directory (and not its subdirectories; I know the -r option does that, but that is not what I want).
(1) Running
`grep "string" /path/to/dir`
is supposed to be able to do this, I've read, but it gives me the error:
grep: dir: Is a directory
(2) Next, I tried running grep on multiple files.
grep "string" .bashrc .bash_aliases works perfectly.
grep "string" .bash* works as intended too.
grep "string" * gives me the errors:
grep: data: Is a directory
grep: Desktop: Is a directory
grep: Documents: Is a directory
grep: Downloads: Is a directory
...
Only the errors are printed, I don't get the matching lines. I tried using the -s option, but to no avail.
So, my questions:
(a) Why am I not being able to use grep on a directory, as in (1), when I should be able to? I've seen that done in plenty examples on the Internet.
Edit: When I say "using grep on a directory", I mean "search in all the files in that directory excluding its subdirectories". I believe that this is what grep does when you pass a directory to it in place of a file. Am I incorrect?
(b) Please give me an explanation on the workings of grep that would explain the behavior of commands in (2).
Edit: Let me be more specific. Why does using wildcards to specify multiple files to search in for work with .bash* and not with * or even ./*?
(c) How can I search all the files in a directory (and not its subdirectories) using grep?
My machine is an Ubuntu 14.04, 64-bit. The output of grep --version is:
grep (GNU grep) 2.16
Copyright (C) 2014 Free Software Foundation, Inc.
*, known as globbing. Globbing does not include filenames starting with a dot such as.bashrcas standard. You can set shell options so that it will include these files, but you can get yourself in a bit of a mess if you don't know what you're doing. A good guide to understanding globing can be found here mywiki.wooledge.org/glob – Arronical 6 hours agogrep "string" .bash*too. – John Red 6 hours agogrep "string" * .* 2>/dev/nullorgrep -s "string" * .*– Terrance 5 hours ago