Week 6: Introduction to using the terminal window.


Reference: The Linux Command Line; Third Internet Edition by William Shotts

Terminal: A program that lets users type things into the shell.

Shell: A program that takes the user's input and translates it into tasks for the operating system to do.

To open the terminal window:

Mac: Applications > Utilities > Terminal

Windows: open the PuTTY terminal window (chapter 16)

ssh username@mathvnc.eiu.edu [enter]
You will be asked for your: password

**CAUTION: YOU ONLY HAVE FIVE ATTEMPTS BEFORE YOU ARE LOCKED OUT!**

To exit the mathvnc server: exit
To end a process press: Ctrl-C
Note: I was having trouble with the arrow key, i.e., tab-complete not working. In general, the [tab] key should autocomplete commands, and more importantly, file paths once you start typing.

Some text editors: vi, nano, emacs
Once you are logged in, you should see the symbol: $
At the end of each chapter, there is a summary of commands.

CHAPTER 1

What happens if you type a random string of characters
$ blah

Current date and time
$ date

What happens if you type calendar
$ calendar

Calendar for current month and year
$ cal

Current amount of free space
$ df
$ df -h

Amount of free memory
$ free

CHAPTER 2
pwd, cd, ls

Present working directory
$ pwd
/home/username

List files and subdirectories, contained in the current working directory
$ ls

To list more details, i.e., long format
Note this is the letter L not the number 1.
$ ls -l

To also list hidden files
$ ls -la

The invisible files are the ones that start with a period.

Make a directory
$ mkdir [directoryname]

Change directory
$ cd [directoryname]

Return to home directory
$ cd ..

What happens if you type who
$ who

In general, most commands look like:
$ command -options arguments

Click here for a list of basic commands.

CHAPTER 3
ls, file, less

Determine file type
$ file [filename]

CHAPTER 4
cp, mv, mkdir, rm, ln

** CAUTION WITH RM!!!**

This asks if you are sure you want to remove file.
$ rm -i

CHAPTER 5
type, which, help, man, apropos, info, whatis, alias

To display a commands manual page
$ man [commandname]

CHAPTER 6
cat, sort, uniq, grep, wc, head, tail, tee

To display the first five lines in a file
$ head -n5 [filename]

Concatenate and print one or more files
$ cat [filename1] [filename2]

Display the lines in a file containing the pattern
$ grep pattern [filename]

Prints line, word, and byte counts of file
$ wc [filename]

You can also "pipe" the output from one command into another command. The pipe key is found by typing the backslash key, while using shift. i.e., you can type shift-backslash to get the pipe symbol " | ". This might be a key you never typed on your keyboard before! It was perhaps feeling lonely in the past. It is a powerful idea.

When we "pipe" the output from one command into another command, it is like asking to do one task, and whatever happens, we send the output from the first task into a second task, as the input for the second task. For instance, type:

$ man wc | grep for

This will print the manual file for the wc commands, but instead of opening it on the screen, it will send the output from the manual into the grep command, and then grep will search for the string: " for " inside the input it was sent (i.e., inside the manual pages for the wc file).

We can remove duplicated lines, when they appear next to each other, by using the uniq command, which is often used together with the sort command, i.e., we can sort a file and then pipe it to the uniq command, to remove any duplicated lines:

sort [filename] | uniq

CHAPTER 7
echo

echo displays a line of text
$ echo hello there!
$ echo ~
$ echo $USER

echo allows us to use the shell as a calculator: echo $((expression))
$ echo $(( 10%6 ))
$ echo $(( $(( 10%6 )) + 1 ))
$ echo $(( $(( 10%6 ))+ $(( 2^3 )) ))

CHAPTER 8
clear, history

cursor movement commands

CHAPTER 16
ping, traceroute, ip, netstat, ftp, wget, ssh

Via ssh, you can download files from the internet.
$ wget http://files.zillowstatic.com/research/public/Zip/Zip_Zhvi_Summary_AllHomes.csv

Allows user to scroll through file; q to quit.
$ less [filename]

Now open a new terminal window. We will be moving files from your local working directory to your mathvnc directory, by Secure File Transfer Protocol. Type the following:

sftp username@mathvnc.edu
You will be asked for your password.

Instead of the dollar symbol, " $ ", you will see: sftp>

A lot of the same commands above will work here. To see what the local and remote working directories are:
sftp> lpwd
Local working directory: /directoryname
sftp> pwd
Remote working directory: /home/username

To send a file from a local to remote directory: put [local path] [remote path]
The second command argument is optional.
sftp> put localfile

Click here for a list of a few more commands.