Find and Grep are perhaps the most used command line tools for the Linux user or administrator. Terse but powerful, these two commands will allow you to search through files and their contents by almost any imaginable attribute or filter criteria: file name, date modified, occurrence of the some specific word in a file, etc. Combined with a couple of other standard unix utilities, you can automate and process modifications over a number of files that match your search.
Here are two blog posts by Eric Wendelin which nicely illustrate the basics of these two commands:
Find is a Beautiful Tool
Grep is a Beautiful Tool
There are a number of other great unix utilities for file search, but knowing how to use find and grep is fundamental, as these two utilities can be found on the most basic build of every unix-like machine you come across.
Got a favorite command line hack that uses find or grep? Drop it on us in the comments.





































#!/bin/bash
# Seeing as I use a "podcatcher" which
# does not support variable speed playback,
# I have writ this script to play my "podcasts"
# in random order.
# Each followed by the option to delete.
# Those "'s above are indicative of my
# general distaste of all things "pod".
# So there.
# To prevent 'for' from booching on spaces
IFS=$'\n\t'
# Where to work
PODCASTDIR=/mnt/hdg2/share/podcasts/
PODCASTLIST=~/.podlist
# Player of choice
PLAYER=/usr/bin/mplayer
# Why ... not
function die()
{
echo "$@"
exit 1
}
# Build the list
find "$PODCASTDIR" -iname "*.mp3" -o -iname "*.ogg" | sort -R > "$PODCASTLIST"
# Parse and play
for i in $(cat "$PODCASTLIST"); do
# Play or puke
$PLAYER $i || die "Someone set up us the bomb!"
# Prompt and purge
echo -e "\nWould you like to delete the file you just heard:"
read -p "$i? "
echo $REPLY | grep -qi y && /bin/rm -i "$i" || echo -e "\nVery well, moving on."
# Prompt and procede
read -p "Would you like another? "
echo $REPLY | grep -qi y && echo -e "\nHit me!\n" || die "Right on. Until next time."
done
# Inform user of sound shortage
echo "So, uh..."
sleep 3
echo "It seems that you have finished."
sleep 1
echo "Well then."
sleep 2
die "Peace."
# I'm pretty sure that posting this here will bork the line breaks, so don't expect a copy/paste to work as is.
# I can email the original on request.
# Some minor language unniceties have been cleaned up for public consumption.
# Hope somebody can make use of this, or let me know where it might be improved.
# phaedrus
# @
# gmx.com
Reply to this comment
I hit the Unix Grymoire all the time when I need to get started with a find, sed, or awk recipe.
http://www.grymoire.com/Unix/
Reply to this comment
real simple:
alias hg='history|grep'
so all you would need to do to search through your history for all of the ssh logins would be
$ hg ssh
it's such a simple and useful alias that it bothers me that perhaps there is something similar out there already that I've overlooked. All you need to do to find a command that you have already issued is to remember one piece of the string.
Reply to this comment