Tag Info

Hot answers tagged

55

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


35

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


25

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


23

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.


18

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


17

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


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


14

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


13

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


13

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


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

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


12

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


12

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


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

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


11

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


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

In the bash shell, !45 returns that command from the command history (or !32 or !873). An event designator is a reference to a command line entry in the history list. Unless the reference is absolute, events are relative to the current position in the history list. ! Start a history substitution, except when followed by a space, tab, the ...


10

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


10

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


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.


9

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


9

Have you looked at Lucene or Sphinx? While you will need to initially parse the documents you want to index, once that's done, either one can search from the cli. For Lucene, there is some info on doing this available. Sphinx, is a bit more vague, but there is also some documentation available. You can pass structured XML data of your choice to sphinx ...


9

Grep is doing all right. That file does not contain any lines with ":youtube.com". If you want to match all that lines with : you could use grep ":.*youtube\.com" UPD: As you've update your question, I need try to answering second part. From the list above (youtube.com, youtube.com.br), I only should get youtube.com, but I don't get anything. ...


9

You can try the following, to confirm upon deleting each file first: $ find /path/to/dir -type f -name "*.txt" -empty -ok rm {} \; or if you feel more confident: $ find /path/to/dir -type f -name "*.txt" -empty -exec rm {} \;


9

GNU grep has the following options: grep --only-matching --ignore-case --fixed-strings --file /usr/share/dict/british-english-insane /path/to/file.txt This outputs strings found one-per-line. Here /usr/share/dict/british-english-insane is a wordlist provided by the Debian package wbritish-insane.


9

With GNU, or FreeBSD or NetBSD or OpenBSD (and potentially others) awk: find . -type f -exec awk ' /^#!.*python/{print FILENAME} {nextfile}' {} + Would look only at the first line of each file and would run as few awks as necessary. The nextfile statement above is not standard but is found in a few implementations including the GNU one (which is ...


9

Entering : and then the beginning of the command previously issued followed by Up will retrieve the matching command. If there is more than one option available, you can cycle through them with Up and Down.


8

A good place to find software, especially for Unix and Linux, is freshmeat. It is a well established site that lists software projects together with a short description, license information, popularity and vitality stats, information about which programming language is used and much more, searchable by subject.



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