UNIX Shell¶
Introduction¶
To run a climate model, we require a powerful computer with many CPU cores, huge disk storage, and optimized memories. Such a computer consists of Unix-based operating system to maximize the computational resources. The Unix (or Linux) shell is a communication tool to control the computer to request our demands (i.e., command) through a terminal. The terminal is a software to run the Unix shell. Once we order something to a computer using a command, the computer responds back to our order every time. When the computer shows a strange response rather than your expectations, something is wrong in your command most likely. Otherwise, the computer is broken. You will learn about the Unix shell below.
One point that you need to keep in mind is that the computer-friendly interface (e.g., the Unix shell) mainly types using a keyboard whereas the human-friendly interface (e.g, GUI, MacOS, Windows) frequently clicks button/icon using a mouse (or MagickPad, figures, gestures). You may feel that it takes several seconds to launch software when you click the icon. This indicates that a computer spends a lot of resources to establish a human-friendly interface. In the Unix shell, however, the computer can spend its resources to do the requested job as quickly as possible.
Shell types¶
Roughly speaking, there are two types of Unix shells: c-shell and Bourne shell. Traditionally, a high-performance computing machine prefers c-shell (called csh or tcsh) whereas many users are familiar with the Bourne shell (called bash). We use bash in this course although the difference between csh and bash is very minor (like differences among US English, British English, Australian English, and Indian English).
Let’s check what shell you are using now.
Please open the terminal and type echo $0
. You may see this:
Even though your shell is not the bash, you can still use the bash by simply typing $ bash
.
I will describe the command by putting “$” at the front:
$ bash
$ echo $0
You can customize your shell and its default setting by modifying the hidden files like”.bashrc”, “.profile”, or “.bash_profile”. Once you set up the file .bashrc, you can activate that setting using a command “source”.:
$ source ~/.bashrc
Basic commands¶
The most commonly used commands in the Unix shell are manipulations of files and directories (see the table below). Let’s see how does it work.
Command |
Meaning |
Options |
---|---|---|
$ ls |
list |
-la |
$ mkdir |
make directory |
-p |
$ cd |
change directory |
|
$ cp |
copy |
-r |
$ mv |
move or rename |
|
$ rm |
remove |
-r |
In the Unix shell, we have a specific role (or grammar) to use it: $ command option argument. We always require the command but options and arguments are sometimes omitted. Let’s see an example using the command “ls”. The command “ls” shows a list of files in a directory provided by “argument”. You can omit the option and argument for the command “ls”. When you type “ls” without “argument”, you can see the list of files in the current directory.:
$ ls
You can get the same result by specifying the current directory using “./”.:
$ ls ./
Or you may get the same result by putting the options like:
$ ls -q ./
$ ls -v ./
As shown above, the hyphen “-” indicates the options. When you use the option “-a”, you can see more files:
$ ls -a
You can get the same result by specifying the current directory “./”
$ ls -a ./
You can also see the detailed information of files with an option “-l”
$ ls -l ./
Or you can combine two options like this:
$ ls -la ./
When you want to list the files in the specific directory, you can do it like this:
$ ls Desktop
Also, the detailed information will be shown by:
$ ls -la Desktop
A manual of the command “ls”, including the other options and usage, would be found in “man” command:
$ man ls
Text Editor¶
Unix
vi, vim
emacs
mule
MacOS
Sublime Text
TextEdit
BBEdit
TextWrangler
Windows
Notepad