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

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*'

Related

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

how to grep only current directory for specific files [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 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.

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.

force symbolic only links [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
So, I had a brainfart and deleted some hardlinks (and the linked files as well). I don't normally use hard links, so is there a better way to force symbolic links by default than
alias ln='ln -s'
in my ~/.bashrc
?
I suggest in this case, you create alias with another name, otherwise when you really want to create a hard-link, you have to type \ln ... (or link)
if you have
alias lns='ln -s'
you could usually type lns ... for symbolic links, when you need to create hard link, you could type ln.... also you still have possibility to exercise typing ln -s ... manually....
hope it helps

Is there an autocomplete feature for folder and file names in bash? [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 10 years ago.
Improve this question
I need to navigate to a certain directory and then execute a script located there.
I am using cd folder_name to navigate to the next directory.
One folder has a very long name (with white spaces). Is there a way to type only the first few letters and then use a shortcut key to autocomplete with the first matching name, or to navigate through possible matches?
The same if I want to perform a command on a certain file (e.g. chmod XXX file_name), is there a way to get the name to appear after I type a few letters of the filename?
The shell I am using is bash-3.2 in OS X 10.7.4.
Yes, Bash supports auto-completion (personally, it's one of my favorite features). Use the Tab key to complete what you've typed (note that it's case-sensitive). The Advanced Bash-Scripting Guide has a section on an introduction to programmable completion. You can enable completion to complete command names and more!

Resources