Introduction to the command line | Learning | Beckstein Lab

. . . . .
Introduction to the command line

Introduction to the command line

As a computational scientist you have one primary tool at your hand: a computer. And like an experimental scientist, you will have to be able to interact with it, adjust it, tweak it, fix it, and generally make it do things that it has never done before — after all, science is about finding out new things about the universe.

You are probably used to interacting with a computer via a graphical user interface — windows, browsers, a mouse or touch screen. Although convenient, this limits you to the interactions designed into the interface. To get more out of a machine you have to talk to it more directly.

One way to do this to give specific text commands: instead of clicking a file and dragging it to a new folder you open a terminal (also known as the shell) and type

mv filename.txt my_folder/

(mv stands for “move” – pretty much all Unix commands are short so that you can type them quickly. All commands also come with documentation, which you can see by typing man commandname, e.g. man mv)

If you have 1000 images, called img0000.jpg, img0001.jpg, img0002.jpg, … then you can move all of them with a single command

mv img*.jpg my_folder/

The * asterisk acts as a placeholder or pattern, which allows you to match all files in one go — no complicated marking and dragging a thousand files.

These are, of course, primitive examples. Neal Stephenson, in his essay In the Beginning was the Command Line (PDF), gives a much more elegant historical discussion of the power of talking directly to the machine.

All machines in our lab are running a flavor of Unix (such as a version of GNU/Linux like Ubuntu or Debian), and all super computers do so, too.

  1. In order to get started, work through a Short Introduction to Unix.
  2. Then learn how to use a good text editor; decent choices are vi and emacs. (Because vi is installed on any Unix system, a little bit of vi-knowledge will always come in handy.

To get a better feeling for what one can do with the shell you should have a look at the classic An Introduction to the Unix Shell. Although written in 1978 by S. R. Bourne (the guy who wrote the “Bourne shell”) it is still readable and concise. Modern shells (such as bash (“bourne again shell”… that’s Unix humor for you…) are based on the venerable Bourne shell but have been expanded to do a range of nifty things.

Discuss: “Introduction to the command line”

October 29, 2014 at 11:36 am #

Hi Dr.Beckstein

Python and Command line knowledge have become mandatory and inevitable in the current research scenario. The courses on Python and unix/Linux would be of great help to students like me who are Computational Biologists. Looking forward to see such courses taught under your expertise in the future.

Posted by  karthigayini
January 13, 2016 at 5:28 pm #

The new class PHY494: Computational Methods in Physics addresses exactly those needs!

Posted by  Oliver Beckstein

Leave a Reply

Textile help