I'm currently accepting new contracts consulting for all aspects of website success and developing in Ruby, PHP, CSS, and (X)HTML!

Please do not contact me about Flash programming or full-time work; I'm not accepting those kinds of work at this time.

clara raubertas

web development & consulting

ruby on rails, php, and more; boston/cambridge

Subscribe!

Sunday, May 18, 2008

Command Line Magic

Using the command line rather than a graphical interface is one of the things that a lot of people find most intimidating about the idea of using Linux. While (my last post notwithstanding!) you can accomplish most things without ever opening up the Terminal, I've grown more and more enamored of using the command line whenever possible.

I found gaining fluency with the command line to be like apprenticing to a magician; at first, you utter the magic incantations syllable by syllable knowing only what will result from the whole. But the more spells you learn, the easier it becomes to notice that each part has meaning, eventually acquiring the knowledge to recombine them in ways you've never seen and feel confident that you can predict what will result. Once you gain experience, it's simply faster to rattle off a handful of magic words than to navigate through the space of the graphical desktop.

If you have a Linux or Mac OS X machine, you can try this at home (Windows has a command line too, but it's not as integrated with the rest of the system and uses different syntax). Open the "Terminal" application and give it a try:

echo 'hello world'
will print the phrase 'hello world'

pwd
will give you the name of the directory you're currently in

ls
will list all the files in your directory


cat groceries.txt
will print the contents of groceries.txt (if groceries.txt is a text file) to the screen

man grep
will print the manual page for the command grep


Commands can have arguments that modify their functions:

ls -l
will list all the files in your directory, in a longer format

firefox &
will launch firefox in the background


The output from a command can be piped into another command:

cat groceries.txt | grep apples
will grep (search) for the phrase 'apples' in the printed text of groceries.txt

ls | grep groceries
will search for 'groceries' in the list of files in the current directory

echo 'bananas' >> groceries.txt
will append the line 'bananas' to the bottom of the file groceries.txt



Not only that, but commands can be used to search for other commands:

man -k search
will give you a list of the names and short descriptions of all the commands whose short descriptions include the phrase 'search'

Labels: ,

AddThis Social Bookmark Button

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home