how to grep only current directory for specific files [closed] - bash

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 years ago.
Improve this question
Hello I have a question I want to find a keyword in a directory without recursion. And I want to check only for the .c extensions.
For example I try;
grep -r 'keyword' --include=*.c .
And it works. But I dont want recursive search I just want the current directory's results so I remove the -r
grep 'keyword' --include=*.c .
However this gives me an error that ". is a directory". Actually I have an idea to write the contents of recursive grep to a textfile and grep that textfile for the file extensions but I think it wont be efficient at all. Thanks for your support.

I suggest this:
grep 'keyword' *.c

The other answer is clean and efficient.
But I have the feeling that you insist on using "-r" and/or "--include", maybe for reasons not mentioned.
bash-3.1$ grep -r --include="*.c" -dskip 'keyword' ./*

Closer to your original syntax, you can use:
grep --include=*.c 'keyword' *
This reports directories without searching them.

Related

Why doesn't "ls -ad */" show both hidden and non-hidden directories? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed last year.
Improve this question
Why doesn't the command:
ls -ad /*
...show both hidden and non-hidden directories? And given this does not work, what would be the simplest command for showing hidden and non-hidden directories, without showing files?
Thanks!
/* is expanded by the shell before ls ever runs. The expansion only includes non-hidden files unless the dotglob option is set. Also, if you want the expansion limited to directories, use /*/ instead.

ag and rg not listing files starting with underline, find does [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
If I do:
touch _gandalf
And then:
rg --files | grep gandalf | wc -l
or
ag -l -g "" | grep gandalf | wc -l
I get 0 matches as result.
Now if I do a touch gandaf I get 1 match.
Why is that? Does files starting with underline have a similar behaviour as hidden files? Maybe is something on mac's filesystem? As mentioned on the title if I replace ag/rg for find . it works as expected.
In my case was my global .gitignore having a clausule to exclude files starting with underlines.
But I think is useful to keep in all this files (as mentioned on the comments):
.gitignore
.ignore
.rgignore
.agignore

what is ls -F (ls --classify) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
Looking at the man pages for plain old ls I see there's a flag for -F
-F, --classify
append indicator (one of */=>#|) to entries
I've used it a few times, but all I see it adds a slash / to folders which is the same as ls -p
What does this mean for the others *=>#|?
I'm running Ubuntu 14.04 with GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)
Each of the symbols is for a specific type of file. If you haven't seen them, it's probably because you don't have any files of that type. The man page for ls should say what each of them means. But, in case you can't read yours for some reason, here's what mine says:
-F Display a slash (`/') immediately after each pathname that is a
directory, an asterisk (`*') after each that is executable, an at
sign (`#') after each symbolic link, a percent sign (`%') after
each whiteout, an equal sign (`=') after each socket, and a
vertical bar (`|') after each that is a FIFO.
Mine seems to use some characters yours doesn't and not use some that yours does. So, to resolve the others you need to read the man page that refers to your version.

What does cd * do in bash? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I saw someone use cd * and then use other commands like ls et al after that.
What does it do? Can someone explain it?
The shell expands * to an alphabetical list of the current directory's contents.
cd ignores all arguments after the first.
In lucky and/or extremely controlled circumstances, you can rely on the first item in the wildcard expansion to be the directory you want to cd into.
This may be marginally useful and/or entertaining if you have just created and descended into the current directory and populated it with a single subdirectory. I find it hard to imagine it could have other actual uses.
This command:
cd *
will only work if first list from current path is a directory since it expands to very first entry (file or directory) in the current path. You can see what comes first by doing echo *.
I would suggest not really relying on it since alphabetically first expansion can give you a file also like .bashrc or some other file name starting with dot.

Bash: troubles with find--not finding existing files [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
Not sure what mistake I am making, but find is not returning anything. What is wrong with my syntax? I have consulted several online resources and my syntax seems identical to the suggested commands.
Example:
~$ find /home/foo/ -name bar
~$ sudo find /home/foo/ -name bar
Both return nothing, when there are files meeting the search criteria within the directory.
This is on Ubuntu 12.
The tripping point is, that find /home/foo/ -name bar will search for a file exactly named bar, and will not find foobar or barfly. If you want to search for a part of the filename, you have to use wildcards (most oftne *). Be aware, that shell expansion is likely to fiddle with your wildcard patterns, so use quoting: find /home/foo/ -name '*bar*'

Resources