Archive for January, 2009

Need to find a SMALL amount of text in a BIG directory? No problem!

Have you ever tried to grep in a directory that has a vast amount of files and you received an error like this? (below)

If so, there is a simple way around this. Just use this: find . | xargs grep "yahoo" * | more. I will break down these processes for you:

  • find . - Find is a command that outputs the location of a file. In this case by specifying a ., the search will only be done in the present directory.
  • xargs - This allows a command to be executed from standard input. This also helps force the grep command (coming next) to return output, even when the directory is too large.
  • grep - The way we will be using this command is to search through a file for a specific string. If you are looking for straight text, it is best to use quotes (e.g. “text”) to help the command line decipher exactly what you are looking for. More info on grep can be found on this earlier post.
  • more - This command is optional for this process. More would be best used if you were expecting a full page of output returned from your search, and want to be prompted for the next page. This option would be very beneficial if the string you are searching for would be common in your results.

Apropos

Ever wanted to use a command to do something, but couldn’t quite figure out the actual command to accomplish what you need done? Try using apropos! Apropos is a way to browse through the help area of the Unix/Linux operating system for a command that will help achieve your goal. For example, if I wanted to find commands that relate to “secure”, I would enter apropos secure at the command line, and the kernel would return the results listed below along with any services that involve ’secure’:

As always, if you wanted to get a more elaborate description on a command or service, you can always use man (shortened for: manual). This will display a full description, and various options of a command which you have found using apropos.