Command Line Magic
1:26 am May 19th, 2008Using 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’
pwdwill give you the name of the directory you’re currently in
lswill list all the files in your directory
cat groceries.txtwill print the contents of groceries.txt (if groceries.txt is a text file) to the screen
man grepwill print the manual page for the command grep
Commands can have arguments that modify their functions:
ls -lwill 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 appleswill grep (search) for the phrase ‘apples’ in the printed text of groceries.txt
ls | grep grocerieswill search for ‘groceries’ in the list of files in the current directory
echo 'bananas' >> groceries.txtwill 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 searchwill give you a list of the names and short descriptions of all the commands whose short descriptions include the phrase ’search’
1 Comment to “Command Line Magic”
» Ada Lovelace DayClara Raubertas // Freelance Web Design, Web Development, & Web Consulting // Cambridge & Boston says:
March 25th, 2009 at 5:59 am
[...] 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