Expand any of the sections below for user guides detailing each of the following Unix programs.

WHAT IS LINUX?

Linux is a version of the UNIX operating system developed by Linus Torvalds. If you are already familiar with UNIX, Linux will appear to be similar. In addition to the standard UNIX commands, Linux supplies a wide variety of utilities that may be used as building blocks for programming. This manual presents some of the more commonly used commands and utilities.

WHY UNIX?

UNIX (and all its variations) has become a very popular operating system for several reasons. UNIX is written almost entirely in C, a high level language, which means it can easily be adapted to different hardware platforms. UNIX was designed to be a multi-user system. Each user can run multiple tasks, taking full advantage of the hardware resources available. UNIX pipes allow the output from one process to be used as input to another process. The UNIX file structure is hierarchical providing easy organization of files in a tree-like fashion. Finally, on-line documentation provides the user with immediate help with system commands.

HISTORY OF UNIX

In the 1960s, AT&T developed a version of UNIX that has evolved as a standard; the current version is called System V. Steven Bourne wrote a command interpreter (or user interface, or shell) for UNIX, known as the Bourne shell. Bill Joy from the University of California at Berkeley developed another command interpreter for UNIX; it has become known as the Berkeley Software Distribution (BSD) C shell. Another shell, the Korn shell, contains virtually all the features of the Bourne shell, as well as several of the best features of the C shell. Bash was written by Brian Fox of the GNU project to replace the Bourne shell and is the default shell on Linux and OS X.

We’ve included this history because you will frequently hear these terms. Although we primarily address generic UNIX or specific Linux issues in this manual, we also have to describe the differences between the shells.

THE UNIX FILE SYSTEM

The UNIX and Linux operating systems have a hierarchical design for storing files. The file system is arranged as an inverted tree. Facilities that allow you to move around in the tree are explained later in this chapter.

The top of this inverted tree structure is called the root; this root contains directories and files. Each directory and file in the tree has a name except the root directory. The name of the root directory is / and is pronounced “root.” By UNIX convention, all directories for users are organized into subdirectories of root.

When you log on, you are automatically placed in a directory referred to as your home directory. Your eName is the name of your home directory. Within your home directory, you may store files, and you may create other directories to hold files and other directories. These subdirectories allow you to organize your files into related groups.

SYSTEM FILE ORGANIZATION

All of the files on UNIX-based computers are organized in subdirectories of root. This section introduces you to the locations of some files you will be using.

COMMAND DIRECTORIES

Commands you use during your computing session are commonly located in one of the following directories:

  • /bin
  • /usr/bin
  • /usr/local/bin

The /bin and /usr/bin directories contain various system commands. The /usr/local/bin directory contains machine specific commands (local commands) that probably aren’t available on other UNIX computers. For example, commands that access the software applications available on LampHost are located in this directory.

LIBRARY DIRECTORIES

Software libraries for Linux are normally located in one of these directories:

  • /lib
  • /usr/lib
  • /usr/local/lib

The /lib and /usr/lib directories are reserved for Linux system libraries, and the /usr/local/lib directory contains machine specific libraries.

HOME DIRECTORIES FOR USERS

When you log onto LampHost you are placed in your home directory. For example, if your eName is smith, your home directory path might be /h/smith.

SYSTEM DIRECTORIES

There are other directories and files in the root directory that are mainly used by the UNIX system. For example, the vi editor uses the /tmp directory for temporary files.

UNIX FILENAMES

A filename that indicates all the branch nodes is called a pathname. When you refer to a filename in UNIX, you must specify the pathname to make clear which file and which branch you mean, because two different directories may contain files that have the same name. You may provide either an absolute pathname or a relative pathname. Absolute pathnames start at the root directory; relative pathnames start from the directory in which you are currently working (the current directory).

Thus, whenever you see a UNIX pathname that starts with a / (slash), it is an absolute pathname; it starts at the root directory. If a pathname does not begin with a /, then it is a relative pathname and it starts from within your current directory. Slashes within a pathname (other than when used as the first character) are simply delimiters between directories and filenames; no spaces are allowed within a pathname. Here’s an example to help clarify:

  • /h/jones/project1/test.f

Here, test.f is a file in a directory called project1, which is in a directory called jones, which is in a directory called h. This is the absolute pathname of test.f. If you log on as “jones”, you are placed in the directory called jones, your home directory. You could then refer to this file as:

  • project1/test.f

If you changed your current directory to the project1 directory (we’ll show you how later), then you could refer to the file with the relative pathname:

  • test.f

In every directory, there are two special files named . and .. that you can use to help build relative pathnames to files. The . file refers to the current directory. The .. file refers to the next highest directory, otherwise known as the parent directory. For example, suppose you log on as “jones”, and there are two subdirectories, project1 and jobs, in the current directory. You could refer to the file test.f in the project1 directory as:

  • ./project1/test.f

If you were currently in the jobs subdirectory, you could refer to the file test.f in the project1 directory as:

  • ../project1/test.f

FILE PROTECTION WITH FILE PERMISSIONS

Each file has a permission structure that allows read, write, or execute permission for groups of users. Note that UNIX and AIX treat directories as special types of files.

File permissions can be displayed using the -l option of the ls command; the ls command is discussed later in this chapter. File permissions are displayed in a ten-character string such as:

  • drwxr-xr-x

OR

  • -rwxr-xr-

The first character is either a d or a – (hyphen): d denotes that this file is a directory; – (hyphen) denotes that this file is a regular file. The next three characters, r, w, and x, refer to the read, write, and execute permissions of the user who owns the file. The next set of three characters indicates the access permissions of the group of users associated with the file, and the last three characters show the access permissions for all other users on the system. In these three sets of three characters, a hyphen denotes that the type of permission associated with that position in the display is not granted.

Read permission for a directory means that the files in that directory can be read. Write permission means that files can be created, changed, or deleted in that directory. Execute permission enables the directory to be used in a pathname, as well as to be searched by other utilities.

The default file creation mode for is set to read and write permission for the owner; no permissions are granted for group and others. This default can be changed with the umask command in your shell’s logon file.

UNIX COMMAND SYNTAX

In UNIX, there are lots of parameters, or options, available on most commands; the purpose of each option depends on the function of the command. This manual does not cover very many of these options; just the most critical ones. Discovering command options can become an adventure once you grow more comfortable with UNIX.

Here are some facts about UNIX syntax:

  1. UNIX commands and options are case-sensitive. Because of this, the uppercase letter A is interpreted as a different character than the lowercase letter a.
  2. Each UNIX command begins with the command name. In most cases, this may be followed by various parameters, or options, which may then be followed by filenames, depending upon the command’s purpose:
    • Commands are usually in lowercase. Options usually start with a – (hyphen or minus sign), followed by a letter or a word that may be uppercase or lowercase, and sometimes also followed by a value. This is only the general structure for most UNIX commands; there are exceptions!
  3. Commands, options, and filenames are separated by any number of blanks within a command line.
  4. Filenames and directory names can be from 1 to 255 characters long. Almost any set of characters is permissible, but you should note that several characters, such as the $ (dollar sign) and the ” (double quotation mark) are special shell characters. We therefore recommend that, until you gain more experience, you should use filenames containing just letters (uppercase or lowercase), numbers, the . (period), and the _ (underscore).

Example:

Here is a simple command line that shows the most common UNIX and AIX syntax of a command, followed by options, which are followed by filenames:

ls -l -f chap2 chap3 chap4  

Example:

Here is a UNIX command line with options that contain both uppercase and lowercase letters. Note that the -q and -l options do not require their values (extname and imslib respectively) to be preceded by a space.

xlf -qextname -limslib -O main.f

Example:

The following command line shows the use of a parameter that is not preceded by a – (hyphen or minus sign). (The pathname /usr/local/bin is a parameter to the find command.) In addition, the -name option is a string of characters and uses another string (sendtg) as its value. Finally, this example shows that UNIX interprets any number of contiguous spaces on a command line as a single blank.

find /usr/local/bin -name sendtg –print  

Note: These examples indicate the importance of reading the on-line documentation about each command you use. You should verify the correct syntax and valid options for each command you use.

GETTING STARTED

You can connect to LampHost in a number of different ways, depending on the type of terminal you are using and how it is connected to the network.

Note: UNIX systems are case sensitive, which means that UNIX distinguishes between upper and lower-case characters. When logging in, make sure you type your login name and password using the proper case for each letter.

LOGGING ON

To log on to LampHost, use a ssh program to connect to your host, e.g. lamphost1.acns.colostate.edu.

You will be prompted to enter a username and password. Enter your eID and associated password at these prompts as show below.

After you connect to the system, your screen displays the following prompt:

login:

Enter your eID at this prompt. When you enter your eID, your screen displays the prompt:

Password:

Enter your password at this prompt. When you type your password, the system does not display it on the screen. After you enter your password, your screen displays the message of the day. In most cases, the screen will then display the prompt:

TERM = (termtype)

which is the system prompt for your terminal type. Enter the appropriate terminal type or press the RETURN or Enter key to accept the termtype specified in parentheses.

After you have entered your eID and password (and terminal type if necessary) your screen displays the system prompt. The prompt you see-either a percent sign (%) or a dollar sign ($)-depends on the shell you are using. (See below for more information about UNIX shells.)

When you see the system prompt, you are logged on and can proceed with your computing.

Example:

Here is a sample LampHost login session. Notice that the user’s password is not echoed on the screen.

SSH Secure Shell 3.2.0 (Build 267)  

Copyright (c) 20002002 SSH Communications Security Corp – http://www.ssh.com/  

This copy of SSH Secure Shell is a non-commercial version.  

This version does not include PKI and PKCS #11 functionality.    

Welcome to Ubuntu 12.04.5 LTS (GNU/Linux 3.2.079-generic x86_64)  

 * Documentation:  https://help.ubuntu.com/  

  System information as of Tue Jul 28 11:18:20 MDT 2015  

  System load:  2.17                Processes:           516  

  Usage of /:   92.4% of 121.01GB   Users logged in:     1  

  Memory usage: 40%                 IP address for eth0: 129.82.100.202  

  Swap usage:   21%  

  => / is using 92.4% of 121.01GB  

  => /boot is using 91.6% of 227MB  

  Graph this data and manage this system at:  

    https://landscape.canonical.com/  

36 packages can be updated.  

0 updates are security updates.  

36 packages can be updated.  

0 updates are security updates.  

New release ‘14.04.1 LTS’ available.  

Run ‘do-release-upgrade’ to upgrade to it.    

*** System restart required ***  

No mail.  

Last login: Mon Jul 27 15:16:36 2015 from mycomputer.acns.colostate.edu  

$   


UNIX SHELLS

When you have successfully logged in, a program called the shell is waiting for your next command. All UNIX systems have a shell that communicates the commands you type to the central processor. The shell reads the lines you type and executes them.

The shells available on LampHost are the Bourne shell (/bin/sh) and Bash (/bin/bash). The default prompt is a dollar sign ($).

Bash uses the .bashrc file as its start-up script, while the Bourne shell uses the .profile file as its start-up script. The .bashrc or .profile file is found in your home directory. The system uses the .bashrc or .profile file to set shell and environment variables. Shell variables are used to set values used during the current invocation of the shell. Environment variables, such as your terminal type and default printer, are stored in your environment where they are passed to any process you start from within the shell.

When the commands differ, this manual provides commands for both the Bash shell and the Bourne shell.

LOGGING OFF

To log off, enter the command:

exit

If you have started another shell after you logged in, use the exit command to exit that shell and return to the original shell.

CHANGING YOUR PASSWORD

To change your password, type passwd, enter your old password, your new password, and your new password again. Choose your password carefully. A variety of password guessing programs are widely used by computer crackers to gain illegitimate access to computer accounts. Such access then becomes the stepping stone for damaging entire systems. Your password is all that protects you from having your data examined, stolen or destroyed.

GETTING ON-LINE HELP WITH MAN

To provide on-line information about a command, UNIX has a man command; it stands for manual. At the system prompt, type:

man command

where command is a command you want information about. Enough text to fill your screen will be displayed; if more text is available, press the SPACE BAR to have it displayed after you read the first page. The man command provides highly detailed information about the syntax, the function, and any options that are available with the command. The on-line manual provided by the man command is a complete system manual written by programmers for programmers. Because of this, beginners usually need to study the man pages carefully to use them effectively. The information in a man page is organized into specific sections. The SYNTAX section shows the command line with all the associated options. The DESCRIPTION section details use of the command and describes any options. A man page may contain several other sections such as CAUTIONS, WARNINGS, NOTES, and FILES.

Example:

To see the manual page for the man command, type:

man man

Here is the first part of the man page you will see.

% man man  

man Command  

Key Concepts  

Purpose  

Displays manual entries online.  

Syntax  

man [ -k Keyword | -f Command] [-] [ – MPath ] [ Section ]  

Title  

Description  

The man command provides information on various reference articles, such as commands, subroutines and files.The man command  can provide one line descriptions of commands that are specified by name, or it can provide information for all commands whose  

-More-(7%)  

LISTING THE CONTENTS OF A DIRECTORY WITH LS

The ls command lists the names of the files and subdirectories in the current directory. You may also list specific files in a directory by typing:

ls options filenames

The most common options to the ls command are:

  • -l produces a “long” listing for each file (and subdirectory) in this directory; this listing includes the total number of files in this directory, each file’s permissions, owner, size, date and time of last modification, and filename
  • -a tells ls to include in its listing all files that begin with . (period); by default, ls ignores files that begin with a period
  • -F tells ls to add a character to the filename signifying what kind of file this is; a trailing / (slash) indicates that the file is a subdirectory; a trailing * (asterisk) indicates that the file is a script, also called an executable file (see the examples on the next page)-note that the characters are not a part of the file’s name, they are put there by ls so you can tell what kinds of files they are

In UNIX and Linux, a directory is just a special kind of file.

If you do not specify a filename on the command line, ls lists all the files in the current directory.

Examples:

To get a simple list of the contents of the current directory:

% ls  

bin file1 project1 project2 rje  

To list the special files in the current directory:

% ls -a  

.   .login      file1       rje  

..  .ntwkparms  project1  

.cshrc -bin     project2  

%  

To get a “long” listing of the contents of the current directory:

% ls -l  

total 5  

drwxr-xr-x 2 jones ACD0009 512 Feb 28 12:04 bin  

-rwxr-r-x  2 jones ACD0009 2695 Mar 22 10:31 file1  

drwxr-xr-x 7 jones ACD0009 512 Feb 20 15:17 project1  

drwxr-xr-x 2 jones ACD0009 512 Feb 20 12:50 project2  

drwxrwxrwx 2 jones ACD0009 512 Mar 13 16:02 rje  

%  

Note that the first part of each line shows the permissions for that particular file or directory. You can also see the owner and group of the file or directory, the size of the file, and the date and time the file was created. The last word on each line is the name of the file or directory.

You can also combine options, such as asking for a long listing that includes the special files of the current directory:

ls -la

CHANGING FILE PERMISSIONS WITH CHMOD

Only the owner of a file or directory can modify the permissions of that file or directory. The chmod command (which stands for change mode) is used to change permissions for a given file or directory. The syntax for the chmod command is:

chmod mode filename

where mode has the format: who_operator_permission

The who part of the mode can be one or any combination of:

  • u (user permission)
  • g (group permission)
  • o (others permission)

The operator part of the mode can be either:

  • + (adds permission)
  • – (subtracts permission)

The permission part of the mode can be one or any combination of:

  • r (read permission)
  • w (write permission)
  • x (execute permission)

Multiple modes can be specified if they are separated by commas and no spaces are included.

Examples:

To remove write permission for group and for others, from a file called data:

chmod go-w data

To add group write permission to the file data, and to remove all permissions for others:

chmod g+w,o-rwx data

CHANGING DIRECTORIES WITH CD

To change to another directory, use the cd command:

cd pathname

This places you in the directory indicated by pathname. Remember that pathnames can be relative or absolute.

The system file .., which is in every directory in UNIX, is commonly used in creating relative pathnames. Recall from the previous discussion that the file .. refers to the next highest directory level in UNIX.

Note: By default, the cd command with no pathname returns you to your home directory.

Examples:

If “jones” is in his home directory and he wants to move into his project2 directory, he would type:

cd project2

His current working directory is now project2.

If “jones” is in his project2 directory and he wants to move into his project1 directory, he would type:

cd ../project1

To return to his home directory, “jones” would type:

cd

DETERMINING YOUR CURRENT DIRECTORY WITH PWD

At times, we all wonder where we are in the UNIX directory structure (tree). The command to print working directory is:

pwd

The system responds with the absolute pathname up to and including the directory where you currently are.

Example:

When you enter the pwd command to see the pathname for your current directory, your screen displays something like:

%pwd

/h/jones/project1

CREATING NEW DIRECTORIES WITH MKDIR

To create a subdirectory, use the mkdir command; it stands for make directory. The syntax is:

mkdir pathname

The pathname may be either an absolute pathname or a relative pathname.

Examples:

If “jones” wants to create a new directory named project3 in his home directory, and he is currently working in his home directory, he would type:

mkdir project3

If “jones” wanted to create a working directory in the user temporary area (/tmp), and he was currently working in his home directory, he would use an absolute pathname such as:

mkdir /tmp/jones

To go to the directory you just made:

cd /tmp/jones

REMOVING DIRECTORIES WITH RMDIR

To remove (delete) a directory, use the rmdir command. The syntax is:

rmdir pathname

This removes the directory indicated by pathname. You must be sure first that the directory is empty, and that you are not currently in it. If these conditions are not met, rmdir cannot remove the directory. To make sure a directory is empty, you can change to that directory with the cd command, then list the files in it with the command:

ls -a

If the directory contains files (other than . and ..), you need to move them or delete them before you can remove the directory. Finally, you must change to a directory above the directory you want to remove, before using the rmdir command.

Example:

User “jones” is currently in his home directory. To remove his project2 directory, he would type:

rmdir project2

COPYING FILES WITH CP

To make a copy of a file, use the cp command:

cp oldname newname

If these files are to reside in the same directory, their names must be different; if the names match, AIX will replace the existing file with the new file. If these files are to reside in different directories, then use the appropriate pathnames (and it won’t matter if the filenames are the same).

Example:

If “jones” is working in his project1 directory and wants a copy of test.f in which to make changes, while keeping a copy of the original test.f, he would type:

cp test.f nutest.f

RENAMING FILES AND DIRECTORIES WITH MV

When you need to change the name of a file or directory in UNIX, you move it from one name to another using the mv command:

mv oldname newname

You can also literally move a file from one directory to another this way by using pathnames for oldname and/or newname.

Examples:

If “jones” is in his home directory, and he wants to move test.f into his project3 directory, here is one way he could do this. First, he can change directories to make project1 his current directory, then he can use a relative pathname for oldname and an absolute pathname for newname:

cd project1

mv test.f /h/jones/project3/test.f

Or, after changing to his project1 directory, he could use fewer keystrokes by using .., the system file which refers to the next highest directory and the fact that if he doesn’t specify a filename, mv uses the same filename it already has. The shortened mv command would be:

mv test.f ../project3

If “jones” is in his home directory and wants to rename file1 to datafile, he could use relative pathnames by typing:

mv file1 datafile

REMOVING FILES WITH RM

To remove (delete) files from a directory, use the rm command with this syntax:

rm options filename(s)

The rm command permanently deletes a file. Three options you can use with rm are:

  • -i causes rm to prompt you with a message to make sure that you really want to remove the file
  • -f tells rm not to send you any error messages (ignore any error conditions) and to remove the file if possible; you would use this option when you are deleting a list of files and you aren’t sure whether all of the listed files exist
  • -r tells rm to remove files recursively; this option is generally used when you want to remove all the files in a subdirectory and then remove the subdirectory itself

Examples:

To remove a file named file2 from your current directory:

rm file2

To remove the files named file3 and data from your current directory:

rm file3 data

You want rm to check with you before removing the file named data:

rm -i data

If you do not answer the prompt with a y (for “yes”), the rm command does not delete the file. Your screen displays:

% rm -i data

rm: Remove data?: n

%

DISPLAYING THE CONTENTS OF FILES WITH CAT

The cat command, which stands for catenate, displays the contents of file(s) specified on the terminal screen. If the file(s) listed have more lines than the number of lines on your screen, you won’t be able to read it because it may scroll by very quickly depending on the transmission speed of your modem or network. Use the more or pg command in these cases. The cat command is best used on short files that are not more than one screenful in length. The syntax for the cat command is:

cat filename(s)

Example:

To look at the contents of a file named file1:

cat file1

The contents of file1 are displayed on the screen.

COMBINING THE CONTENTS OF FILES WITH CAT

The cat command can also be used in conjunction with shell I/O redirection features to concatenate files together. Two redirection symbols you can use with cat are:

  • > redirects the output from your terminal to a specified file
  • >> append the results of the cat command to the end of a file

Example:

To combine files prog1, prog2, and prog3 and save the results in a destination file called finalprog:

cat prog1 prog2 prog3 > finalprog

The file finalprog now contains the concatenation of prog1, prog2, and prog3.

WARNING: In the command above, if the file finalprog had previously existed, it would have been overwritten. When using this command, make sure you do want to overwrite the destination file. Also, use a destination filename which is different from the source files listed, otherwise the source file contents may be lost.

Example:

To append the contents of file data2 to the end of file data1:

cat data2 >> data1

DISPLAYING THE CONTENTS OF A FILE WITH MORE

The more command allows you to display the contents of a text file on your terminal screen, one screenful at a time. An interactive command, more has its own set of subcommands that you can use after you’ve executed the command.

more filename

The more command displays a message at the lower left corner of your screen telling you how much of the file you have previewed. If the file contains fewer lines than the size of your terminal screen (there are generally 24 lines on a terminal), then more displays those lines and exits.

  • If the file contains more lines than the size of your terminal screen, you can get to the next screenful of the file by pressing SPACEBAR.
  • To get a brief listing of the subcommands for more, type ? (question mark) while the more command is running.
  • To exit from more at any time, type q (for quit) and press RETURN.

The following lists some of the common commands you may enter at the more prompt:

  • ? – displays help information
  • SPACEBAR – displays next screenful of the file
  • RETURN or Enter – displays next line of the file
  • /string – searches for first occurrence of string and displays that page
  • nf – skips forward n screenfuls of text
  • nb – skips backward n screenfuls of text
  • ns – skips forward n lines in the file
  • :f – displays current filename and line number
  • v – invokes the vi editor at the current line
  • q – quits more

Example:

You want to page through your ocean.data file using the more command:

more ocean.data

The first page of the file appears on your screen. To see the next page (screenful) of the file, press SPACEBAR.

A typical page of the ocean.data text file looks like this using more:

% more ocean.data  

3.142.66.99997.435624.3  

3.142.66.99997.435624.3  

3.142.66.99997.435624.3  

-More-(22%)_

DISPLAYING THE CONTENTS OF A FILE WITH PG

The pg command, which stands for page, has subcommands that allow you to move forward and backward and to search among the pages of your file. Some of these movement commands are listed below. The syntax of the pg command is:

pg options filename

The pg command displays one page (screenful) of the file on your screen. The options to pg must be entered on the command line.

The pg command also displays a : (colon) prompt at the bottom of the screen.

You may enter the movement commands (pg subcommands) only at the colon prompt at the bottom of the screen. The following table lists some of the more common commands that you may enter at this colon prompt:

  • RETURN or Enter – displays the next screenful of the file
  • $ – goes to the last screenful of the file
  • n – moves to page n
  • +n – moves forward n pages
  • -n – moves backwards n pages
  • . – redisplays current page
  • /string – searches for the first occurrence of string and displays that page
  • ?string – searches backwards for the first occurrence of string and displays that page
  • d – scrolls forward half a page
  • -d – scrolls backwards half a page
  • f – skips the next screenful of the file
  • h – displays help information
  • xl – begins the screenful at line x
  • q – quits pg

Example:

To look at the contents of a file named file3 one page at a time:

pg file3

Now you want to page through the file ocean.data using the pg command:

pg ocean.data

The first page of the file appears on your screen. To see the next page of the file, press RETURN.

A typical page of the ocean.data text file looks like this using pg:

% pg ocean.data  

3.142.66.99997.435624.3  

3.142.66.99997.435624.3  

3.142.66.99997.435624.3  

:_

 

CommandFunctionExample
catDisplays contents of file on screen
Appends contents of file2 to file1
cat file1
cat file2 >> file1
cdChanges directorycd project4
chmodChanges permissions of a file or directorychmod ug+x data
cpCopies contents of a file to a new filecp test.f nutest.f
lsLists the contents of a directoryls -l
manFinds manual information by keywordman cat
mkdirMakes a new directorymkdir project4
moreDisplays contents of file on screen, one screenful at a timemore file3
mvMoves or renames a filemv myfile nuname
pgDisplays contents of a file on screen, one page at a time,
allowing forward and backward movement
pg file3
pwdLists name of present working directorypwd
rmRemoves a filerm file2
rmdirRemoves a directory that does not contain any filesrmdir project4

DESCRIPTION:

SSH (Secure SHell) is a terminal emulation protocol that is used to log into a remote host computer on the Internet. You establish a connection to the remote computer using the ssh command, then log in just as if you were a local user.

A person who wishes to log into a remote host with the ssh command must provide a user name and password for the remote computer. This is similar to the procedure used for logging into a local host. Because ssh is one of the TCP/IP protocols, it is supported on thousands of computers both nationally and internationally. SSH is a replacement for telnet, which sent information in plaintext, making passwords and other data vulnerable to interception. SSH uses encryption, which allows secure connections over the insecure Internet. The instructions in this bulletin are for using ssh on LampHost. SSH programs for personal computers, such as PuTTY, function in a similar manner.

DOCUMENTATION:

You can view online information about ssh by logging into LampHost, and entering the following command at the system prompt on LampHost:

man ssh

SSH is a powerful protocol, allowing such features as passwordless SSH connections, the execution of a single command on a remote host, and forwarding of X11 connections and TCP/IP ports. You can find more documentation on these features in the man page, as well on the Internet.

ACCESS:

To use ssh, you invoke the ssh command and specify the computer to which you want to connect. To open a ssh session on LampHost, enter the command:

ssh destination

where destination is a domain name (e.g., lamphost1.ancs.colostate.edu), or an Internet address (e.g., 129.82.100.202), or an abbreviated name that has been predefined on the local host (e.g., lamphost1).

Your screen will display a login message from the remote computer. At this point, enter your user name and password for the remote host.

When you have logged in successfully, the screen displays the system prompt for the remote host, and you can issue commands.

You can also specify a login name on the ssh command line. For example, if you wanted to login to LampHost as user pmh, you could use the command:

ssh pmh@lamphost1.acns.colostate.edu

If you are doing screen oriented commands, such as man, vi and more, and experience problems using these commands while running ssh, it it likely because the terminal type on the remote host does not match the terminal type on the local host. You will need to use appropriate commands on the remote host to set the terminal type to match your terminal type on LampHost1.

ENDING A SSH SESSION:

When you have finished computing on the remote host, log off as you normally would. This closes the connection between your local computer and the remote host. Once you have logged off, your screen displays the message: Connection to <destination> closed

DESCRIPTION

Pico is a simple text editor developed by the University of Washington for the Pine mail system. You can use Pico with Pine or as a general purpose editor on LampHost. Commands are displayed at the bottom of the screen, and context-sensitive help is provided. As characters are typed they are immediately inserted into the text. Editing commands are entered using control-key combinations. The editor has four basic features: paragraph justification, case-insensitive searching, a spelling checker, and a file browser.

Paragraph justification takes place in the paragraph that contains the cursor, or, if the cursor is between lines, in the paragraph immediately below. Paragraphs are delimited by blank lines, or by lines beginning with a space or tab. To cancel justification, use the control- U key combination immediately after justification.

String searches are not sensitive to case. A search begins at the current cursor position and wraps around the end of the text. The most recent search string is offered as the default in subsequent searches.

The spell checker examines all words in the text. It then offers, in turn, each misspelled word for correction while simultaneously highlighting it in the text. Spell checking can be canceled at any time.

The file browser is offered as an option in the “Read File” and “Write Out” command prompts. It helps you search for specific files and navigate directory hierarchies. File names with sizes and names of directories in the current working directory are presented for selection. The current working directory is displayed on the top line of the display while the list of available commands takes up the bottom two. Several basic file manipulation functions are supported: file renaming, copying, and deletion.

ACCESS

To start Pico, enter the command:

pico

or

pico filename

where filename is the name of an existing file you want to edit or the name of a file you wish to create. If you don’t specify a filename, Pico opens a blank file.

Each character you type is automatically inserted into a buffer at the current cursor position. Pico automatically wraps the text to a new line when you come to the right margin. You only need to press the Return key to start a new paragraph. Editing commands are performed by typing special control-key combinations. (See the section, “Pico editing commands.”)

USING PICO’S ONLINE HELP

To access Pico’s online help, simply press ^G (hold down the CTRL key while pressing the G key).

SAVING TEXT

To save your file, press ^O. Pico will prompt you to enter a filename. If the file doesn’t have a name yet, you must type one. If the file already has a name, it will follow the filename prompt, and you can just press Return.

EXITING PICO

When you are finished with your editing session, press ^X to exit Pico. Press Y to save your changes and N to leave the file as it was.

PICO EDITING COMMANDS

You perform editing commands in Pico by typing special control-key sequences. A caret, ‘^’, is used to denote the control key, so the CTRL-x key combination is written as ^X. To type the ^X combination, hold down the CTRL key, then press the x key. The following commands are available:

  • ^G Display online help text.
  • ^F Move Forward a character.
  • ^B Move Backward a character.
  • ^P Move to Previous line.
  • ^N Move to Next line.
  • ^A Move to beginning of current line.
  • ^E Move to End of current line.
  • ^V Move forward a page of text.
  • ^Y Move backward a page of text.
  • ^W Search for (where is) text, neglecting case.
  • ^L Refresh the display.
  • ^D Delete the character at the cursor position.
  • ^^ Mark cursor position as beginning of selected text. To type this key combination, hold down the CTRL and Shift keys and press the 6 key. Then press the arrow keys to mark the selected text. Note: Setting mark when already set cancels the selection.
  • ^K Cut selected text (displayed in inverse video). If no text is selected, the current line is deleted. Note: The selected text’s boundary on the cursor side ends at the left edge of the cursor. So, with selected text to the left of the cursor, the character under the cursor is not selected.
  • ^U Uncut (paste) last cut text inserting it at current cursor position.
  • ^I Insert a tab at the current cursor position.
  • ^J Format the current paragraph. Note: paragraphs are delimited by blank lines or indentation.
  • ^T Invoke the spell checker.
  • ^C Report current cursor position.
  • ^R Insert an external file at the current cursor position.
  • ^O Output the current buffer to a file, saving it.
  • ^X Exit Pico, saving buffer.

Pine and Pico are trademarks of the University of Washington. No commercial use of these trademarks may be made without prior written permission of the University of Washington.

Editor’s Note: This bulletin is based on Pico’s online help and main pages.

MAKING PICO YOUR DEFAULT EDITOR

To make Pico your default editor, you must set the UNIX environment variable EDITOR.

C Shell

C shell users (% prompt) may add the following line to their .login file:

setenv EDITOR /usr/local/bin/pico

Bourne or Korn Shell

Korn shell users ($ prompt) may add the following line to their .profile file:

export EDITOR=/usr/local/bin/pico

Vi is a full-screen text editor that is available on most Unix systems. It is functionally compatible on all defined terminal types. While advanced users may consider vi a useful tool, it is not straightforward to learn. This article presents a battle plan for getting started using the vi editor.

To invoke the vi editor on a file, type:

vi filename

POSITIONING YOUR FORCES

Before you can edit or append information in a text file, you must first get to the point in the file where that information is or will be located. Vi has several commands and capabilities for doing this.

Most keyboards have cursor keys. If your terminal and the terminal type you are using on the UNIX system are compatible, you should be able to use the cursor keys to position yourself within a file.

The cursor keys operate just as they appear to: the key marked with an upward arrow moves the cursor up one line each time you press the key, the left-directed arrow key moves the cursor one character to the left, and so on.

If your keyboard doesn’t have cursor keys, or if they don’t work properly with your terminal, vi supports four commands that serve the same function of positioning the cursor. These commands are h, j, k and l. These commands function, respectively, as left-arrow, down-arrow, up-arrow and right- arrow.

The cursor keys and commands are used for “fine positioning” within a file; generally only to position the cursor within the text that is currently displayed on the screen. To locate the correct position within a large text file, use one of the following positioning commands:

  • -F move forward one screenful (press F while pressing Ctrl)
  • -B move back one screenful (press B while pressing Ctrl)
  • nG position to line number n, by default the last line
  • /string search forward for string
  • ?string search backward for string
  • n search for next occurrence of string in the same direction
  • N search for next occurrence of string in the opposite direction

OUTGUESSING THAT SURREPTITIOUS INPUT MODE

The positioning commands in vi operate only while vi is in command mode, which is the mode in which vi starts. By entering any one of several vi input commands you switch vi to input mode. Once in input mode, any character you type is taken to be text and is added to the file. This includes any commands you may attempt to execute, with the exception of the escape (Esc) key, which causes vi to exit input mode.

Vi’s input and command modes are sneaky: vi doesn’t give you labels on the screen indicating the current mode, making it easy to lose track of what mode you’re in. If this happens, the easy way to regain your bearings is to press the escape (Esc) key. Then if the bell on your terminal rings or your screen flashes, you were already in command mode; otherwise, you were previously in input mode, but are now in command mode. In either case, you’ll end up in command mode, where you can reposition for the next modification.

Note: Many UNIX systems have a vi option called “showmode.” After starting vi, type

:set showmode

Then the words “INPUT MODE” will appear on the status line whenever you are in input mode. Following are some of the standard input commands for vi:

  • i insert text before the current cursor position
  • a append text after the current cursor position
  • o open a line following the line the cursor is on and position the cursor at the beginning of that line
  • O open a line before the line the cursor is on and position the cursor at the beginning of that line

Any of these commands leaves vi in input mode until you press Esc. Pressing the RETURN key will not take you out of input mode.

PREVENTING DELETION CASUALTIES

Vi supports several commands for deleting text. These commands are distinguished by the resulting amount of text that is deleted. One delete command you must exercise caution with is “dd”, which is used to delete an entire line at a time. Because the command consists of duplicate letters, it’s easy to lose track of how many d’s you have typed, and end up with an extra “d”. Depending on what command you attempt after this, you might not be happy with the result!

For this reason, it is recommended that you type “dd” to delete the first line of text, then “.”, which repeats the previous command, for each additional line you want to delete. Remember that once you type another command, the “.” command is no longer loaded with the “dd” function, and the new command will be repeated.

The deletion commands can all be prefixed with a repeat count. Thus, instead of typing a sequence of ten d’s to delete 5 lines, or 2 d’s followed by 4 periods, you could type “5dd”, a savings of seven or three keystrokes, respectively, minus a few seconds to count lines on the screen.

The basic delete commands follow:

  • x delete a single character at the current cursor position
  • dd delete the line at the current cursor position
  • dw delete a “word” (defined to be all contiguous text from the cursor up to the first special character or space)
  • D delete from the current cursor position to the end of the line

RECOUPING YOUR LOSSES

If you get yourself into trouble with one of the delete commands or some other command, you can undo the result of the most recent change using the “u”, or undo command. Likewise, if you’ve made several changes in a row within the same line of a file, you can undo the whole set of changes by typing “U”.

SURRENDERING WITH HONOR

If you really get yourself in trouble; say, if you forget that you’re not in input mode and type some random sequence of characters, and have no idea what you really did, the safest option is to bail out. To quit the editor without saving any of your changes, type:

:q!

To keep your losses to a minimum from such a disaster, it’s a good idea to save your changes every five or ten minutes as you work. To do this, escape out of input mode (if necessary) and type the following command:

:w

CLAIMING VICTORY

As mentioned in the previous section, typing “:w” writes the contents of the current editor buffer to the permanent copy of your file. If you want to save your changes and get out of the editor at the same time, type:

:wq

You can also save changes to a new file, by specifying another filename following the command. For example:

:wq article.new

writes the current contents of the editor buffer to the file article.new and exits the editor. The file being edited, let’s say it’s called article, would be unchanged.

writes the current contents of the editor buffer to the file article.new and exits the editor. The file being edited, let’s say it’s called article, would be unchanged.

CHANGING THE BATTLE PLANS WITH CHANGE AND REPLACE COMMANDS

Vi provides the following commands to allow you to change characters, words or lines.

  • s substitute for the character at the current cursor position
  • cw change from the current cursor position to the end of the current “word” (defined to be all contiguous text from the cursor up to the first special character or space)
  • c$ or C change from the current cursor position to the end of the current line

After you enter one of the above change commands, vi displays a $ over the last character that will be affected by your change, thus delimiting the field of change.

You can adjust the field of change by prefixing a command with a repeat count. For example, the command “6s” substitutes your input text for the next six characters.

Once you enter a change command, vi puts you into input mode. (See “Outguessing that surreptitious input mode”) Now any character, characters, words or lines you type will be inserted into your file in place of the delimited field.

As with the other input mode commands, you terminate entering input by pressing the Escape key.

You can alter your tactics slightly from those used by the change commands by using the replace commands. The replace commands are distinguished from the change commands in that text is replaced character-by-character. This means there is no delimited field: it is up to you to avoid overtyping text you wish to keep, or to clean up extraneous text not overtyped.

The replace commands introduce a new vi mode: REPLACE MODE, which is displayed at the bottom of your screen if you set showmode.

  • rc replace the character at the current cursor position with “c”
  • R replace text character-by-character starting at the current cursor position until the Escape key is pressed

MARCHING IN STRAIGHT LINES USING TAB STOPS AND AUTO-INDENT

Normally when you enter text into a file using the vi editor, you want the text to line up on the left side of the screen. However, you may occasionally need to set off a paragraph or quote by indenting it or to enter columnar data in a data file or report. If you are a programmer, you need to indent your code to enhance its readability.

You may accomplish any of these tasks by inserting the tab character at appropriate places within your entered text. Pressing the tab key while you are in the vi editor causes vi to position the cursor at the next tab stop.

Tab stops are pre-defined in vi, and you can’t set them arbitrarily as you can on a typewriter or in a more sophisticated word processing package. By default, vi sets tab stops every 8 columns. While you can’t override the even placement of tab stops, you can change their frequency. To change the frequency of the tab stops, type:

:set tabstop=#

where # represents a decimal number. Note that tab characters are stored as part of your file but the tab stops aren’t. Therefore, the actual location of the text may vary depending on where vi’s tab stops are currently set.

One problem with indenting text is that it can get very tedious tabbing over to the indentation column every time you go to a new line. Vi has an answer for this though. By typing:

:set autoindent

you tell vi to do the work for you. Now every time you press the Return or Enter key in input mode to go to a new line, vi positions your cursor underneath the first character of the previous line and you’re ready to start entering more text from there.

But what if you’re done indenting? You may notice that in autoindent mode, vi won’t let you backspace from the first character position, even though there appears to be white space to the left of the cursor.

If you want to move your starting column back to the left you must press CTRL-D once for each tabstop you want to back up (up to the far left column).

To turn off vi’s autoindent feature, just type:

:set noautoindent

MAN-TO-MAN COMBAT WITH MATCHED PARENTHESES, BRACKETS AND CURLY BRACES

If your text includes either programming code or mathematical formulas, evenly matching certain symbols, such as parentheses, square or curly braces, is probably a concern to you.

Vi has a couple of features to help you out with this. First, if you position your cursor over any one of the special symbols ( ) [ ] { } and press %, vi will reposition your cursor on the symbol that corresponds to the one on which your cursor was positioned. Press % again to jump back to where you were. If a match doesn’t exist, vi will ring your terminal bell and will not reposition the cursor.

You can also set vi to check matches on the special symbols ( ) and {} automatically as you enter text. To set this option, type:

:set showmatch

With showmatch set, each time you enter a right parenthesis or a right curly brace, vi automatically checks for a corresponding left parenthesis or curly brace. As it does so, vi briefly positions your cursor to the corresponding left-hand symbol allowing you to verify that it is the correct match, then back to the symbol you just entered. If you enter a right parenthesis or curly brace without having entered the corresponding left-hand symbol, vi will ring your terminal bell, but will allow you to continue typing.

To turn off the showmatch option, type:

:set noshowmatch

CALLING FOR REINFORCEMENTS FROM OTHER FILES

Have you ever wanted to insert all or part of the contents of another file into the one you were currently editing? Vi provides a couple ways to do that. The simplest way is to use the :r command to read in the full file, then use the deletion commands to clean up whatever you don’t need. (See “Preventing Deletion Casualties”)

First, making sure you are in command mode, position your cursor to the line above where you want to make the file insertion. Then type:

:r filename

to read the file in. Once vi is through reading filename, it will leave the cursor on the first character of the first line of the inserted file.

 

 

Invoking vi:

vi filename

Format of vi commands:

[count] [command]

where count repeats the effect of the command.

COMMAND MODE VERSUS INPUT MODE

Vi starts in command mode. The positioning commands operate only while vi is in command mode. You switch vi to input mode by entering any one of several vi input commands. (See next section.) Once in input mode, any character you type is taken to be text and is added to the file. You cannot execute any commands until you exit input mode. To exit input mode, press the escape (Esc) key.

INPUT COMMANDS (END WITH ESC)

  • a Append after cursor
  • i Insert before cursor
  • o Open line below
  • O Open line above
  • :r file Insert file after current line

Any of these commands leaves vi in input mode until you press Esc. Pressing the RETURN key will not take you out of input mode.

CHANGE COMMANDS (INPUT MODE)

  • cw Change word (Esc)
  • cc Change line (Esc) – blanks line
  • c$ Change to end of line
  • rc Replace character with c
  • R Replace (Esc) – typeover
  • s Substitute (Esc) – 1 char with string
  • S Substitute (Esc) – Rest of line with text
  • . Repeat last change

CHANGES DURING INSERT MODE

  • h Back one character
  • w Back one word
  • u Back to beginning of insert

FILE MANAGEMENT COMMANDS

  • :w name Write edit buffer to file name
  • :wq Write to file and quit
  • :q! Quit without saving changes
  • ZZ Same as :wq
  • :sh Execute shell commands (d)

WINDOW MOTIONS

  • d Scroll down (half a screen)
  • u Scroll up (half a screen)
  • f Page forward
  • b Page backward
  • /string Search forward
  • ?string Search backward
  • l Redraw screen
  • g Display current line number and file information
  • n Repeat search
  • N Repeat search reverse
  • G Go to last line
  • nG Go to line n
  • :n Go to line n
  • z Reposition window: cursor at top
  • z. Reposition window: cursor in middle
  • z- Reposition window: cursor at bottom

CURSOR MOTIONS

  • H Upper left corner (home)
  • M Middle line
  • L Lower left corner
  • h Back a character
  • j Down a line
  • k Up a line
  • ^ Beginning of line
  • $ End of line
  • l Forward a character
  • w One word forward
  • b Back one word
  • fc Find c
  • ; Repeat find (find next c)

DELETION COMMANDS

  • dd or ndd Delete n lines to general buffer
  • dw Delete word to general buffer
  • dnw Delete n words
  • d) Delete to end of sentence
  • db Delete previous word
  • D Delete to end of line
  • x Delete character

RECOVERING DELETIONS

  • p Put general buffer after cursor
  • P Put general buffer before cursor

UNDO COMMANDS

  • u Undo last change
  • U Undo all changes on line

REARRANGEMENT COMMANDS

  • yy or Y Yank (copy) line to general buffer
  • “z6yy Yank 6 lines to buffer z
  • yw Yank word to general buffer
  • “a9dd Delete 9 lines to buffer a
  • “A9dd Delete 9 lines; Append to buffer a
  • “ap Put text from buffer a after cursor
  • p Put general buffer after cursor
  • P Put general buffer before cursor
  • J Join lines

PARAMETERS

  • :set list Show invisible characters
  • :set nolist Don’t show invisible characters
  • :set number Show line numbers
  • :set nonumber Don’t show line numbers
  • :set autoindent Indent after carriage return
  • :set noautoindent Turn off autoindent
  • :set showmatch Show matching sets of parentheses as they are typed
  • :set noshowmatch Turn off showmatch
  • :set showmode Display mode on last line of screen
  • :set noshowmode Turn off showmode
  • :set all Show values of all possible parameters

MOVE TEXT FROM FILE OLD TO FILE NEW

  • vi old
  • “a10yy yank 10 lines to buffer a
  • :w write work buffer
  • :e new edit new file
  • “ap put text from a after cursor
  • :30,60w new Write lines 30 to 60 in file new

REGULAR EXPRESSIONS (SEARCH STRINGS)

  • ^ Matches beginning of line
  • $ Matches end of line
  • . Matches any single character
  • * Matches any previous character
  • .* Matches any character

SEARCH AND REPLACE COMMANDS

Syntax:

:[address]s/old_text/new_text/

Address components:

  • . Current line
  • n Line number n
  • .+m Current line plus m lines
  • $ Last line
  • /string/ A line that contains “string”
  • % Entire file
  • [addr1],[addr2] Specifies a range

Examples:

The following example replaces only the first occurrence of Banana with Kumquat in each of 11 lines starting with the current line (.) and continuing for the 10 that follow (.+10).

:.,.+10s/Banana/Kumquat

The following example replaces every occurrence (caused by the g at the end of the command) of apple with pear.

:%s/apple/pear/g

The following example removes the last character from every line in the file. Use it if every line in the file ends with ^M as the result of a file transfer. Execute it when the cursor is on the first line of the file.

:%s/.$//