counsel-locate
essentially just calls the system locate
command (see man 1 locate
).
You can control which executable is called by customising the user option locate-command
from the built-in package locate.el
.
You can further control the exact command that counsel-locate
issues by customising the user option counsel-locate-cmd
.
On GNU/Linux, the default command issued by counsel-locate
is:
locate -i --regex REGEXP
where REGEXP
is the user input interpreted as a regular expression.
So, to find any .txt
files under any directory called Temp
, you need an input like Temp \.txt\'
or Temp.*\.txt\'
(note that the literal full stop .
has to be escaped, that \'
anchors the file extension at the end of the file name, and that Ivy translates the first pattern into something equivalent to the second pattern by default).
To find any .txt
files under a specific directory called Temp
, you need an input like
\`/home/alexeij/Temp \.txt\'
or
\`/home/alexeij/Temp.*\.txt\'
Where the
\`
anchors the search at the start of the file name.
Finally, to start every counsel-locate
search in the current directory, you can write a custom command like the following based on adl's answer:
(defun my-counsel-locate-here ()
"Start `counsel-locate' anchored at `default-directory'."
(interactive)
(counsel-locate (rx bos (literal (file-truename default-directory)) ?\s)))
Then you can issue e.g. M-x my-counsel-locate-here RET \.txt\'
to find all .txt
files under the current directory.
A more direct (but sometimes slower) way of achieving the same thing is M-x counsel-file-jump RET \.txt\'
.
For a fuzzy search analogue, there's also e.g. M-x counsel-fzf RET .txt
.
Update
P.S. [adl/counsel-locate-in-the-current-folder-and-subfolders
] work only for current folder. But I need to find also in all subfolders.
The locate
command usually depends on indexing your filesystem in order to answer queries efficiently. Are you sure the subfolders in question have been indexed already? Usually locate
updates its database daily in the background, but you can force it via updatedb
.
In any case I think adl/counsel-locate-in-the-current-folder-and-subfolders
is working fine (except for the fact that it doesn't quote and anchor regular expressions properly, see the my-counsel-locate-here
example), so the problem is most likely a pilot error/misunderstanding.
M-x counsel-locate $PWD/*.txt
. This command will probably find all txt files in the current folder and its subfolders.counsel-fd-file-jump
fromcounsel-fd
which lists all files under the current directory. You can select.txt
files easily usingivy
.locate
hasn't indexed them, so I don't think it'scounsel-locate
's fault. See my updated answer, as well asman locate
andman updatedb
.