Unix commands
Two of my most favorite unix commands are "find" and "tail -f". I'll briefly describe how to use them, but for more information, please consult their man pages.
tail -f
tail - Print the last 10 lines of each FILE to standard output. Useful in itself, but not super useful.
But with the "-f" flag (follow file), every few seconds, tail will rescan the file, and if anything new has been added to the file, it'll display that. It's very cool for watching log files, or output files, or anything that you don't want to keep "more"-ing.
But, this weekend, I found the coolest new extension to tail, "--follow". tail used to just watch a file descriptor, so if you were looking at a logfile, and the logfile got rotated, you would be looking at the backed-up log file, and not the current version. So, use "--follow=name", and tail will instead look for the filename instead of the file descriptor.
find
find is an incredibly powerful command, and even though I now use "grep -ri" (recursive case insenstive grep, try it out) for a lot of the things I used to use find for on IRIX, find is still incredibly useful.
First, how to use find in it's most basic context find . -name "*pattern*" -print This will start at the current directory ".", will search for all files that contain the pattern "*pattern*" and will print their filenames.
One of the coolest options to find is "-exec". Here's an example of it's use: find ~/GDEV/seed -name '*.[ch]' -exec grep enum {} \; -print
This will start in the directory "~/GDEV/seed", will find all files that end in either ".c" or ".h" and will print out all occurences of "enum" in these files. For each file that contains "enum", it will also print out it's filename.
Looking at the -exec part of the above command you see
-exec grep enum {} \;
-exec - start the command to exec grep - command to run {} - current file being processed by find \; - end the command to exec
Woah. This is getting pretty cool now. What really is cool is that you can run *any command* with -exec. I use "cp" a lot, but you can use any command you need. Very powerful.
There are *tons* of options to exec, some of my favorite are
-printf -maxdepth -xdev -amin
Use "man find" to find out what these options do.
Sunday, December 24, 2006
Subscribe to:
Post Comments (Atom)
1 comment:
If you're interested I also have a little writeup on the find command to help me remember the various options I commonly use. Its at:
http://timarcher.com/?q=node/23
Post a Comment