Questions tagged [search]

search is used for questions relating to searching through the contents of files. For searching for filenames using the locate command use the tag locate.

Searching is the practise of looking for a matching strings, with or without the use of regular expressions, in a file or in multiple files.

Searching may involve indexing of the text to search, in particular if there is a lot of data and the searches are frequent and/or have to be fast.

Searching for a match in filenames is often done using locate which has its own tag .

567 questions
266
votes
18 answers

How can I grep in PDF files?

Is there a way to search PDF files using grep, without converting to text first in Ubuntu?
Dervin Thunk
  • 3,429
  • 4
  • 23
  • 21
190
votes
6 answers

How do I grep recursively through .gz files?

I am using a script to regularly download my gmail messages that compresses the raw .eml into .gz files. The script creates a folder for each day, and then compresses every message into its own file. I would like a way to search through this archive…
Kendor
  • 2,001
  • 2
  • 12
  • 5
158
votes
4 answers

locate vs find: usage, pros and cons of each other

In Linux and Unix systems there are two common search commands: locate and find. What are the pros and cons of each? When one have benefits over the other?
m0nhawk
  • 2,628
  • 3
  • 20
  • 28
117
votes
14 answers

How can I search history with text already entered at the prompt in zsh?

In zsh, I know that I can search history with Ctrl+r. However, oftentimes I start to type a command directly at the prompt, but then realize I should be searching history. When I hit Ctrl+r, it brings up a blank history search prompt like…
Sean Mackesey
  • 1,547
  • 2
  • 10
  • 14
88
votes
3 answers

Unhighlight last search in 'less'

When you use a / forward search or a ? backward search in less, all instances of the file get highlighted. After I've found the instance of the word I'm looking for, what is the most correct way to unhighlight something? Currently I just press /…
VxJasonxV
  • 1,507
  • 2
  • 11
  • 12
74
votes
5 answers

Quickly find which file(s) belongs to a specific inode number

I know of this command: find /path/to/mountpoint -inum but it is a very slow search, I feel like there has to be a faster way to do this. Does anybody know a faster method?
Alex
  • 936
  • 1
  • 6
  • 9
74
votes
4 answers

Limit grep context to N characters on line

I have to grep through some JSON files in which the line lengths exceed a few thousand characters. How can I limit grep to display context up to N characters to the left and right of the match? Any tool other than grep would be fine as well, so long…
dotancohen
  • 15,494
  • 26
  • 80
  • 116
65
votes
13 answers

Is there a file search engine like "Everything" in Linux?

On Windows there a nice file search engine called Everything, which is (unlike find) very fast and (unlike locate) always returns up to date results. AFAIK it works by filling a database from the NTFS journal (it doesn't work with other…
maaartinus
  • 4,979
  • 7
  • 30
  • 29
62
votes
1 answer

ripgrep: print only filenames matching pattern

Using ripgrep (rg), can I print only the filenames which match a given pattern? There are two separate things I'm trying to do: Match the pattern to the pathname itself (like ag -g pattern) Match the pattern to the contents of the file and print…
Tom Hale
  • 28,728
  • 32
  • 139
  • 229
62
votes
2 answers

How do I use ag to look for text in files with certain extensions?

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…
Dave
  • 2,348
  • 21
  • 54
  • 84
49
votes
10 answers

How can I "grep" patterns across multiple lines?

It seems I am misusing grep/egrep. I was trying to search for strings in multiple line and could not find a match while I know that what I'm looking for should match. Originally I thought that my regexes were wrong but I eventually read that these…
Jim
  • 9,750
  • 15
  • 57
  • 84
48
votes
7 answers

Command-line-friendly full-text indexing?

Is there such a thing as a full-text indexing engine, that can be queried from the command line and ideally wouldn't require using a gui at all ? I'm especially interested in indexing my ebooks and papers, so that's a mixture of pdf, epub and a few…
julien
  • 681
  • 1
  • 5
  • 6
45
votes
2 answers

How can I use grep to search multiple unnested directories?

It may sound like I'm asking the same thing as this question, but I have different requirements. This is an example of my filesystem: /code/ internal/ dev/ main/ public/ dev/ main/ release/ tools/ /code/internal/dev/, /code/public/dev/…
Big McLargeHuge
  • 3,044
  • 11
  • 35
  • 49
43
votes
2 answers

How to Navigate within bash's Reverse Search?

Bash offers the functionality to reverse search via Ctrl + R. Then one can type in a part of a command it will show a fitting entry from the history. Assume this is my history: vim foo1 vim foo2 # I want to go here vim foo3 # this is where I land,…
k0pernikus
  • 14,853
  • 21
  • 58
  • 79
42
votes
4 answers

Searching for a string on multiple zip files

I am working on SunOS 5.10. I have a folder that contains about 200 zip files. Each zip file contains only one text file in it. I would like to search for a specific string in all the text files in all the zip files. I tried this (which searches…
ziggy
  • 533
  • 1
  • 5
  • 8
1
2 3
37 38