Hot answers tagged

90

locate(1) has only one big advantage over find(1): speed. find(1), though, has many advantages over locate(1): find(1) is primordial, going back to the very first version of AT&T Unix. You will even find it in cut-down embedded Linuxes via Busybox. It is all but universal. locate(1) is much younger and nonstandard. The earliest ancestor of ...


45

Install the package pdfgrep, then use the command: find /path -iname '*.pdf' -exec pdfgrep pattern {} +


40

If you have poppler-utils installed (default on Ubuntu Desktop), you could "convert" it on the fly and pipe it to grep: pdftotext my.pdf - | grep 'pattern' This won't create a .txt file.


36

Here is one way to get the exact output you're looking for: $ grep -nFx "$(sort sentences.txt | uniq -d)" sentences.txt 1:This is sentence X 4:This is sentence X Explanation: The inner $(sort sentences.txt | uniq -d) lists each line that occurs more than once. The outer grep -nFx looks again in sentences.txt for exact -x matches to any of these lines ...


33

You can access this via the forward-search-history function which is bind per default to ctrl+s. Unfortunately ctrl+s is used to signal xoff per default which means you can't use it to change the direction of the search. There are two solutions for solving the problem, one disabling sending the xoff/xon signaling and the other change the keybinding for ...


31

If you want to grep recursively in all .eml.gz files, you can use: find -name \*.eml.gz -print0 | xargs -0 zgrep "STRING" You have to escape the first '*' so that the shell does not interpret it. "-print0" tells find to print a null character after each file it finds; "xargs -0" reads from standard input and runs the command after it for each file; ...


24

You may have a look at rlocate, a reimplementation of locate that is always up-to-date. Another interesting project is recoll which also supports real time indexing and allows you (like beagle) additionally do full-text searches. Finally I should mention doodle which also supports real time indexing. For doodle there are some nice frontends like catfish. ...


20

Add ~i (short for ?installed) to match the installed packages whose name contains bash: aptitude search '~i bash' To match whose description contains bash. aptitude search '~i ~d bash' To limit to the ones that are not installed: aptitude search '!~i bash'


18

Try this trick: man chmod | less +'/a\+x' or man chmod | more +'/a\+x' With a backslash before the + sign because what comes after / is an extended regular expression.


18

For quickly getting help on a Bash builtin, use help: help read is what you want. For man-page-like formatting, use help -m read or, even better, help -m read | less If you still insist on looking for it in the man page, I find what quickly gets me to a command's explanation is /^\s*read [[] This works because when a command is first explained, ...


17

search and limit can also actually search inside messages, depending on the search patterns you give. From the Patterns subsection of the Mutt reference: ~b EXPR messages which contain EXPR in the message body ~B EXPR messages which contain EXPR in the whole message That is, ~b only searches in the body, whereas ~B also searches in the ...


17

The first place to look is your distribution's package list. That's where you'll find the easiest-to-install programs. Some package management tools provide advanced ways of searching it. On Debian and Debian-based distributions (e.g. Ubuntu), you can search package descriptions with apt-cache search or aptitude search (on the command line), or through the ...


16

There's a lot of confusion here because there isn't just one zgrep. I have two versions on my system, zgrep from gzip and zgrep from zutils. The former is just a wrapper script that calls gzip -cdfq. It doesn't support the -r, --recursive switch.1 The latter is a c++ program and it supports the -r, --recursive option. Running zgrep --version | head -n 1 will ...


15

You have a lot of options! pdftotext from poppler has already been mentioned. There's a Haskell program called pdf2line which works well. calibre's ebook-convert commandline program (or calibre itself) is another option; it can convert PDF to plain text, or other ebook-format (RTF, ePub), in my opinion it generates better results than pdftotext, although ...


15

$ find . -type f -print0 | xargs -0 grep foo $ grep -r foo . # GNU grep only and in zsh with setopt extendedglob, $ grep foo **/*(.)


15

locate uses a prebuilt database, which should be regularly updated, while find iterates over a filesystem to locate files. Thus, locate is much faster than find, but can be inaccurate if the database -can be seen as a cache- is not updated (see updatedb command). Also, find can offer more granularity, as you can filter files by every attribute of it, while ...


14

I generally use a tool called pcregrep which can be installed in most of the linux flavour using yum or apt. For eg. Suppose if you have a file named testfile with content abc blah blah blah def blah blah blah You can run the following command: $ pcregrep -M 'abc.*(\n|.)*def' testfile to do pattern matching across multiple lines. Moreover, you can ...


14

I find it surprising how fast does locate work or the autocompletion (that I know) work in linux. ... Is there any indexing being done in the background or how is this achieved? This is actually two completely distinct questions. locate uses an index (slocate stores it in /var/lib/slocate/), that is updated by a nightly cron job. This nightly job ...


14

You can concatenate several paths for grep to look for: grep -r "some string" /code/internal/dev/*.cs /code/public/dev/*.cs /code/tools/*.cs


13

I think what most closely fits what you're looking for is apropos (a.k.a. man -k), which will search the one-line descriptions preceding every manpage. If you want to search through whole manpages, at least man-db supports man -K, which does exactly this (man-db is the man implementation used on at least Debian derivatives by default). IIRC, man -K is ...


12

After more searching, it looks like the easiest way to do this is with \_s. So for example: /hello\_sworld


12

You may find q: useful. It opens the command-line window. The command-line window looks like this: I tried to make an animation of its usage: Also see c_CTRL-F, which opens the command-line window from command mode. You can also re-run the last command from normal mode by typing @:.


12

Incremental search has this feature, but the replace functions don't. Fortunately, incremental search does have a way to switch to replace mode once you've selected a search term. So: Press C-s to switch to incremental search mode Press C-w to yank the current word into the search buffer You can keep pressing it to append multiple words, and you can also ...


11

From the Surfraw website: Surfraw provides a fast unix command line interface to a variety of popular WWW search engines and other artifacts of power. It reclaims google, altavista, babelfish, dejanews, freshmeat, research index, slashdot and many others from the false-prophet, pox-infested heathen lands of html-forms, placing these wonders where they ...


11

Here's a sed one that will give you grep-like behavior across multiple lines: sed -n '/foo/{:start /bar/!{N;b start};/your_regex/p}' your_file How it works -n suppresses the default behavior of printing every line /foo/{} instructs it to match foo and do what comes inside the squigglies to the matching lines. Replace foo with the starting part of the ...


11

You can use zle's history-search functionality: bindkey "^[[A" history-beginning-search-backward bindkey "^[[B" history-beginning-search-forward This binds Up and Down (adjust for your own escape sequences) to a history search, backwards and forwards, based upon what has already been entered at the prompt. So, if you were to enter "vim" and hit Up, zsh ...


11

Assuming I understood your question, you are possibly overcomplicating it. This should do find your_directory -type f -name '[az]*[az]' This omits files whose name is a single letter a or z. If you also want to include them, you need to specify another pattern: the name must match either [az]*[az] or [az]. find your_directory -type f \( -name '[az]*[az]' ...


11

From man man: -K, --global-apropos Search for text in all manual pages. This is a brute-force search, and is likely to take some time; if you can, you should specify a section to reduce the number of pages that need to be searched. Search terms may be simple strings (the default), or regular expressions if the --regex ...


10

The --exclude option takes globs that are matched against file names, not directories or full paths: --exclude=GLOB Skip files whose base name matches GLOB (using wildcard matching). A file-name glob can use *, ?, and [...] as wildcards, and \ to quote a wildcard or backslash character ...


10

You seem to be looking for find: find . -type f -name "*foo*" would look for file names containing foo in the name in the current directory and subdirectories. find . -maxdepth 1 -type f -name "*foo*" would look for file names containing foo only in the current directory.



Only top voted, non community-wiki answers of a minimum length are eligible