Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
0
votes
1
answers
82
views
Uninstalled package but command remained usable as user (command not found with sudo)
I recently installed `silversearcher-ag` with `sudo` and uninstalled it as it required `sudo` to run the command every single time. The command I used to install and uninstall this package respectively: ``` # installation sudo apt install silversearcher-ag ``` ``` # uninstallation sudo apt remove si...
I recently installed
silversearcher-ag
with sudo
and uninstalled it as it required sudo
to run the command every single time.
The command I used to install and uninstall this package respectively:
# installation
sudo apt install silversearcher-ag
# uninstallation
sudo apt remove silversearcher-ag
sudo apt autoremove
As mentioned by the comment, here's the output for type -a ag
:
ag is aliased to `apt-get update;apt-get dist-upgrade'
After uninstallation, I found that if I do sudo ag
, the command would correctly fail due to command not found; however, if I simply do a ag
as user, I was still able to run the command ( although the command actually failed due to lack of permission, i.e., it has to be run with sudo
every single time).
I've looked at places like /usr/bin/
, /usr/local/bin
, /usr/sbin/
, /usr/local/sbin
, sbin/
, bin/
, the ag
command didn't reside in any of them.
whereis
, locate
returned no matching results.
I've also tried
sudo apt purge silversearcher-ag
sudo apt purge silversearcher-ag*
The first command actually removed some additional affliations, the second simply removed none. After these two commands the ag
was still there.
What do I need to do to completely remove this package?
I am running MX Linux 23-ahs, based on Debian 12 bookworm.
stucash
(111 rep)
Oct 16, 2024, 04:50 PM
• Last activity: Oct 16, 2024, 05:53 PM
16
votes
4
answers
13086
views
How to ignore multiple files with `ag` The Silver Searcher
There is an option `--ignore` which allows specifying files to ignore. At the moment I only managed to ignore multiple files by doing `--ignore file1 --ignore file2.......` Trying to use `--ignore "*assets*|*scripts*"` does nothing. So is there a catch I'm not aware of?
There is an option
--ignore
which allows specifying files to ignore. At the moment I only managed to ignore multiple files by doing --ignore file1 --ignore file2.......
Trying to use --ignore "*assets*|*scripts*"
does nothing. So is there a catch I'm not aware of?
T.Chmelevskij
(263 rep)
May 3, 2017, 06:11 PM
• Last activity: Dec 18, 2023, 04:21 PM
1
votes
2
answers
224
views
How can I limit the file size of files searched by ag?
I don't want [ag](https://github.com/ggreer/the_silver_searcher) to search files larger than 2Mio. I can't find anything like a --file-size flag to the ag command, but is there any way to tell it that? I'm getting lots of ``` ERR: Skipping foo.bar: pcre_exec() can't handle files larger than 21474836...
I don't want [ag](https://github.com/ggreer/the_silver_searcher) to search files larger than 2Mio.
I can't find anything like a --file-size flag to the ag command, but is there any way to tell it that?
I'm getting lots of
ERR: Skipping foo.bar: pcre_exec() can't handle files larger than 2147483647 bytes.
Jason Hunter
(227 rep)
Oct 21, 2023, 11:18 PM
• Last activity: Oct 22, 2023, 09:34 AM
1
votes
0
answers
341
views
How can I recursively search file contents by ANDed patterns and print the output like ag/the silver searcher would?
This will be easier to explain via example. Here are my input files: ``` file1: x x a b c x x file2: x x c b a x x file3: x x x x a b c x x x x file4: x x x x c b a x x x x file5: x x a b x x file6: x x x x b c x x x x file7: x x x x b b x x x x ``` I want to search for files that have regexp `a` AN...
This will be easier to explain via example. Here are my input files:
### ag -C 1 --pager="less -R" "regexp1|regexp2" ...
Here, I am giving
file1:
x
x
a
b
c
x
x
file2:
x
x
c
b
a
x
x
file3:
x
x
x x a b c x x
x
x
file4:
x
x
x x c b a x x
x
x
file5:
x
x
a b
x
x
file6:
x
x
x x b c x x
x
x
file7:
x
x
x x b b x x
x
x
I want to search for files that have regexp a
AND c
. This will return files 1-4.
I want the output to look as close as possible to ag -C --pager="less -R" regexp
's output. Here's what that would look like (I am surrounding results with angle brackets to represent color highlighting):
file1:
2: x
3:
4: b
5:
6: x
file2:
2: x
3:
4: b
5:
6: x
file3:
2: x
3: x x b x x
4: x
file4:
2: x
3: x x b x x
4: x
Or maybe ag
would print it like this:
file1:
2: x
3:
4: b
--
4: b
5:
6: x
I'm not sure, but this detail doesn't matter to me. Here's what does:
1. The highlighting
1. The relative path of the file above the results
1. The features less
provides for navigation and search
1. It can find multiple regexps ANDed together
1. That -C
option still exists on the command line
The line numbers are a nice to have, but not necessary.
---
I've tried many many things, and this is the closest I've gotten:
## Step 1: Precompile a file list of each individual regexp
for x in $array_of_regexp_file_names;
do r=${x/.txt/} ; # remove .txt from the end
ag -il $r | sort > $x & ; # sort the list of FILES with this single regexp
done
This gives a list of files for each regexp, sorted by filename.
## Step 2: Use ag to search the intersection of 2+ file lists
I will break down the following:
ag -C 1 --pager="less -R" "regexp1|regexp2" $(comm -12 regexp1.txt regexp2.txt)
### $(comm -12 regexp1.txt regexp2.txt)
This command finds the intersection of two file lists. That is, the red in this picture:

ag
a regexp that I *know* exists in every file in that intersection. That may seem redundant, but I'm doing it because want those words highlighted in the output. It makes my life 1000x easier.
Here's the problem: that intersection is so many files, running the command gives me this output:
zsh: argument list too long: ag
Other than that, my workaround works. I've tested this by running a command like this:
ag -C 1 --pager="less -R" "regexp1|regexp2" $(comm -12 patter1.txt regexp2.txt | head -10)
The problem is the intersecting list is so long, it doesn't fit on the command line. If ag
provided an option to pass a list of files to search, I could get past this, but it doesn't have that functionality.
Regardless, I'm hoping I don't need to: I'm assuming there's a much easier solution to this problem, I just don't know what it is.
---
Edit: To solidify some highlighting rules, here are some other examples:
### Example 1
regexs:
regex1 = a.
regex2 = .b
input
file8:
x
x
abc
x
x
Output:
2: x
3: c
4: x
### Example 2
regexs:
regex1 = foo
regex2 = oba
input
file9:
x
x
foobar
x
x
Output:
2: x
3: bar
4: x
I picked these outputs because that's what grep and ag already do, but I'm pretty ambivalent about both of these scenarios, so if these examples are challenging to implement, I don't mind if highlighting works differently in these edge cases; in general, *my* regexps won't overlap.
Daniel Kaplan
(1070 rep)
Mar 10, 2022, 10:19 AM
• Last activity: Mar 11, 2022, 06:06 AM
1
votes
1
answers
271
views
How do I configure ag so that it will also search for files beginning with a "."?
I'm using ag v 2.2. How do I configure ag so that it will search for files beginning with a "." in addition to all other files? I'm noticing I have a file like so $ cat client/.env.production REACT_APP_PROXY=https://map.chicommons.coop but when I search with "ag" using a term in that file, the term...
I'm using ag v 2.2. How do I configure ag so that it will search for files beginning with a "." in addition to all other files? I'm noticing I have a file like so
$ cat client/.env.production
REACT_APP_PROXY=https://map.chicommons.coop
but when I search with "ag" using a term in that file, the term doesn't come up ...
$ ag 'map\.chicom' .
web/directory/settings.py
28:ALLOWED_HOSTS = ['127.0.0.1', 'localhost', 'dev.chicommons.coop', 'map.chicommons.coop']
client/config.js
3: ? "map.chicommons.com"
Dave
(2808 rep)
Feb 4, 2022, 01:55 AM
• Last activity: Feb 4, 2022, 09:39 AM
0
votes
0
answers
132
views
How to get shell TAB-completion to work when I redirect grep ag ack output to vim?
I define `ag` as bash function, to make usage relatively transparent ```sh ag() { [ $# -gt 0 ] && vim -c silent\ SyntasticToggleMode -c copen -q Vim: Warning: Output is not to a terminal ``` Only way out is to kill stuck vim process from another shell. What's going wrong here and how can this bash f...
I define
ag
as bash function, to make usage relatively transparent
ag() { [ $# -gt 0 ] && vim -c silent\ SyntasticToggleMode -c copen -q
Vim: Warning: Output is not to a terminal
Only way out is to kill stuck vim process from another shell.
What's going wrong here and how can this bash function be upgraded (or find some alternative) to make it TAB-completion compatible ?
EDIT ag
doesn't ship any upstream completion
$ [git:master] complete -p ag
-bash: complete: ag: no completion specification
lkraav
(1201 rep)
May 9, 2021, 06:51 PM
• Last activity: May 10, 2021, 05:16 PM
1
votes
0
answers
145
views
How to make ag search "non-standard" langauge files?
I'm using Silver Searcher, `ag`, version 2.1.0 on Ubuntu. I'm trying to search for the string `aStar` in Haskell files in the current directory tree. (The files are text files with extension `.hs`.) The behaviour isn't what I expect. ``` $ ag aStar ``` finds no matches. ``` ag --haskell aStar ``` fi...
I'm using Silver Searcher,
ag
, version 2.1.0 on Ubuntu. I'm trying to search for the string aStar
in Haskell files in the current directory tree. (The files are text files with extension .hs
.)
The behaviour isn't what I expect.
$ ag aStar
finds no matches.
ag --haskell aStar
finds no matches.
ag --haskell --all-text aStar
finds the correct matches in the .hs
files.
ag --all-text aStar
finds the correct matches in .hs
files, plus a bunch in some temporary files I don't want searched.
Any suggestions on what I'm doing wrong, and why the --haskell
flag doesn't make ag
search the Haskell files?
Neil Smith
(111 rep)
Jan 1, 2020, 03:05 PM
71
votes
2
answers
44507
views
How do I use ag to look for text in files with certain extensions?
I'm using `ag` ([The Silver Searcher][1]) version 0.31.0. I can easily look for a string in a bunch of files using: localhost:workspace davea$ ag 'ftp' . But what if I only want to scan files with certain extensions? I tried this: localhost:workspace davea$ ag 'ftp' .java ERR: Error stat()ing: .java...
I'm using
ag
(The Silver Searcher ) version 0.31.0. I can easily look for a string in a bunch of files using:
localhost:workspace davea$ ag 'ftp' .
But what if I only want to scan files with certain extensions? I tried this:
localhost:workspace davea$ ag 'ftp' .java
ERR: Error stat()ing: .java
ERR: Error opening directory .java: No such file or directory
but got the errors you see above.
Dave
(2808 rep)
Feb 8, 2017, 09:11 PM
• Last activity: Sep 16, 2019, 07:54 PM
18
votes
1
answers
12350
views
How is ripgrep different from silver searcher ag?
Are these related? Which is faster? Can either be limited to directory-names? https://github.com/BurntSushi/ripgrep https://github.com/ggreer/the_silver_searcher
Are these related?
Which is faster?
Can either be limited to directory-names?
https://github.com/BurntSushi/ripgrep
https://github.com/ggreer/the_silver_searcher
johny why
(371 rep)
Aug 24, 2018, 09:47 PM
• Last activity: Jun 10, 2019, 09:16 PM
0
votes
0
answers
246
views
How to create a regex matching a custom string at the beginning of line while ignoring all preceding whitespaces via ag silversearcher?
Give an `example` file with the content: // find me val ignore me = "" // I should not be found // find me // find me I want to find all the lines with `find me` using ag silversearcher. Basically, it should match any line optionally starting with any white space and a double space `//`. I know that...
Give an
example
file with the content:
// find me
val ignore me = "" // I should not be found
// find me
// find me
I want to find all the lines with find me
using ag silversearcher.
Basically, it should match any line optionally starting with any white space and a double space //
.
I know that:
ag ^// example
only yields in the first line without spaces.
For the beginning of the line I know I can use ^
, for whitespace it should be \s
, and my custom string should either be //
or it may need to be to escaped to: \/\/
That's why I thought:
ag ^\s*// example
ag ^\s*\/\/ example
Should do the trick, yet it finds also only the first line.
How can I match all the lines starting with white space and my custom string?
k0pernikus
(16549 rep)
Nov 30, 2018, 04:10 PM
0
votes
3
answers
50
views
Is it possible to print a search pattern result just until it hits a blank newline in terminal?
Say for example I have a file with contents like this: # TODO: Optimize this. alias bash='start bash' # FIXME: Just fix this. alias fix='there is something wrong with this What I want is if I search for pattern `TODO:` it should only print result like this: # TODO: Optimize this. alias bash='start b...
Say for example I have a file with contents like this:
# TODO: Optimize this.
alias bash='start bash'
# FIXME: Just fix this.
alias fix='there is something wrong with this
What I want is if I search for pattern
TODO:
it should only print result like this:
# TODO: Optimize this.
alias bash='start bash'
Is this possible?
cevhyruz
(477 rep)
Nov 5, 2018, 05:29 PM
• Last activity: Nov 6, 2018, 01:13 AM
3
votes
2
answers
1197
views
how to issue a `start of string` pattern for ag
I want to find every file in from the current dir and downwards whose filename starts with `foo` using __[`ag`](https://github.com/ggreer/the_silver_searcher)__(the silver searcher). I have tried: ag -g '^foo' ag -g '\^foo' ag -g '\Afoo' no luck. But it should work as `ag` implements PCRE syntax, ri...
I want to find every file in from the current dir and downwards whose filename starts with
foo
using __[ag
](https://github.com/ggreer/the_silver_searcher)__(the silver searcher). I have tried:
ag -g '^foo'
ag -g '\^foo'
ag -g '\Afoo'
no luck.
But it should work as ag
implements PCRE syntax, right? What am I missing here?
ninrod
(389 rep)
Aug 11, 2016, 08:35 PM
• Last activity: Feb 2, 2018, 02:11 PM
0
votes
1
answers
1234
views
search with and without a pattern with ag
With two files with echo 'example.com/call_me?param' > file1.txt echo 'example.com/call_me_maybe?param' >> file1.txt echo 'example.com/call_me?' >> file1.txt echo 'example.com/call_me?param' > file2.txt echo 'example.com/call_me_maybe?' >> file2.txt $ ag -v '\?param' file2.txt 2:example.com/call_me_...
With two files with
echo 'example.com/call_me?param' > file1.txt
echo 'example.com/call_me_maybe?param' >> file1.txt
echo 'example.com/call_me?' >> file1.txt
echo 'example.com/call_me?param' > file2.txt
echo 'example.com/call_me_maybe?' >> file2.txt
$ ag -v '\?param'
file2.txt
2:example.com/call_me_maybe?
file1.txt
3:example.com/call_me?
$ ag '\/call_me_maybe' -v '\?param'
ERR: Error stat()ing: \?param
ERR: Error opening directory \?param: No such file or directory
$ ag '\/call_me_maybe' -v '\?param' file1.txt
ERR: Error stat()ing: \?param
ERR: Error opening directory \?param: No such file or directory
file1.txt
1:example.com/call_me?param
3:example.com/call_me?
I would like to search for one term and exclude the other pattern. Is it possible in one command?
I'm using ag because it digging into
log.gz
files. So I can use zgrep
or ag -z
.
PockPock
(103 rep)
Jan 17, 2018, 02:06 PM
• Last activity: Jan 17, 2018, 02:31 PM
1
votes
0
answers
53
views
Can ag search sub-directories with the same name, within a bunch of directories?
Given a directory structure such as: dev/project1/assets/** dev/project2/assets/** dev/project3/assets/** Is it possible to search, from within the dev directory all assets directories only. Given that the project directories will include other sub-directories. I don't want to have to explicitly nam...
Given a directory structure such as:
dev/project1/assets/**
dev/project2/assets/**
dev/project3/assets/**
Is it possible to search, from within the dev directory all assets directories only. Given that the project directories will include other sub-directories. I don't want to have to explicitly name each project directory. But something like search on
/*/*/assets
. So x directories deep, with a given name.
Kris
(255 rep)
Oct 23, 2017, 07:52 AM
• Last activity: Oct 23, 2017, 11:35 AM
3
votes
1
answers
438
views
No output using parallel in tandem with ag or ack
I have a list of java reserved words, first letter capitalised. $ tail -n5 ~/reservedjava.txt Break While True False Null I'm trying to look through all my java source code to find methods that look like `getWhile()`. cat ~/reservedjava.txt | parallel 'ag "get{}\(\)$"' This shows me nothing. Now, I...
I have a list of java reserved words, first letter capitalised.
$ tail -n5 ~/reservedjava.txt
Break
While
True
False
Null
I'm trying to look through all my java source code to find methods that look like
getWhile()
.
cat ~/reservedjava.txt | parallel 'ag "get{}\(\)$"'
This shows me nothing. Now, I know that I have a method getBreak()
:
$ ag "getBreak\(\)$"
src/main/java/Foo.java
154: public Break getBreak()
Here's what a dry run looks like:
$ cat ~/reservedjava.txt | parallel --dry-run 'ag "get{}\(\)$"' | tail -n5
ag "getBreak\(\)$"
ag "getWhile\(\)$"
ag "getTrue\(\)$"
ag "getFalse\(\)$"
ag "getNull\(\)$"
I'm using gnu parallel (v. 20130722) and the silver searcher (ag) (v. 0.18.1). If it makes a difference, I'm on Fedora 19, but have compiled these utilities myself. I get the same result with ack (v. 2.12).
djeikyb
(348 rep)
Jan 8, 2014, 10:00 PM
• Last activity: Sep 13, 2017, 10:49 AM
0
votes
1
answers
430
views
Ack/Ag does not return search result without *
I am trying to search text in a directory and it turned out that the following syntaxes do not return any result ack -i "0xabcdef" ./ ack -i "0xabcdef" ack -i "0xabcdef" . while the following command works ack -i "0xabcdef" * Can someone explain why that is the case? What is the significance of `*`?...
I am trying to search text in a directory and it turned out that the following syntaxes do not return any result
ack -i "0xabcdef" ./
ack -i "0xabcdef"
ack -i "0xabcdef" .
while the following command works
ack -i "0xabcdef" *
Can someone explain why that is the case? What is the significance of
*
? I also noticed that the directory has symbolic links.
user2065276
(105 rep)
Aug 1, 2017, 03:12 PM
• Last activity: Aug 2, 2017, 12:31 AM
6
votes
2
answers
905
views
How to make this search faster in fgrep/Ag?
I am thinking methods to make the search faster and/or better which principally uses `fgrep` or `ag`. Code which searches the word `and` case-insensitively at `$HOME`, and redirects a list of matches to `vim` find -L $HOME -xtype f -name "*.tex" \ -exec fgrep -l -i "and" {} + 2>/dev/null | vim -R -...
I am thinking methods to make the search faster and/or better which principally uses
fgrep
or ag
.
Code which searches the word and
case-insensitively at $HOME
, and redirects a list of matches to vim
find -L $HOME -xtype f -name "*.tex" \
-exec fgrep -l -i "and" {} + 2>/dev/null | vim -R -
It is faster with ag
because of parallelism and ack
find -L $HOME -xtype f -name "*.tex" \
-exec ag -l -i "and" {} + 2>/dev/null | vim -R -
Statistics
---
Small group average statistics with fgrep
and ag
by time
fgrep ag terdon1 terdon2 terdon3 muru
user 0.41s 0.32s 0.14s 0.22s 0.18s 0.12s
sys 0.46s 0.44s 0.26s 0.28s 0.30s 0.32s
Cases terdon1
and terdon3
can be equal fast.
I get great fluctuations with those two.
Some Ranking by sys
time (not best criteria!)
1. terdon1
2. terdon2
3. terdon3
4. muru
5. ag
6. fgrep
Abbreviations
---
- terdon1 = terdon-many-find-grep
- terdon2 = terdon-many-find-fgrep
- terdon3 = terdon-many-find-ag (without F because not exists in ag
)
Other codes
---
muru's proposal in comments
grep -RFli "and" "$HOME" --include="*.tex" | vim -R -
OS: Debian 8.5
Hardware: Asus Zenbook UX303UA
Léo Léopold Hertz 준영
(7138 rep)
Dec 24, 2016, 12:35 PM
• Last activity: Dec 25, 2016, 10:05 AM
2
votes
2
answers
382
views
How do I force ag (the silver searcher) to list empty files
How do I get `ag` to list all files, including empty ones? +ravi@boxy:~$ mkdir new && cd new +ravi@boxy:~/new$ echo stuff > non-empty && touch empty +ravi@boxy:~/new$ ag -ul non-empty +ravi@boxy:~/new$ How do I get `empty` to appear in the example above?
How do I get
ag
to list all files, including empty ones?
+ravi@boxy:~$ mkdir new && cd new
+ravi@boxy:~/new$ echo stuff > non-empty && touch empty
+ravi@boxy:~/new$ ag -ul
non-empty
+ravi@boxy:~/new$
How do I get empty
to appear in the example above?
Tom Hale
(32922 rep)
Aug 14, 2016, 12:47 PM
• Last activity: Nov 26, 2016, 05:50 AM
1
votes
1
answers
486
views
Why is ag printing blank lines from this file?
I want to use [ag](https://github.com/ggreer/the_silver_searcher/blob/master/doc/ag.1.md) to print the classes and their methods in a python file. I thought that this would be easy using: ag --context=0 --nocolor -os '^\s*(def|class)\s+[_A-Za-z]*' prog.py but for reasons I don't understand this is a...
I want to use [ag](https://github.com/ggreer/the_silver_searcher/blob/master/doc/ag.1.md) to print the classes and their methods in a python file. I thought that this would be easy using:
ag --context=0 --nocolor -os '^\s*(def|class)\s+[_A-Za-z]*' prog.py
but for reasons I don't understand this is also matching blank lines. For example, if you make prog.py the following
class MyFavouriteClass
def __init__
def __contains__
blah
class MyNextFavouriteClass
def _repr_
def __iter__
then it returns the full file, including the blank lines, *except* for the line containing
blah
. Of course, I can always pipe the output into something else to remove the blank lines but I'd rather get it right the first time.
I suspect that the problem has nothing to do with the regular expression and, instead, that it's a feature of ag
's --context
, --after
and --before
flags but I can't find a combination of these that does what I want.
Any ideas?
Andrew
(113 rep)
Aug 10, 2016, 06:46 AM
• Last activity: Aug 10, 2016, 10:54 PM
Showing page 1 of 19 total questions