1.0 Introduction
2.0 Connecting to ROHAN
3.0 Finding Help
4.0 Available Software
5.0 Solaris 10 OS
6.0 File Security
7.0 Printing
8.0 Email
5.0 Solaris 10 Operating System
5.1 Start-Up Considerations for the First-Time User
5.2 Working With Files
5.3 Commands
5.4 Using the Language Compilers
5.5 Editing Files
5.1 Start-Up Considerations for the First-Time User
- Your account is created with a unique password, default startup file (.login), shell and disk quota.
- The command to change your password is passwd. Be sure to remember your password and keep it private.
- Your account username is also your Email name on the system. Your email address will be username@rohan.sdsu.edu
- The name Email uses for your real name is called a finger name. You can change it from your username with the chfn command.
- When leaving your workstation unattended on campus, it is best to logout to prevent others from making changes to your account.
5.2 Working With Files
Virtually all the work you will do involves the creation, modification and manipulation of files. A file is an organized collection of information referenced by a unique full filename or pathname. Contents of the file may represent a source program, text of a document, data, etc.
The UNIX operating system provides a hierarchical file organization. The naming structure consists of the path (the hierarchy of directories) and the filename itself. NOTE: Both the path and the filename together comprise the file's pathname.
- 5.2.1 Directories, Paths and Filenames
5.2.2 The Login Startup File (.login)
5.2.3 Disk Quotas and /tmp Usage
5.2.4 File Protections
5.2.5 Web Page File Protections
5.2.6 Displaying and Copying Files
5.2.7 Deleting and Renaming Files
5.2.8 Comparing and Sorting Files
5.2.9 Re-Directing Input and Output5.2.1 Directories, Paths and Filenames
Directories are used to group together files and/or subdirectories which are related by the purpose they are used for. Each directory may contain both files and other subdirectories. A full filename or pathname is written as a sequence of directory names separated by the / character. All paths start at the system's root, or / directory.
The pathname: /home/ma/b/masc1234/myfile.c
starts with the system's root directory, /, which contains the directory home. The directory home contains the directory ma which contains directory b which contains the home directory of masc1234 which contains the file myfile.c. Each user has a home directory which is named the same as their account name. In the above example, the username is masc1234. A short hand for a users home directory is the tilde (~). The file /home/ma/b/masc1234/myfile.c is the same as ~masc1234/myfile.c.
When you first login, you are placed in your home directory. Unless you change directories (cd), you do not have to enter the pathname to access files in your home directory. You do need to be aware of the path to other files not in your home directory.
Programs, data and text are stored in files identified by unique filenames within a directory. Filenames should be 14 characters or less. Longer filenames are allowed, but are not saved in the system filename cache causing a slight delay in accessing them. You can use almost any character in a filename, but it is best to use only letters, numbers and the period. If you create a filename you can't delete or access, see section 5.2.6 Deleting and Renaming Files. Some filename extensions have a special meaning to UNIX. Among these are the following:
Extensions/File Contents
.c
C language source file .f Fortran 77 language source file .gz Gzipped compressed file .o Object module file from a compiler or assembler .p Pascal language source file .s Assembly language source file .Z Compressed file The following are valid filenames:
a.out, file1.c, program2.p, daniels_file, progdata, .logfile Most commands let you specify more than one file at a time. There is a shorthand to allow you to specify several files. Some characters act as "wild cards" when used as part of a filename. These wild card characters form a pattern that is expanded into filenames as follows:
Character/Function
* Matches any string of characters except slash and period (/.). For example: d*n will match files named dan, drawn, dn, and dfg4n ? Matches any single character in that position. For example: d?ve will match dave, dove, dive and d.ve [list] Matches any character included in the list of characters. A hyphen (-) may be used to specify a range of characters. Example: pro[1,2,g] will match pro1, pro2 and prog. Example: run[1-3] will match run1, run2, and run3 Return to 5.2 Working With Files
5.2.2 The Login Startup File (.login)
The default startup file is named .login. This file sets up the directories to search for commands, the file creation mask, terminal type, key bindings and various other things done when logging in. A standard .login is copied from /usr/local/.login into every new account created. This file can be customized to create command aliases, change the terminal type, editor, pager or prompt. The default login shell is /bin/csh, known as the C shell. See the command man csh for more information on the C shell.A common change is to modify .login to allow the BACKSPACE key to erase characters instead of the DELETE key. This change is made by modifying the stty command line in .login to read:
stty erase `^H' Another change to consider is your terminal type. The terminal type defines how your screen moves its cursor. A VT100 terminal clears a screen quite differently from the way an X Terminal clears a screen. UNIX programs need to know how to address your terminal screen. This is defined by setting term (terminal type) in your .login file. To avoid being asked for terminal type at login, define a permanent terminal type in your .login file. To do this, delete the four lines starting with set noglob and ending with unset noglob. Then insert:
set term=vt100 If you encounter problems with your .login file, you can replace it with the default startup file by entering:
cp /usr/local/.login .login If you are unable to log into your account because your .login file is messed up, login (with permission) to someone else's account (friend, lab assistant, professor) and replace your.login file by entering:
Now test it by logging into your own account.
- rohan% su username
- <--your username replacesusername
- password:
- <--your password
- cd ~username
cp /usr/local/.login .login
exit- <--this will return you to the account you just logged into logout
Return to 5.2 Working With Files
5.2.3 Disk Quotas and /tmp Usage
Every account is created with a disk quota for /home, /tmp and /var/mail file systems. To view your quota type:
quota -v Disk quotas for masc1234 (uid 123):
Filesystem usage quota limit timeleft files quota limit timeleft /home 20 50000 4200 0 0 0 The value for quota is the number of KBytes you're allowed to save indefinitely. The value for limit is the maximum you can temporarily save for up to a week. If you try and save more than your limit, the program writing the file will abort with a write error.
To summarize usage of a directory, type:
du To summarize usage of each file in a directory, type:
ls -aF The "L"ist content"S" (ls) command shows the directory contents with a symbol for various file types appended to the file name: Mark directories with a trailing slash (/), executable files with a trailing asterisk (*), and symbolic links with a trailing "at" sign (@).
More help with the options to the ls command can be found on the ls man page.
Incoming email is saved in the /var/mail file system. New email for your account will be refused if the email exceeds the /var/mail quota. When email is refused, the message is bounced back to the sender with a " Quota Exceeded" error.
The /tmp disk partition can be used by users that need more space for a few hours. The prefered way to use /tmp is to create a directory in /tmp and put your files there. Please delete your files and directories from /tmp as soon as you are finished with them. The /tmp disk is shared among all users and is used by editors and compilers for temporary space. NOTE: The system deletes files and directories from /tmp that are over 24 hours old and when the system reboots.
Return to 5.2 Working With Files
5.2.4 File Protections
The setting of your umask determines the default file protection. Typing umask will show the current setting. The default .login sets it to 077. This creates files that only you can read and write. See maYour home directory is set up with permissions -rwx------ to prevent others from viewing its contents. If you should change the permissions of your home directory be sure and allow yourself access! If you should manage to make your home unreadable for yourself, you will see the following message on login:
No directory! Logging in with home=/ This means you need to fix your home directory's permissions:
rohan% chmod 700 ~username Where 700 makes your directory permissions allow read/write/execute for you.
Return to 5.2 Working With Files
5.2.5 Web Page File Protections
When preparing an account for use as a website, directory and file permissions must be changed so that others can view the files. For most users, the following statements will create the access you desire:
- Use ssh to access the ROHAN account.
- At the main directory, enter chmod 711 . This command provides access to the account. If you place .htm or .html files in the public_html sub-directory, enter chmod 644 *.htm or chmod 644 *.html This provides access to the htm or html files within that directory.
- If you create any directories within the main directory (e.g., public_html) you must enter the directory (e.g., cd public_html) to set the access permissions. When in the directory, enter chmod 711 . and then enter chmod 644 *.* This gives read and execute privilege to all files within that subdirectory.
- Replacing files with the same name to the existing directories will not require resetting the permissions. However, if you create a new directory or create new files, the permissions must be set.
- Confirm that the permissions work by accessing the new website through your web browser of choice.
Return to 5.2 Working With Files
5.2.6 Displaying and Copying Files
The cat command will display a file to your screen. The command cat myfile will display the contents; This is myfile, that I typed in previously. The problem with cat is it copies the entire file at once. With short files this is not a problem, but with longer files the commands more and less provide a screen full at a time. These programs are often called pagers. You can set your preferred pager in your .login file. For example, to use less as the default pager, add the line setenv PAGER less to your .login file. Less allows you to go backwards as well as forwards when viewing a file. See the man pages for more info (e.g. man less)The cp command will copy a file. Example: cp peter john will create a file named john and make a copy of peter in it. The cp command can also copy a list of filenames into a directory.
The tar command provides a way to transfer all the files and subdirectories in a directory. Tar stands for tape archive. The -f option allows a filename to be written instead of a tape. If the hyphen (-) is used for the filename, screen output is used (see 5.2.9 Re-Directing Input and Output for more on output files). The following command will transfer the directory mydir, and all files contained in it, into the directory todir, duplicating and preserving the directory structure:
rohan% tar cf - mydir | ( cd todir; tar xf -) Return to 5.2 Working With Files
5.2.7 Deleting and Renaming Files
The rm command deletes files. There is no command to undelete files in UNIX. If you delete a file, it is gone. Some useful options to rm are:
-i Show each file to you and ask before deleting it. If you type "y" or "yes" the file is deleted -- Allow filenames starting with a hyphen (-) to be deleted. The mv command allows you to rename or move files from one name to another. Example:
rohan% mv red fred The above example renames the file red to the new name of fred.
Return to 5.2 Working With Files
5.2.8 Comparing and Sorting Files
The diff command will compare two files and list the differences.The sort command will not change the contents of the file it sorts. Rather it will list the sorted contents of the file. The sort command has options to specify various fields, sorting methods, and field separators. See man sort for more details.
Return to 5.2 Working With Files
5.2.9 Re-Directing Input and Output
UNIX treats everything as a file, including the terminal keyboard input and screen output. Because of this, it is possible to redirect I/O (input and output) and pipe I/O thru multiple programs.Option/Description
> Redirects the output to a new file. Example: rohan% cat file1 file2 file3 > bigfile
This example creates bigfile and copies the output of cat into it.>> Redirects the output, appending it to the contents of an existing file. Example: rohan% cat /etc/motd >> bigfile
this appends /etc/motd to the end of bigfile, which now contains the contents of file1 file2 file3 and /etc/motd< Redirects the input to a program or command to be from a file instead of the keyboard. Example: rohan% mail coqp0001 < newletter this mails the file newletter to user coqp0001
| Pipes the output of one program into the input of another program. Example: rohan% sort myfile | less this sorts the contents of myfile and displays them with less
Return to 5.2 Working With Files
Return to 5.0 The Solaris 10 Operating System
5.3 Commands
The UNIX operating system has a large number of commands which are used for file processing and manipulation. This section will briefly cover some of the more common programs and commands.
5.3.1 Shells
The commands you type are processed by the shell. The shell reads your commands and then calls a program to execute them. The shell can't do a lot on its own. But the shell is an expert at coordinating other programs. There are several shells used in UNIX. They all understand the same basic commands, but have different additional features. New accounts are given a default shell, bash shell, otherwise known as /bin/bash. Other shells are the Korn shell, /bin/ksh, the Bourne shell, /bin/sh,the C shell, /bin/csh, and the T shell, /bin/tcsh. You can change your shell by the chsh command. Warning: the shells sh, ksh, and bash do not use .login to set up account preferences, they use .profile instead. See the respective man pages for details.Normally you will be talking to the top-level shell, the shell created when you log in. However some programs have commands that create another shell. This happens if you are in the middle of something and suddenly need to do a ls or some other command. When you are in one of these subshells, the exit command will get you back to the program that called the shell.
A command is usually the name of a program followed by arguments. For example, the command rm *.c (which deletes all files ending in .c) is a request to run the program rm. The shell looks in the shell variable named path for the directories to search for the command. The system sets up a basic path for most commands and your .login file adds any additional directories to be searched such as:
set path = ( $path ~/bin . ) A single dot in the above example represents the current directory.
Return to 5.3 Commands
5.3.2 Job Control
The bash and C shells allow you to run and keep track of more than one process at a time. A process is the computer's way of labeling your programs. The shell labels these processes as jobs. A normal command causes the shell to start the program you requested and wait for it to finish. The command can be interrupted by a ^C, but this kills the process. A common way to do more than one thing at a time is to put an ampersand, &, at the end of a command. Suppose you want a list of all your files in your account and don't want to wait for it to finish:
rohan% ls -lR >files & The & tells the shell not to wait for the command to finish. You can now type more commands and forget the ls is still running. This is called running a program in the background.
Another way to run a program in the background is the ^Z command. This stops the current job, but unlike ^C, leaves the job around. The job can be continued later, put in the background, or killed. To continue a stopped job, use the fg command to bring the job in the foreground. To put the job in the background, use the bg command.
To effectively use these commands, you need to know how to refer to a job. Here is the output of the command jobs:
rohan% jobs
[1] Running ls -lR [2] - Stopped mail problems [3] + Stopped vi Here are 2 jobs stopped by ^Z and one running in the background. The jobs can be referred to by job number (%3), job name (%vi), or by default. Some of the commands default to the current job. This is the job with the + next to it. The - is the previous job. The previous job becomes current if the current one finishes. In this example, the commands fg, fg %3, and fg %vi all resume the vi job.
Return to 5.3 Commands
5.3.3 Limits
It is a good idea to set limits on maximum CPU time and disk file size to prevent runaway commands from wasting system resources. The systemwide limits are 4 CPU hours per process and 1024 MB of RAM. The command limit will show the current limits. The limit command is a feature of the bash, csh and tcsh. See their man pages for more information on limits.Return to 5.3 Commands
5.3.4 General Commands
Commands/Description
cat file1 file2 Reads each file or the keyboard if no filename is given and displays each on the terminal screen. The -n option adds line numbers to the screen listing cd newdir Changes the current directory to the directory name given. If no directory name is specified, the current directory is set to your home directory. chmod og+r myfile Changes the protection of the files specified. This example sets myfile to allow all users to have read access. NOTE: If the file doesn't allow read access or any part of the directory path doesn't allow execute access, the file will not be readable. See section 5.2.4 Creating Files and File Protections. clear Clear the screen. NOTE: You must have the correct term type defined for this comand to work. See section 5.2.2 The Start-Up File (.login). cp file1 file2 Makes copies of files. This command can make a copy of a single file or copy a list of files into a directory. This example makes a copy of file1 and names it file2. finger username The finger command, along with a username, lists user information including their "real name" as it is listed in their finger entry. Use chfn to change your finger name which will also change the name on your outgoing Email. kill Terminates a process. This command works with Job Control or with a Process Id Number (PID) reported by the ps command. less A file pager. It allows examination and searching by content of files, forwards and backwards. Less displays one screen of the file at a time when pressing the SPACE bar. lp myfile Prints the file named myfile to the paid printer in the Student Computing Center in LL-200. Additional printers can be specified with the -d printername option. ls The ls command lists information about files or directories. The -l option lists the file permissions, ownership, size and creation date. The -R option recursively searches subdirectories. mkdir mydir Creates a directory. Your umask determines the permissions. mv file1 file2 Rename a file. This examples changes the name of file1 to file2. If file2 exists, it is deleted before file1 is renamed. pwd Prints the working directory. This is the current directory. rm file1 Remove files. The -i option asks before deleting files. Type y or yes to confirm the deletion. rmdir mydir Removes directories if they are empty. Return to 5.3 Commands
Return to 5.0 The Solaris 10 Operating System
5.4 Using the Language Compilers
The ROHAN computer has a number of compilers: cc, c++, clisp, f77 (Fortran), gcc, g++, np (Prolog), pc (Pascal), Tcl, Tk. To compile a program, enter the name of the compiler, any options, and the name of the source file(s). If the compile is successful, the executable version produced by the compiler will be named a.out unless an output file name was given on the command line. The adb, dbx, and gdb debuggers are available.
5.4.1 C
The C compiler is ANSI compliant, but understands non-ANSI C code. The basic syntax of the C compiler is:cc source.c There is also a BSD compatibility compiler (/usr/ucb/cc). If you want to use the BSD C compiler, change your path so that /usr/ucb is first:
set path = (/usr/ucb $path) Unless specified, the compiler will not save any object files. The -c option will create an object file (.o file) that can later be linked against other files. The -o filename option will create an executable named filename given instead of a.out.
For any special functions which need to be called from a system library, use the option -lxx. Where xx is the abbreviation for the library you wish to use. This option must be the last option on the command line or it will not be passed to the linker. If you are using sockets, you need to include -lsocket -lnsl. If using math routines (such as sin or cos), include -lm for the math library.
Return to 5.4 Using the Language Compilers
Return to 5.0 The Solaris 10 Operating System
5.5 Editing Files
When you want to create a new file or change an existing one, you use an editor. An editor is a program that reads in a file, lets you modify it, and then writes out an updated copy of it. The editors we use are full screen editors. This means a piece of your file is displayed on the screen. In order to make changes, move the cursor around until it is pointing to the place you need to make a change. Then using editor commands you delete and/or insert things. The changes show up immediately on the screen. You can also scroll forwards and backwards through your file to display different portions.When you're in an editor you are working with a copy of your file. Changes made do not show up, but are kept in memory until you ask the editor to save the changes. If you make a drastic mistake, you can exit from the editor without saving the changes, leaving the file as it was before.
Editors are different from most commands. In most programs, the commands are designed to be easy to remember and read. But in an editor, most commands are single characters. This greatly reduces the typing needed to make changes. Most commands are not echoed; you instead see the effect of the command. When deleting a word, the word disappears.
5.5.1 Vi
Many users use vi, it is present on almost every UNIX system. This prevents needing to learn another editor if you use a different computer. A good introductory tutorial for vi is the command vilearn. There are several books on using vi (see section 3.3 Reference Books). Here is a very brief intro to using vi:Vi has two modes, insert and command modes. When in insert mode, anything you type is inserted. If the keys echo, you are in insert mode. Press the ESCAPE key to resume command mode. Here are some commands to get you started:
Commands/Description
h,j,k,l Move the cursor left, down, up, and right ^F Move forward a screenful ^B Move back a screenful x Delete the character under the cursor dd Delete the line the cursor is on D Delete the rest of the current line J Join two lines 0 Go to the beginning of the line $ Go to the end of the line 1G Go to the beginning of the file 55G Go to line 55 (so 1G will go to the beginning of the file) G Go to the end of the file o Open up a new line u Undo the last change i Insert text in front of the cursor wq Update the file with changes and exit :q! Exit without making changes to the file Return to 5.5 Editing Files
5.5.2 Emacs
Emacs is generally available on many UNIX systems and is more powerful than vi. Emacs is a lisp interpreter and is extremely extensible. To learn about emacs type the comand teachemacs. In emacs there is no distinction between command mode and insert mode. When you type a normal printable character, it is inserted. The commands are all control characters. To add new text, move the cursor to the right place and start typing. To execute a command, just type it. If you are using X Terminals, emacs will allow you to use the mouse to move the cursor around, and to cut and paste text in your document.
Emacs has some command prefix characters that make up two character commands. The most common ones are the ESCAPE key and ^X. Any character typed after a prefix character forms a command. The more common commands are put on the numeric keypad. The cursor movement keys are on the keypad and are:
8 up
4 6 left right
2 downHere are a few commands to get you started with emacs:
Commands/Description
^V Move forward a screenful ESCAPE v Move back a screenful ^S Search for a specified string; asks for string ^D Delete a character DELETE Delete previous character ^K Kill (delete) the rest of the current line (at the end of the line, join two lines) ^A Go to the beginning of the line ^E Go to the end of the line ESCAPE < Go to the beginning of the file ESCAPE > Go to the end of the file ^O Open up a new line ^Y Put back the most recently deleted line(s) ^X^S Write the changes to the file ^X^C Exit
Return to 5.5 Editing Files
5.5.3 Pico
Pico is a simple editor written for people who don't really want to learn an editor. It is part of the pine mail system, but can be used independently of mail. Pico displays a menu at the bottom of the screen of all commands that can be applied. If you wish to use pico instead of vi in the elm mail system, select the elm options menu from the main menu and replace the editor with:
>pico -t Return to 5.5 Editing Files
Return to 5.0 The Solaris 10 Operating System
Return to Contents