GETTING STARTED WITH UNIX ACNS BULLETIN UX-01 SEPTEMBER 1995 Getting Started with UNIX and AIX What is AIX? ------------ AIX is a version of the UNIX operating system developed by IBM. AIX is based on both UNIX System V (pronounced "System Five") and BSD 4.3 (Berkeley Software Distribution), two popular UNIX standards. If you are already familiar with UNIX, AIX will appear to be similar. In addition to the standard UNIX commands, AIX 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. Later, 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. The C shell is the default for academic accounts on ACNS UNIX systems. The Korn shell is the default for undergraduate accounts. We've included this history because you will frequently hear the terms AT&T System V, Bourne shell, Berkeley, BSD, C shell, and Korn shell. Although we primarily address generic UNIX or specific AIX issues in this manual, we also have to describe the differences between the shells. (See Page 9.) The UNIX file system -------------------- The UNIX and AIX 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 logon ID 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/ucb (BSD) /usr/local/bin The /bin, /usr/bin, and /usr/ucb 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 Lamar are located in this directory. Library directories ------------------- Software libraries for AIX are normally located in one of these directories: /lib /usr/lib /usr/local/lib The /lib and /usr/lib directories are reserved for AIX system libraries, and the /usr/local/lib directory contains machine specific libraries. Home directories for users -------------------------- When you log onto Lamar or Holly, you are placed in your home directory. For example, if your logon ID is smith, your home directory path might be /h/smith. Figure 1 shows this structure. 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 Lamar or Holly 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: command options filenames 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 Lamar or Holly 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 ---------- After you connect to the system, your screen displays the following prompt: login: which is the system prompt for your logon id. When you enter your logon id, your screen displays the prompt: Password: which is the system prompt for the password that goes with your logon id. 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. (See Page 10 for more information about terminal types.) After you have entered your login ID 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 the next page for more information about UNIX shells.) When you see the system prompt, you are logged on and can proceed with your computing. 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 three most commonly used shells available on Lamar and Holly are the C shell, the Bourne shell and the Korn shell. The C shell is the default for academic accounts; the Korn shell is the default for undergraduate accounts. The C shell and the Korn shell each have different prompts: * The default prompt for the C shell is a percent sign (%). * The default prompt for the Bourne or Korn shell is a dollar sign ($). The C shell uses the .login file as its start-up script, while the Korn shell uses the .profile file as its start-up script. The .login or .profile file is found in your home directory. The system uses the .login 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. The C shell and the Korn shell each use different commands to set values for shell and environment variables. * C shell uses the set command to set shell variables and the setenv command to set values for environment variables. * The Korn shell uses an assignment statement to set shell variables and the export command to set values for environment variables. When the commands differ, this manual provides commands for both the C shell and the Korn shell. Terminal types -------------- When the screen displays the prompt: TERM = (termtype) you must enter a valid terminal type. Valid terminal types include vt100, tvi970, wyse60, vt220, and others. If you have a terminal type that is not in this list, try typing the name of your terminal without capital letters or spaces. * If you press RETURN when prompted for your terminal type, the system selects the termtype specified in parentheses. * If you enter a termtype that the system doesn't recognize, the default termtype is set to unknown, and the system prompts you again for termtype. You may enter another terminal type or press RETURN to accept "unknown" as a terminal type. However, you will not be able to use full-screen applications such as vi or info if your termtype is set to unknown. Listing terminal types ---------------------- After you have logged in, you may enter the following command to see a list of currently accepted terminal types: lsterm Checking your terminal type --------------------------- To check the terminal type your login is currently using, enter the command: echo $TERM Setting your terminal type -------------------------- Although your terminal type is typically set as part of the login process, you can check or set your terminal type anytime after you log in. To change your terminal type, use the tset command. This command works differently depending on which shell you are running. Korn shell ---------- Korn shell users ($ prompt) may change their terminal type by entering: eval 'tset -s termtype' C shell ------- C shell users (% prompt) may change their terminal type by entering: set noglob eval 'tset -s termtype' unset noglob Examples ======== Korn shell ---------- To set your terminal type to vt100 under the Korn shell ($ prompt): eval 'tset -s vt100' C shell ------- To set your terminal type to vt100 under the C shell (% prompt): set noglob eval 'tset -s vt100' unset noglob Example Here is a sample Lamar login session. Notice that the user's password is not echoed on the screen. IBM AIX Version 3 for RISC System/6000 (C) Copyrights by IBM and by others 1982, 1990. lamar login: beth beth's Password: *** IBM AIX Version 3.2! Questions or problems? Contact a consultant at: Room 224 Weber Building (M-F 8:30 - noon, 1 - 4:30) phone: 491-7276 e-mail: consult@lamar.colostate.edu NOTICE: Type 'man lamarquotas' for quota information. Type 'man sw' for software information. Tin threaded newsreader now available on lamar. Enter your terminal type at the following prompt or press return to get VT100. TERM = (vt100) vt100 Erase is Ctrl-H Kill is Ctrl-U Interrupt is Ctrl-C TERM=vt100 PRINTER=mailit $ 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 with passwd ---------------------------------- If you are a new user, the system will prompt you to change your password the first time you log on. You should continue to change your password often for optimum security. The passwd command allows you to change your password. When you type passwd with no options, the system prompts you to enter your old password, then your new password, then your new password again (to make sure you didn't make a typing mistake the first time). None of these passwords appear on the screen. 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. Guidelines for good passwords: * DO change your password frequently. * DO combine upper and lower case letters and punctuation. * DO choose a password that is longer than five characters. * DO choose a nonsense word or the first letters of words in a phrase. * DO keep your password a secret. * DON'T use your name or user ID as a password. * DON'T use a word that can be found in the dictionary. * DON'T write or post your password next to your terminal. Example Here is an example of what you will see when you type the passwd command. Note that you cannot see any of the passwords you type. % passwd Changing password for "beth". beth's Old password: beth's New password: Retype new password: % 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. While viewing a manual page, the following commands can be used: 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 ar- ticles, 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%) Using InfoExplorer on-line documentation ---------------------------------------- One of the problems with using the manual pages is that you are required to know the name of the command before you can access the documentation. Many times this isn't the case. On ACNS UNIX systems, the utility InfoExplorer can be used to help you determine the command name yourself. What is InfoExplorer? --------------------- InfoExplorer is a hypertext documentation utility which allows access to documentation for the AIX Operating System and associated programs. All of the documentation available for AIX, is available within InfoExplorer. The manual list includes the Base Operating System Reference Manual, Editing Concepts & Procedures and the C/Pascal/FORTRAN Compiler Reference Manuals and User's Guides. Running InfoExplorer -------------------- To run InfoExplorer, simply enter the command: info InfoExplorer opens a navigation screen and a reading screen. The reading screen displayed has information on how to proceed. However, by using the cursor keys and the following key sequences you can begin exploring on your own: ---------------------------------------------------------- Key sequence What this key sequence does ----------------------------------------------------------or Enter selects menu option or hypertext link ctrl-o move into or out of the menu bar ctrl-b position to previous hypertext link ctrl-f or position to next hypertext link ctrl-n page forward one page ctrl-p page backward one page ---------------------------------------------------------- Some items in the InfoExplorer text are hypertext links to other pieces of information. These links are indicated by underscores with the selected link in inverse video. You can position to a link within an article and then follow the link to the new information by simply pressing the RETURN key. For more information on running the info command see the help menu option within InfoExplorer itself or look at the manual page (man info). Searching with InfoExplorer --------------------------- Probably the most useful feature of InfoExplorer is the search capability. You can perform searches over the full InfoExplorer documentation set for a single phrase or various combinations of several phrases. For example, when coding a FORTRAN program you may need to know the syntax of the READ statement. You could perform a search for all the articles which contain the phrases 'FORTRAN', 'READ Statement' and 'syntax'. The section of the information base entitled 'FORTRAN Programming Languages' has several matches. One of the articles in this section is titled READ, WRITE and PRINT statements. This article will probably include the information you need. If you'd like to get a listing of the books included in InfoExplorer, select the Display option from the menu bar, then select Books. You can select any of the books listed, view the table of contents, and then look at the actual text of a chapter if you desire. NOTE If you are telneting into Lamar or Holly and are having trouble with the cursor keys not acting properly within the info program, try setting your ESCDELAY environment variable to 1250. C shell ------- C shell users (% prompt) can add the following command to their .login file, and the next time they log in the variable will be set: setenv ESCDELAY 1250 Korn shell ---------- Korn shell users ($ prompt) can add the following command to their .profile file, and the next time they log in the variable will be set: export ESCDELAY=1250 You can also enter these commands at the prompt, and the variable will be set for the current session. 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 AIX, 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. A full discussion of file permissions appears on pages 5-7. 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 discussion on page 5-6 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. Example 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 Example 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 data: y % 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 table lists some of the common commands you may enter at the more prompt: --------------------------------------------------------------- Command What this command does ------------------------------------------------------------ ? 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.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.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: ---------------------------------------------------------- Command What this command does ---------------------------------------------------------- RETURN displays the next screenful of the file or Enter $ 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.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 3.14, 2.6, 6.9999, 7.4356, 24.3 :_ Printing files with lpr To print a file, use the lpr command: lpr options -Pprinter -Jbanner filename(s) -Pprinter directs your output to a specific printer or print queue. Currently five print queues are defined on Lamar and Holly: msite Line printer output printed at Main Site (located in basement of E-wing, Engineering Bldg.) weber Line printer output printed at the CTSS Lab (located on the second floor of the Weber Bldg.) msiteps PostScript output printed at Main Site msitehp HP LaserJet output printed at Main Site mailit Sends the output to your mailbox -Jbanner specifies the ID that appears in extra large letters on the cover page of the output. If you do not specify -Jbanner, your login name is used. -Jbanner is also used to file output in boxes at Main Site. A banner of bx15zzz indicates that the output should be filed in box 15 at Main Site. The lpr command copies the file(s) to the specified print queue. The file will be printed when it moves to the head of the queue. NOTE The lpr command is discussed in more detail in the ACNS UNIX Bulletin, "UX-002: Printing on ACNS UNIX Systems," available in the CTSS Computer Lab, 2nd floor Weber Building. Examples To print the files prog1.f and prog2.f at Main Site with a banner of bx15zzz (the output will be placed in box 15 at Main Site), type: lpr -Pmsite -Jbx15zzz prog1.f prog2.f To print the file final as standard line printer output at the CTSS Lab with the user's login name as the banner, enter the command: lpr -Pweber final Using the PRINTER variable to define a default printer ------------------------------------------------------ You can define a default printer to which all your print jobs will be sent by specifying a PRINTER variable. Once you have set up the PRINTER variable, you can print as many files as you'd like without specifying the -P option on the lpr command. To determine your default printer, type echo $PRINTER C shell ------ C shell users (% prompt) may change the default printer to the CTSS Lab by entering the command: setenv PRINTER weber This command changes the default printer for the current login session. To set your printer to the CTSS Lab automatically whenever you log in, add this command to your .login file. The new printer takes effect the next time you log in. Korn shell ---------- Korn or Bourne shell users ($ prompt) may change the default printer to the CTSS Lab by entering the command: export PRINTER=weber This command changes the default printer for the current login session. To set your printer to the CTSS Lab automatically whenever you log in, add this command to your .profile file. The new printer takes effect the next time you log in. Checking on the status of a print job with lpq ---------------------------------------------- You can look at all the jobs queued up and waiting to print on a particular printer by using the lpq command. To check on the status of a print job, use the lpq command: lpq -Pprinter If the -P option is not used, lpq checks the status of the printer specified by the PRINTER variable. Example: To view the print jobs queued up for the printer at Main Site: % lpq -Pmsite Queue Dev Status Job Files User PP % Blks Cp Rnk ----- --- ------ --- ----- ---- -- - ---- -- --- msite msite RUNNING 617 prog1.f smith 0 0 10 1 1 %