search

Linux: Recursive file searching with grep -r (like grep + find)

Linux grep FAQ: How can I perform a recursive search with the grep command in Linux?

Solution: find + grep

For years I always used variations of the following Linux find and grep commands to recursively search subdirectories for files that match a grep pattern:

find . -type f -exec grep -l 'alvin' {} \;

This command can be read as, “Search all files in all subdirectories of the current directory for the string ‘alvin’, and print the filenames that contain this pattern.” It’s an extremely powerful approach for recursively searching files in all subdirectories that match the pattern I specify.

Ubuntu ‘apt-get’ list of commands (cheat sheet)

I have a couple of Ubuntu Linux systems, including Raspberry Pi systems, test servers, and production servers. It seems like every time I have to use an apt-get or other apt command, I always have to search for the command I need. To put an end to that, I’m creating this “apt-get reference page.” It’s very terse, as I’ve just written it for myself, but I hope it’s also helpful for others.

How to search for a string in all fields of every table in a MySQL database

Here’s a cool tip: if you want to search for a text string in all fields of all tables of a MySQL database, you can use phpMyAdmin to do this very easily. Here are the steps to search every MySQL database table.

1) Select the desired database

The first step is to select the database you want to search. Don’t select a table — just select the database you want to search. (If you select a table you’ll get a different search form in Step 2.)

How to search multiple jar files for a string or pattern (shell script)

Here’s a Unix shell script that I use to search Java JAR files for any type of pattern. You can use it to search for the name of a class, the name of a package, or any other string/pattern that will show up if you manually ran jar tvf on each jar file. The advantage of this script — if you’re a Unix, Linux, or Cygwin user — is that it will search through all jar files in the current directory:

A map of “Why is [state] so ...”

To create this graphic, someone Google’d all the queries for “Why is [state] so” (like, “Why is Illinois so”), and mapped the first Google auto-complete result onto each state. Makes me want to spend some time in the “haunted” states.

(They actually Google’d these queries in 2014. Makes me wonder what the current results look like.)

How to replace newline character with sed on Mac OS X (macOS)

I don’t have much time to explain this today, but ... if you want to see how to use the sed command on a Mac OS X (macOS) system to search for newline characters in the input pattern and replace them with something else in the replacement pattern, this example might point you in the right direction.

How to search the history of my Facebook posts

Facebook FAQ: How do I search the history of my own posts?

I was just looking for an old Facebook post I thought I made about five months ago, and scrolling through the history of my posts was very painful. It seems like Facebook gets slower and slower the farther back in your history that you go. This made me wonder, is there any way to easily search through the history of my past Facebook posts?

While it’s not obvious, the answer is that yes, you can search your Facebook posts history, and here’s how you do it, at least as of February, 2016.

How to search a MongoDB collection with Scala and Casbah

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 16.5, “How to search a MongoDB collection with Scala and Casbah.”

Problem

You want to find objects in your MongoDB collection using Scala and the Casbah driver.

Solution

Use the find* methods of the MongoCollection class to get the elements you want, specifically the find and findOne methods.