Pentax 50mm, 2x + 1x + 4ND half-grad. Three exposures +/- 1.3EV. Luminace HDR, Mantuik’08.
Doing much on the command-line often leads to some repetition. Learn how to roll up a group of commands by making a shell script.
I love using the find command. In DOS, find is like grep. In Linux, find is the most powerful recursive DOS dir /s or Linux ls -r command you could ever put your saddle on.
One of the things you can do with find is to avoid directories, using the -prune switch. Like so:
find /usr/local -type d -a \( -name jre1.6.0_38 -prune -o -type d -print \)
Yeah, put your bike helmet on if you keep reading. That spat out a ton of gook. But was I lying? Well, grep out everything but what we should have pruned:
find /usr/local -type d -a \( -name jre1.6.0_38 -prune -o -type d -print \) | grep jre1.6
What if you have a series of subdirectories you want to include, but you cannot write enough -prune switches for them? This is a problem I frequently have. For instance, how do you exclude all your Firefox Cache directories, especially if you have multiple profiles? Great question.
I’d first use find to find all the directories I
do want to backup:
find /home/jed -maxdepth 4 -type d > /tmp/dirlist
Then you grep out things you really don’t want:
egrep -i "/cache|/Trash" /tmp/dirlist > /tmp/avoid
Then parse it into things you do want to find to avoid:
cat /tmp/avoid | while read F ; do echo " -path $F -o " ; done > /tmp/avoid2 ; echo "-path ./asdf" >> /tmp/avoid2
Now we can refresh our list of directories to descend:
find . -xdev -depth -type d \( `cat /tmp/avoid2` \) -prune -o -print
If we want to turn that right into files, modify the last print statement to find files:
find . -xdev -depth -type d \( `cat /tmp/avoid2` \) -prune -o -type f -print
Now if you want to find the files more recently created than your last backup in /home/backup/monday.tgz, try this:
find . -xdev -depth -type d \( `cat /tmp/avoid2` \) -prune -o -type f -newer /home/backup/monday.tgz -print
Is that enough to make you cry? Chin up, think of all the disk space you’re saving, and how much faster a specific backup can occur. This means you can run backups every 15 minutes.
I’m grateful for Cygwin. I wouldn’t know how to do this in cmd–though I should probably learn how to do it in PoSH.
find LogFiles/W3SVC1 -type f | xargs ls -1tr | tail -n1 | xargs tail -F
I need to make it an alias now….