The Importance of Command Line Literacy

The oldest interface is still one of the best. Learning about shells and utilities can pay off for jobs where they're the fastest or most flexible.

Have you sat down with that grey-haired system administrator and watched what’s happening as her (or his) fingers fly over the keyboard? Ever wondered why they’re still Stuck In The Stone Age, typing text instead of using the obviously easier mouse and menus? Suspect that person is a geezer who can’t learn new techniques?

Maybe they did learn Linux (actually, Unix) before everyone had windows on a monitor. But there’s a reason why they keep a terminal window (or ten) open on their desktops: this is a power platform that can be the fastest way to work. It remembers what you’ve done (so it’s easy to repeat and/or modify), has built-in programmability (need a loop? no worries!), and gives you full access to the library of hundreds of Linux utility programs that were designed for just this environment. A terminal and utilities do jobs that a GUI can’t touch.

Less power than your wristwatch

The Linux command line was born around the time Linus Torvalds drew his first breath: in the days of small Unix systems with tiny amounts of memory. Back then, a tty was a teletype — those clattering machines that also sent and received telegrams over 110-baud lines. Using Unix meant typing on a keyboard and waiting for the (often-busy) system to respond. Every byte and CPU cycle were precious. The Unix command line evolved to help people cope with this environment.

Typing ahead

In these days of speedy systems with enough power to burn that you can have 3-D multicolor displays which morph with your mouse, the typeahead feature of Linux device drivers can still be worth knowing about.

Typeahead means that the memory buffer which reads your keystrokes and passes them on to the kernel can read input and save it until the rest of the system is ready to receive it. This was very useful in the days of super-slow processors that could barely cope with the keyboard interrupts generated each time you pressed a key.

Once you’re confident on the command line, you can still use typeahead today. For instance, if you’re trying to coax work out of a remote system through a congested network link, you may not need to wait to see a response. If you’re typing simple commands at a shell prompt, or using a keyboard-driven editor like vim that you know well enough to trust the commands you type, try typing ahead! It doesn’t always work: for instance, keystrokes like CTRL-C or CTRL-Z flush the typeahead buffer. But typeahead is still available, ready to receive commands at molasses speed and execute them when the processor is ready.

Not the only way

We aren’t saying that you’ll only want to use the command line. Understanding where it’s useful and how to use it will let you choose whether to use your terminal window or a GUI.

Think (twice?) before you type

One pitfall for new command-line users is this: Utilities were born in the days when you wouldn’t want to wait (and wait…) for a system to ask “Are you sure?” before, say, removing a file. So it’s best to think before you type — or, at least, to double-check before you press the RETURN key to run a command.

Once you’re used to decisiveness by default, the constant pop-up confirmations of a GUI can actually be frustrating.

So what?

Why would you want to type on a command line instead of (say) choosing commands from a GUI menu? There are more reasons than we can cover in three pages. Here are some of the best:

  • Linux utility programssort, cut, join, and hundreds of others — are powerful and flexible tools that are ready to run with a few keystrokes. Options let you fine-tune (or completely change) how utilities work.
  • Powerful I/O redirection lets you save data to files, read data from files, and connect a series of utilities together in a pipeline that lets you custom-build exactly what you need… again, with just a few keystrokes. GUI applications — which have to pack all possible operations into a set of menus and checkboxes — can’t be nearly as flexible or powerful.
  • Linux commands can operate on many files at once. Filename completion lets you specify filenames by typing a few characters and the TAB key. Some GUIs have that feature too. But most GUIs don’t have wildcards, which let you specify one or many files with just a few keystrokes. The pattern [A-Z]*.txt matches any filename that starts with an uppercase letter and ends with .txt; that could be many files. ([:upper:]*.txt handles non-English filenames too.) Use /home/*/data0[0-5] to match all files named data00 through data05 in all directories under /home — for instance, /home/amy/data01, /home/randolph/data06, and so on.
  • A shell is actually an interpreter for a programming language: the language of command lines. It puts powerful loops, tests, variables, I/O manipulation, error-trapping, and more at your fingertips when you type a command line.

    Put these same command lines in a script file, and you have a shell script — which lets you repeat those stored commands anytime you want to. It’s the same language from the command line or from a script file. Learn the shell “language” and you can use it both places!

    One of the authors of the Apress book “From Bash to Z Shell: Conquering the Command Line” gave a good example of this. “Earlier this week we had to rearrange a bunch of source files … arranging according to newer directory structure conventions. Lots of little jobs like renaming files to lower case would be really laborious from a GUI. From the shell I could do all the stuff on the fly as fast as my colleague explained what needed doing. He was quite impressed and it’s convinced him to try to learn more about it all himself.”

  • Command substitution lets you use the output of one command as part of another command line. If you haven’t used a shell before, this is hard to explain… but, trust us, it’s very powerful. For instance, you can run a file-search program like find, then run another command on the files that find found.

This kind of flexibility is unheard-of in a GUI menu system.

Behind the scenes

If you’re new to the command line, understanding some basics can help you fit the pieces together.

On modern systems, the old teletype device has been replaced by either a console terminal (which fills your screen — like the virtual terminals that appear when you press Alt+Fn or Ctrl+Alt+Fn; see the console manual page for details) or a terminal window (which is like other GUI windows).

Running “inside” the terminal is a shell. A shell is a Linux program that’s designed for running both internal “built-in” commands (like cd to change the shell’s current directory) and external commands (like grep, perl, vim, and many more). There are several different shells; bash, tcsh, and zsh (“Z shell”) are probably the most popular, but you can choose whatever shell you like.

A shell is a program like any other on Linux. So a shell can run another shell; that’s the situation when you run a shell script (a text file with one or more command lines, which start with a command like cd, grep, perl, vim, …).

A shell does the following steps, over and over:

  1. Unless it’s reading from a script file, it outputs a prompt (like $ — or anything you set it to) and waits for step 2.
  2. Reads a command line from the terminal (followed by the RETURN key) or from a script file.
  3. Parses (interprets) the command line to find the command name(s), special characters like * and ? (wildcards that let you specify one or many filenames without much typing), | and > (redirection symbols, which route programs’ input and/or outputs).
  4. Runs the command(s) and waits for them to finish.
  5. Repeats the steps for the other commands until the script file ends, or the user types exit or CTRL-D. Then the shell program terminates — and the terminal window closes, or virtual console prints another login: prompt.


We can’t give many examples in a three-page column that also explains the basics. If you’d like to see of what you can do in this feature-rich environment, browse through some of the past six years’ Power Tools columns.

Being able to use any command in a loop — to do something repetitive, with just a few command lines — is one of the most obvious reasons to use a shell instead of a GUI. Here’s a loop that finds every filename ending with .c in the current directory and makes a copy with OLD_ preceding the filename. (The -p is an option that tells cp to give the copy the same last-modification date as the original file.) Linux utilities normally run silently unless they have errors… but, if you wanted to see what files cp is copying, you could add the -v or --verbose option:

$ for f in *.c
> do cp -p $f OLD_$f
> done

The $ and > are prompts. These tell you that the shell is waiting for commands. You can customize prompts to show much more information: the name of the current directory, the computer name, your username, the date and time, and almost anything else.

To repeat the previous loop at some later time, you could navigate up in the shell’s history list by pressing the up-arrow key on your keyboard — and, when you see the loop you typed before, press RETURN to re-run it. It’s also possible to edit the loop interactively at this point. Or, you could use one of the history commands available on old teletypes. This command repeats the previous for loop:

$ !for

Not all shells will let you repeat an entire loop with !for; they may only repeat the first line. The shell will show the loop commands, then re-execute them. This is an example of why Linux commands generally do what you ask without confirmation: in this case, cp will replace the previous backup files with the new ones. (If you didn’t want that, you could have added a cp option like -i, “interactive,” which asks before overwriting.)

Want to back up every filename ending in .c in the entire directory tree — which could be tens or thousands of directories? Replace the *.c in the previous loop with command substitution and the find utility. Here we’ll change the cp command line to make copies whose names end with .bak:

$ for f in $(find . -name '*.c' -print)
> do cp -p $f $f.bak
> done

That loop has a couple of subtle problems that you’ll understand once you learn more about how shells work. (You could add -type f to tell find to copy only files — not directories whose names happen to end with .c. Also, if any names have spaces or special characters, you should be sure they’re handled correctly.) The Z Shell has a built-in ** recursive-matching operator that’s easier than find. Here’s the previous loop using Z shell:

% for f in **/*.c
for> do cp -p $f $f.bak
for> done

This is an example of the power of different shells: if you know how to use more than one, you can choose the best shell for a job. (Many Linux users only learn bash… and that’s plenty!)

Maybe your IDE (programming environment) has a function that can copy your source code. But can it copy any or all directories? Can you choose the backup method, and whether the backups keep the original timestamps? Can you add conditional tests to choose which files are backed up — for instance, only files modified in the past day, or only files with more than 100 lines, or only files containing a call to the function foobar(), or …? If you can, that’s a sophisticated IDE! But what if you want to make a zip or tar archive instead of a backup? Or if you don’t want to copy the files; you want to rename them? Or …

Or maybe you should take the time to learn the fundamentals of shells and utilities. Once you learn the basics (like for loops) you can use those same fundamentals with the hundreds of utilities to do thousands of operations — with just a few keystrokes. Grab a good book (like the Apress book mentioned earlier; shameless plug: this author wrote part of it) and get ready to be a (grey-haired?) Linux guru yourself.

Comments on "The Importance of Command Line Literacy"

Do you have a spam issue on this website; I also am a blogger, and I was curious about your situation; we have developed some nice methods and we are looking to swap methods with other folks, please shoot me an e-mail if interested.Here is my website; Task Management Delegation Software

Every as soon as inside a though we pick out blogs that we study. Listed below would be the most up-to-date websites that we pick out.

Hi there! This is my first visit to your blog!We are a team of volunteers and starting a new initiative in a community in the same niche.Your blog provided us valuable information to work on. You have done a extraordinary job!Also visit my web blog :: food travel podcast

Rght here is the perfect sote forr anyone who really wants to understand this topic. Youu realize a whole lot its almost tough to argue with you (not that I actually will need to…HaHa). You definitely put a fresh spin on a subject that’s been discussed for many years.Great stuff, just wonderful!Have a look at my site – Penney

Here are some of the web sites we advocate for our visitors.

I want to to thank you for this very good read!! I certainly enjoyed every little bit of it.I have you book-marked to check out new things you post…My homepage: lose 20 pounds in 2 weeks diet plan

Additional services like fixing,. changing, or
updating any kind of locks are also provided by the locksmith professionals
to the homeowners and business consumers.

Also visit my webpage … All City Lock

?hen ? initially ?ommented I clicked the “Notify me when new comments are added” checkbox andd now eac?? time a commentt is added I get three emails with the same comment.Is there any way yo? can remove mee from that service??hanks a lot!?y homep?ge – oneilrsadyaknpz.bl?g.c?m (Maximilian)

Here are some hyperlinks to sites that we link to simply because we believe they are really worth visiting.

Just beneath, are several totally not related websites to ours, nevertheless, they may be surely worth going over.

For newest news you have to go to see world-wide-web and on internet I found this web page as a most excellent site for hottest updates.Here is my web-site – nautical chart miami to key west

Howdy! I know this is kind of off topic but I was wondering which blog platform are you using for this website?I’m getting tired of WordPress because I’ve had issues with hackers and I’m looking at options for another platform.I would be awesome if you could point me in the direction of a good platform.Also visit my web-site; best reverse osmosis water filter system reviews

When some one searches for his necessary thing, so he/she wishes to be available that in detail, thus that thing is maintained over here.Review my blog; your Ex Back

If some one needs expert view regarding running a blog after that i advise him/her to visit this website, Keep up the fastidious job.Look into my page miami key west zip code

België zal de uitdaging van Ierland in Groep E tweede ronde toegelaten, verloor de eerste wedstrijd in Europa de Rode
Duivels behoefte in dit spel om punten te krijgen.

Debu Lao vertegenwoordiging in België niet geschopt
niveau van vorig jaar de eerste plaats in de wereld, met Ierland een oorlog is heel
belangrijk, hij gelooft dat de fysieke voordelen van de Ierse speler zal België de spelers
heel moeilijk om te doen.

Debu Lao binnenkant zei: “Ierland’s eerste wedstrijd speelde erg goed, zal de speelwijze tegenstanders moeilijk te doen voor de start van de Europese Cup zou ik zeggen dat dit de sleutel games te maken, is het waarschijnlijk om het team kwalificatie situatie te beslissen. Ierse spelers zijn zeer goede fysieke kracht, kwalificatie resultaten die ze grote vooruitgang hebben geboekt, maar ze zijn in deze groep en onopvallend, maar zeer gevaarlijk, moeten we voorzichtig zijn.

“Toen de loting kwam ik wist dat het zou zijn een moeilijke groep,
Italië, Ierland en Zweden zijn erg sterk. Topprioriteit
van het team is om zich te kwalificeren uit de groep, we moeten ook meer inspanningen te maken,
het zal niet makkelijk zijn. we goed gepresteerd in de kwalificatie fase, zodat mensen van België hebben hoge verwachtingen, en nu het team op de rechtbank om te bewijzen dat de hoop om een ??deel van de fans memorabele momenten te brengen. ”

Every the moment inside a whilst we choose blogs that we read. Listed beneath are the most up-to-date sites that we choose.

Wonderful blog! Do you have any tips for aspiring writers?I’m planning to start my own website soon but I’m a little lost on everything.Would you suggest starting with a free platform like WordPress or go for a paid option? There are so many options out there that I’m completely confused ..Any recommendations? Thanks a lot!my web blog :: reverse osmosis water for sale

Hi there Dear, are you really visiting this web skte daily, if soo then you will definitely get nice know-how.Feel free to surf to my web site … penn pursuit 4000 combo Review

I am sure this article has touched all the internet people, its really really good article on building up new website.Here is my webpage :: waste tire pyrolysis

Pretty section of content. I just stumbled upon yyour weblog and in accession capital to assert thbat I get in fact enjoyed account your blog posts. Anyway I will be subscribing to your augment and even I achievement you access consistently quickly.Check oout my homepage :: abu garcia baitcast reel review

Hi everyone, it’s my first go to see at this web page,and paragraph is truly fruitful in favor of me, keep up posting such posts.Also visit my web blog; miami to key west high speed boat

Terrific article! This is the kind of information that should be shared around the internet.
Disgrace on Google for now not positioning this post upper!

Come on over and visit my website . Thanks =)

Without prompting, my 3rd graders (equivalent to high school seniors in the U.
They saw Jesus in his glorified body state just six days after He made this promise.
This picture was taken in on March 9th 2005 when Ghost Tree went huge and perfect and very very dangerous.

The data mentioned in the article are a number of the ideal offered.

Having read this I thought it was really informative. I appreciate you finding the time and energy to put this information together. I once again find myself personally spending a lot of time both reading and leaving comments. But so what,it was still worth it!My page :: history tutoring

As the admin of this web site is working, no hesitation very rapidly it will be famous, due to its feature contents.Also visit my page: queens peak condo

I know this if off topic but I’m looking into starting my own weblog and was wondering what all is required to get set up? I’m assuming having a blog like yours would cost a pretty penny? I’m not very web smart so I’m not 100% sure. Any recommendations or advice would be greatly appreciated. Cheers

I do not even know how I ended up here, but I thought this post was great. I don’t know who you are but certainly you are going to a famous blogger if you aren’t already ;) Cheers!

My developer is trying to convince me to move to .net from PHP.I have always disliked the idea because of the costs. But he’s tryiong none the less. I’ve been using Movable-type on various websites for about a year and am anxious about switching to another platform.I have heard great things about blogengine.net.Is there a way I can transfer all my wordpress posts into it? Any kind of help would be really appreciated!Review my web site :: quick money making wood projects

Wonderful story, reckoned we could combine a few unrelated data, nevertheless genuinely worth taking a look, whoa did 1 find out about Mid East has got additional problerms at the same time.

Zwitserland 0-0 met Frankrijk in het spel, in vergelijking met de kalme wedstrijd voert de
Zwitserse spelers vaak gescheurd shirt om meer
fans aandacht te trekken.

Breel Embolo, Fabian Schär, Behrami, Zaka (2 keer), Mathieu Erie en Mohammadi zijn truien is gescheurd.
Ze hadden op een nieuw overhemd te zetten. ZDF zegt Kahn gasten kan het niet helpen, maar
lachen: “. Ze zijn waarschijnlijk droegen huisje versie ervan”

Volgens de Duitse media “Bild” gemeld dat de Zwitserland truien vaak gebroken voor een reden. Zwitserland, omdat sommige spelers koos Puma sponsort een speciale strakke shirts.
Puma ACTV met behulp van nieuwe technologie heeft dit
nieuwe overhemd voor de huid micro-massagefunctie gemaakt,
deze spier overhemden voor de spelers is goed.

Maar in de felle concurrentie, shirts gemaakt van speciale materialen lijkt nog steeds te kwetsbaar.

Panel overtreffen Hourui Shi vijf punten aan de tweede groep te
krijgen, zullen hun playoff tegenstander de tweede wedstrijd van groep C.


Fantastic web site. A lot of helpful info here. I’m sending it to some friends ans additionally sharing in delicious.And of course, thank yoou in your sweat!Also visit my webpage; Buy Provigil

Leicester City Stürmer Vardy wurde noch nicht bestimmt, ob Arsenal beitreten, sondern nach Sky Sports verstehen,
Vardy ist wahrscheinlich Arsenal beizutreten.

Wenger sagte in einem Interview mit chinesischen Medien, dass die Vardy in Leicester bleiben, sagte
er: “Vardy ist jetzt Leicester City Spieler und ich weiß, dass er in Leicester bleiben wird.”

Arsenal vor drei Wochen aktiviert Vardy Vertrag Schadenersatz -Klausel
von £ 20 Millionen, mit der Stadt Houlaisite
Spieler ein Gehalt Vertragsverlängerung anbieten. Laut
Sky Sports verstehen, und jetzt will nur Vardy unnachgiebigen Fokus auf den europäischen Cup, entscheidet er seine Zukunft
in den Europa-Cup.

Vardy ergab, dass er nicht jetzt Dinge im Club Samstag Interview betrachten, sagte er:
“. Ich möchte auf den Europa-Cup vollständig zu konzentrieren, die derzeit das einzige was ich tun möchte, wo ich will England zu helfen, gute Noten zu bekommen”

Good day very nice site!! Man .. Excellent .. Wonderful ..I will bookmark your site and take the feeds additionally? I am satisfied to find numerous useful information here within the post, we need develop more strategies on this regard, thanks for sharing. . . . . .my blog post :: Premium Custom Essay Writing Service

One of our guests lately suggested the following website.

Wonderful story, reckoned we could combine a number of unrelated data, nonetheless seriously worth taking a search, whoa did one understand about Mid East has got much more problerms also.

Hello! I’m at work browsing your blog from my new iphone 3gs!Just wanted to say I love reading your blog and look forward to all your posts!Keep up the fantastic work!Also visit my web page: miami e key west

Very handful of web-sites that happen to become in depth beneath, from our point of view are undoubtedly nicely worth checking out.

Great post. I was checking continuously this blog and I am impressed!Very useful info specifically the last part :) I care for such info a lot. I was seeking this particular info for a long time.Thank you and best of luck.my weblog: 7 mile bridge miami to key west

Here is a superb Weblog You may Uncover Exciting that we encourage you to visit.

Here is an excellent Blog You might Come across Intriguing that we encourage you to visit.

What a information of un-ambiguity and preserveness off valuable knowledge regarding unpredicted feelings.my webpage … Reta

Greate article. Keep posting such kind of info on your site.

Im really impressed by your site.
Hello there, You’ve done a great job. I will certainly digg it
and personally recommend to my friends. I am sure they’ll be benefited
from this site.

I percaya apa yang Anda kata adalah sangat wajar.Tapi, apa tentang ini bagaimana jika Anda ?menambahkan sedikit konten ? tidak mengatakan Anda konten tidak padat , tapi kira Anda menambahkan ? title ? yang membuat orang ingin? lebih Maksudku% BLOG_TITLE% adalah agak plain. Anda harus melirik ?i Yahoo depan halaman dan menonton bagaimana mereka membuat berita judul ke mendapatkan pemirsa untuk membuka link.Anda mungkin menambahkan video terkait atau terkait pic atau dua untuk ambil pembaca bersemangat tentang apa yang Anda sudah ditulis.Menurut pendapat saya, itu bisa membuat situs Anda sedikit lebih hidup. http://marketlisters.com/user/profile/84491Here ?s my web-site; Pulau tidung

I was able to find good information from your blog articles.

Hi my family member! I want to say that this post
is awesome, great written and come with approximately all
important infos. I’d like to look extra posts like this

I just couldn’t go away your site prior to suggesting that I actually enjoyed the usual info a person provide in your visitors? Is gonna be again steadily to investigate cross-check new postshttp://emap.pw/a/3/villa1.xmlHere is my web-site … villa indonesia batu nurah

each time i used to read smaller posts that also clear their motive, and that is also happening with this piece of writing which I amm reading here.my blog – penn V spinfisher review

Way cool! Some extremely valid points! I appreciate you
penning this article and the rest of the website is also
very good.

Feel free to surf to my weblog; club penguin walkthrough secret of the fur

Enjoy the connection with shopping taobao cheap attire online and receive each one of these stuffs at low-cost amounts!My homemade page is across at swim suits.com.Be sure to pay me a visit sometime.

Leave a Reply