organise
Find Makes You More Productive at the Command Line
Posted by Gina Trapani at 1:30 AM on July 12, 2008
Programmer Eric Wendelin says you can get a lot more done with sets of files at the command line once you've mastered the basics of find, an old school search tool. Find in and of itself gives you the same functionality as Google Desktop or Spotlight, but because it's at the command line, you can pipe results into other tools like grep or sed and really get things done in a flash—like do a global search and replace. If all this is making you go "huh?" but you've dabbled at the command line before, hit up Eric's post, which is a nice intro to what you can do with find. Here's another helpful introduction to the command line.
Tags: command line | organise

Comments (AU Comments · US Comments)
There are currently no AU comments for this post.
savedsoul
Posted 2:42 AM 12/7/08
I love these old school 'cl' guys that try to hold on tight for dear life. Nothing wrong with the 'cl', I use it a good bit myself. But, IMHO, the evolution of computer systems should be harnessed, not shunned.
Just cause your a sed/awk/bash/cmd/bat/whatever pro, doesn't mean that the new-hyped-tool doesn't make it easier to get at the same information. And for the vain, 'cl' output is downright drab :).
savedsoul
GilbertErik
Posted 2:29 AM 12/7/08
'find -exec' has to be one of my favorite misused tools. Pay particular attention to the comments in the article about xargs
GilbertErik
azpat
Posted 3:23 AM 12/7/08
If you have vista, you can use "where" out of the box. I find it's faster than find via cygwin. It has a find-like syntax: 'where /r . *.txt' will list all text files in the current dir and all sub dirs. 'where /?' for more examples.
azpat
johnsmith1234
Posted 3:04 AM 12/7/08
It's amazing how under used the Windows command line is. Especially after adding a couple small tools, it is very powerful and for some things quicker than GUI. Plus it's a much easier to automate.
Though I normally have a cmd window open, I'm not strictly a CL guy. Some things are better GUI, some are better CLI, I choose the right tool for the job.
The runbox is also greatly underused.
johnsmith1234
daniel.j.doughty
Posted 3:53 AM 12/7/08
Command line work is a good way to complete custom jobs for free. Now most sensible people won't sit around and waste hours on a script when there is a tool they can install. Take the flickr uploadr tool. It's free, is supported by the website, and does all the work that I don't feel like doing in some script that might quickly become antiquated.
Unfortunately, it's pretty rare for these tools to exist, plus with the advent of malware many of us won't risk installing a shareware version of some program that may have been written four years ago and has never been supported since.
daniel.j.doughty
whereisian
Posted 3:39 AM 12/7/08
@savedsoul
CL may be drab, but more often than not, it's the right tool for the job.
Can't script a gui program without funky scripting languages. Can't send the output of one program as the input to another. Most gui apps won't give you the granularity that a CL app can.
CL and GUI complement each other, they don't necessarily compete; they have both evolved. It's telling that MS has reinvested in the command line.
whereisian
johnsmith1234
Posted 3:33 AM 12/7/08
dir /s/b *.txt
johnsmith1234
-Thurston-
Posted 4:24 AM 12/7/08
FOR...the most useful and misunderstood windows command line tool I know of.
-Thurston-
emwendelin
Posted 4:02 AM 12/7/08
Really, command line tools like find are the best way to automate some tasks, especially for development work. Another added benefit is that it just just so much faster without a Graphical User Interface (GUI) that all of these automated tasks take very little time.
Any votes on what tool to write about next?
emwendelin
emwendelin
Posted 4:53 AM 12/7/08
@rlee: I totally love Google Desktop (and use it) for searching files and executing/opening them. In that way GDesktop is better but the point I'm making here is that the extensibility of find, much like Firefox, is what makes it extra special and powerful. You also can't really automate the GUI-fied apps much.
emwendelin
rlee
Posted 4:34 AM 12/7/08
"... the same functionality as Google Desktop or Spotlight". Well, that's debatable. Don't get me wrong -- I use 'find' -- but besides the lack of a GUI and related bells-and-whistles, the point of the latter is that they pre-scan and index your files. So the finding is a heck of a lot faster when you use them.
rlee
sir_pantsalot
Posted 5:05 AM 12/7/08
I switched jobs a year ago and went from using Unix, Linux and PC to only using PC. I think my IT department is scared of Linux. I have been trying to use Windows Command Line off and on for the past 6 months. I have a few aliases set up to help me out but does anyone know of any good resources for beginners of Windows CL? Have you guys used the Cygwin? Is this something I can install at work without IT finding out?
sir_pantsalot
radiantchains
Posted 3:17 AM 12/7/08
@johnsmith1234: Care to mention some of those small tools? I'm a Windows command line fan and I'd love to know about any add-on tools that exist.
radiantchains
ricardo.slacker
Posted 6:29 AM 12/7/08
I completely respect the gui for certain problem domains, (single image editing, etc.), but the command line will never be outdated for the same reason that writing will never be outdated. The most efficient, unambigous way we as humans communicate is through the written word, and I don't see that changing anytime soon.
ricardo.slacker
screaminscott
Posted 6:15 AM 12/7/08
um, isn't grep a UNIX command? You might want to mention that this is a UNIX tool, not a DOS tool in the post. I got all excited for nothing.
screaminscott
MrJR
Posted 6:56 AM 12/7/08
Many unix tools (grep, for instance) have long been ported to DOS and without needing Cygwin. Greps are especially popular, here: [directory.fsf.org] , for instance. Or google unix tools or the specific tool name. Another route is 4NT (not free), a substitute for the DOS command shell which adds a lot of unix-like (but not identical) functionality, including a nicely structured batch language.
MrJR
Mark
Posted 6:41 AM 12/7/08
Command line rocks! It's not for the AOL/YouTube crowd but then it looks like that's already been pointed out. I could not get rid of an empty directory no matter what I did. Surprisingly, it wasn't Cygwin but good old Windows MS-DOS command line that got the job done. Another time, Bash CL saved the day when I had to output a file listing on a crashed computer. Command line - MS-DOS, Cygwin, Bash, etc. - is way more powerful than click and point. Definitely worth learning.
Mark
GilbertErik
Posted 8:49 AM 12/7/08
Oh yeah... and with cygwin, adding a '+' on the end of your exec call builds the command line "...in much the same way that xargs builds its command lines.", so:
- find . -name "*.css" -print0 | xargs -0 grep -l "#content"
could be expressed as
- find . -name "*.css" -exec grep -l "#content" {} +
(we ever gonna get monospaced fonts in comments?)
GilbertErik
GilbertErik
Posted 8:38 AM 12/7/08
Why does it feel like there are two types of people commenting here, those who understand the command line and use for what it's good at, and those who don't understand the command line and start talking smack about it...
Quick example, last night, a graphic artist friend wanted to compile individual .png frames from a walk cycle he created into a full sheet showing all the frames of the walk cycle on a single row and a different angle (1 of 8) [img299.imageshack.us]
An install of ImageMagick, 15-20 minutes, and a 9 line .bat script (which is simple and straightforward enough for him to edit on his own) saved him 10-40ish hours of manual copy-paste in a graphics editor. I'm not saying that ALL image editing can be done well in a command line, I'm just saying there are things that can be expressed REALLY concisely in a scripting language with redirection and pipes which point-and-click can't compete with...
I think of it as the polar opposite of popular flash games (whose primary objective is to let you do all interaction purely through the mouse).
GilbertErik
rlee
Posted 1:20 PM 12/7/08
@emwendelin: I completely agree that find is good and useful, and you can do things with it you can't do with Google Desktop and the like. I'm just quibbling with the "same functionality" claim, as the lack of indexing is a significant difference.
rlee
mario_grgic
Posted 6:23 AM 13/7/08
find/xargs/grep are great tools, but on Mac you also get the power of spotlight on the command line. Look up the man page for mdfind. It uses the spotlight's metadata index to search.
For example:
mdfind -interpret "search criteria"
-interpret is to tell mdfind to interpret the "search criteria" as if it were typed in the spotlight menu.
E.g.
mdfind -interpret "kind:image flash:1"
to find all images you ever took with camera flash.
And the fun part is that you can chain further commands on this to execute more complex commands on the search results.
Nothing beats the command line. Once you master it, you will wonder how you ever lived without it. But it takes time and patience.
Like they say, those who refuse to learn Unix are destined to re-invent it, badly :D.
mario_grgic