Command Line Magic

1:26 am May 19th, 2008

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’


You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

1 Comment to “Command Line Magic”

  • [...] me my first technical jobs, first as her research assistant (which is where I first learned UNIX-y command line magic) and then as a grader for an introductory CS [...]

     

  • Leave a Reply