Hot answers tagged

84

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 ...


38

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.


37

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


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 ...


31

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 ...


21

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

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; ...


19

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

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, ...


18

Try this trick : man foobar | less +/searched_string or man foobar | more +/searched_string this should do the joke.


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 ...


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

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 ...


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

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

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 ...


13

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 ...


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 @:.


11

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


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

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

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

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 ...


10

You can do either of grep pattern_search . # does a normal grep on the current directory grep pattern_search * # use a normal grep on all the globbed files from the current directory grep -R pattern_search . # use a recursive search on the current directory grep -H pattern_search * # prints filename when the files are more than one. ‘-H’ Other ...


10

Try the pgrep command, which will output the PID of the command you're interested in. pgrep selenium To actually kill the process, use the companion pkill command. pkill selenium


10

There are different regular expression dialects; some (e.g. Perl's) do not require backslashes in the quantification modifier (\d{2}), some (e.g. sed) require two (\d\{2\}), and in Vim, only the opening curly needs it (\d\{2}). That's the sad state of incompatible regular expression dialects. Also note that for matching exact numbers, you have to anchor the ...


10

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 ...



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