|
Using Unix: Intermediate Platform: Unix Level of Difficulty: Intermediate Rutgers Main | OIT Main | NBCS Main | NBCS Documentation Main Documentation NoteAll examples used in this document will be from the rci login machines.The notation <CTRL>d means that you should hold down the control key while typing the indicated character (in this case d). ShellsThe commands that you type to a Unix system are processed by a program called a shell. A shell reads your command and then calls a program to execute it; that is, shells are used to coordinate other programs. There are several different shells available in the Unix environment; all understand the same basic commands, but each has different additional features. The default shell used at Rutgers is the T shell (tcsh). You can view the shells available by typing the command: more /etc/shells The shells currently listed in /etc/shells on rci are:
To change your login shell, issue the command chsh. The computer will then display your current shell and prompt you for your new login shell. Issuing a blank response to this prompt will result in no change to the login shell. Shell VariablesShells have settings that are called shell variables. Those of interest
to most users are TERM, PRINTER, BIN, HOME, EDITOR, and PATH. TERM will
hold the terminal type that the computer thinks you are using. PRINTER
will hold the name of the printer that you want output to go to by default
(see the output of the printers command for printer names). BIN
will hold the printing bin number (if any) that you have set. HOME
holds the absolute path to your home directory. EDITOR holds the
name of your default editor (this will affect command line editing in the
t shell). PATH holds a list of paths to be searched for commands that you
issue. To review your shell variable settings issue the printenv
command. The setenv command is used to alter the shell variables
(see File Access/ProtectionUnix allows you to control access to your files. If you or your start up files do nothing to change the default settings, no one else on the system will be able to read or execute your files. You may protect (or grant access) your files by the individual file or by entire directories. For someone to have access to one of your files, they first must have access to your directory. If you give them access to your directory, you can still restrict access to certain files. Each file has protections for the three different types of users: owner. group, and others. The owner is the user who created the file. Someone can own a file in your directory, but you can always delete any file that is in your directory, even if it is owned by another user. Groups are set up by the system administrator. They represent users who have some common link, such as users in one class or one department. All existing groups can be found in the file /etc/group. Others are those users who do not fall into the owner or group category. When the ls command is used with the options -l and -g the accesses are displayed, as in: drwxr-xr-x 2 jqsmith users 512 Mar 12 12:02 Project1 The first ten characters is the access code (explained below), next comes the number of links to this file/directory (2), then the username of the owner (jqsmith), then the name of the group whose members are affected by the group protections (users), this is followed by the size of the file in kilobytes (512), its last modification date/time (Mar 12 12:02), and finally the name of the file/directory (Project1). The common access code positions represent:
-rwxr-x is a plain file; the owner can read, write and execute it; users in the same group as the owner can read and execute it; and everyone else can only see that the file exists (if given access to the containing directory). The default protection given to new files is set by the umask command. If you want all your files to have the same default protection a umask command should be in your .login file. Protections for existing files and directories can be set or changed using the chmod command. The use of the commands chmod and umask is described on page 4. Directories File Access/ProtectionAs previously mentioned, in order to be able to access a file, a user must have the appropriate permission for the file. In addition she/he must also have read and execute access to the directory that contains the file. Typically access to directories are set up as follows drwxr-xr-x, which translates to: the owner can do anything with the files in this directory, all other users can access files according to the access that they have been granted for each file. For instance, in the r-x above the r allows other users to look at the files in the directory, the x allows them to look into the directory, and since w is missing other users can not create new files in the directory). If you want to have a totally private directory, set the protections to drwx. In this case no one else could look at any files in the directory. If you want members of your group to be able to create files in your directory, you might use drwxrwxr-x.ProcessesPrograms that are run by a shell are known as processes. Processes are affected by control characters: <CTRL>c will interrupt a process, <CTRL>d will exit a process or shell, and <CTRL>z will suspend a process. Multitasking
Normally when the shell is given a command, it executes the command and then the user waits until the command finishes and the computer issues a prompt for the next command. Unix is a multitasking operating system, which means that more than one job can be performed by a user at the same time. When more than one job is running, one runs in the foreground and the rest run in the background. The foreground is where the user interacts through the keyboard and the user must wait while the foreground executes. Background jobs can not accept input from the keyboard and do not make the user wait for their completion before allowing another job to be started. To run an executable file called 'demo', from the current directory, in the background; issue the command
The './' instructs the shell to find the executable file in the current directory; the '&' instructs the shell to put the execution into the background, where it will run unattended until it is finished. The prompt will then appear and another command can be executed. A job being run in the background will stop if it tries to read from the terminal. Input can not be given to a background job so make sure that all input necessary is available to it. Background jobs are allowed to produce output. You can suspend a currently running foreground job by typing a <CTRL>z. This will stop the job's execution and put it into the background. To return the job to the foreground, where it will continue execution, type fg. You can have more than one background job at a time; the fg command will, by default, turn the latest background job into the foreground job. Controlling JobsThe shell keeps a table of current jobs, printed by the jobs command. When a job is started in the background with &, the shell prints a line which looks like: [1] 1234 indicating that the job was started as background job number 1 and has a process id of 1234. There are several ways to refer to jobs in the shell. To refer to a job with job number 1, you can refer to it with %1. Just naming a job brings it to the foreground; therefore, either %1 or fg %1 will bring job 1 into the foreground. Similarly saying %1 & returns job 1 to the background; this also may be done with bg %1. The command jobs has a notation for current and previous background jobs. The current background job is marked with a '+' and the previous jobs with a '-'. %+ starts the current job and %- starts a previous job. When you try to leave the shell while jobs are stopped, you will be warned that you have stopped jobs. If you immediately try to exit the shell again, the shell will not warn you a second time, and the suspended jobs will be terminated. You may use the jobs command to see what those jobs are and if you want to terminate them. You can terminate a background job using the kill command. kill %1 will terminate job number 1 and kill 1234 will kill the job with a process id of 1234. If you try to logout and there are suspended jobs, you will be warned of this and the logout will be aborted. If you immediately try to logout again these jobs will be killed and you will be logged out. If you must start a process that is to continue after you logout, precede the command for that process with the nohup command and be sure you have provided for all of its input and output to go to files. NOTE: abuse of the system via the nohup command will endanger your account privileges. MetacharactersMetacharacters are a group of characters that have special meanings, different shells may have different metacharacters. The following list is some of the metacharacters for the Rutgers default shell: tcsh.
Intermediate Commands: Online Help
Dealing with the File System
Work Environmentdate show the current date and time printenv show your current environment variable settings setenv set environment variables unsetenv unset environment variables Controlling Your Jobs
For More InformationQuestions should be directed to the OIT/NBCS Help Desk (732-445-HELP). You can also send electronic mail to the address help on any OIT system (e.g., help@eden.rutgers.edu or help@rci.rutgers.edu) or post a message to the newsgroup ru.comp.qa.news .
webmaster@nbcs.rutgers.edu
|