[an error occurred while processing this directive]
Options are usually one or two characters preceeded by a minus sign.
Command-line arguments are often names of files or
directories.
For example, the following command prints the file named
lab1a.C
to the printer named mwah177
(-Pmwah177
option) in a 2-column rotated format
(-2r
option).
enscript -2r -Pmwah177 lab1a.C
command < file1executes command with input from file1,
command > file2executes command with out to file2, and
command < file1 > file2executes command with input from file1 and output to file2.
command1 | command2executes both command1 and command2, but command2 will get its input from the output produced by command1, rather than reading input from the keyboard.
The printenv
command is used to display environment variable
definitions.
If it is given with no arguments then all environmental variables wil be
displayed.
You can also give the command with a single argument, which is
the name of an environmental variable without a dollar sign.
Then the definition of that variable is displayed.
The setenv
command is used to define an environmental variable.
The first argument names the variable.
The second argument is the string value for the variable.
It is a good practice to put the string value in quotes.
This is essential if the string value contains any blanks.
For example, suppose you want to define a variable named INTRO
to have the string value "/home/usra/COURSES/cs1623".
To do this you give the command
setenv INTRO "/home/usra/COURSES/cs1623"Then to check the variable give the command
printenv INTROThis should display the string value without quotes.
If you want to read the file /home/usra/COURSES/cs1623/UNIX
using vi, you would give the command
vi $INTRO/UNIX
!!reexecute the previous command
!patternreexecute the most recent command that matches pattern.
For example, giving the command !v
results in reexecuting the
most recent command that begins with the letter v.
For vi
users this is a way of resuming an edit session on a
file after an interuption.
While you are logged on a UNIX system, there will always be one directory whose contents are readily accessible. This directory is called your current working directory. When you first log on to a UNIX system, your current working directory is a directory that is called your home directory. Each system user has their own home directory.
At first, you will probably keep all of your files in your home directory, which will not have any subdirectories. After you have created a lot of files you will probably want to use subdirectories to organize the files. When you get to this point, you should read about naming UNIX files.
UNIX has a command, mkdir, for creating new directories. If you need to change the structure of your directories, you can use the rmdir command to remove directories and the mv command to move or rename directories.
You can change your current working directory using the cd command. This gives you the capability of navigating through the UNIX file system. You can see what your current working directory is by using the pwd command and list the contents of the current working directory with the ls command. Finally, you can set access permissions on directories with the chmod command.
ls
command.
Then you need to start using subdirectories to
organize your files.
In UNIX, the simple names that you used at first only apply to files that are in your current working directory. For other files, you need to specify the directory that contains the file in addition to its simple name. There are two ways of doing this: absolute path names, and relative path names.
For example, the root directory contains a subdirectory named
usr
, which contains a subdirectory named bin
,
which contains an executable file named vi
.
This is the vi
editor program.
Its absolute path name is /usr/bin/vi
.
The leading forward slash says to begin at the root directory (it is an
absolute pathname).
The usr
says go into the usr
subdirectory.
The bin
says go into the bin
subdirectory.
The vi
says take the file named vi
.
/user
then the relative
path name of the vi
program is bin/vi
.
The relative path name of a file in your current working directory is just
the simple name of the file.
Relative path names do not have to use downward paths.
They can use upward steps with the .. filename abbreviation.
For example, the directory /usr
also contains a subdirectory
named etc
.
If this is your current working directory then the relative pathname of the
vi
file is ../bin/vi
.
. | - | the current working directory |
.. | - | the directory above the current working directory |
~ | - | your home directory |
* | - | matches any string of characters that does not contain a /. |
cp /home/usra/COURSES/cs1623/lab3/* .copies all files from the directory named
/home/usra/COURSES/cs1623/lab3
to your current working
directory.
When the * appears in a command-line argument, the UNIX
command interpreter generates a list of file names with one name for each
file whose name matches the argument.
UNIX environmental variables can also be used
for customized pathname abbreviations.
cd
command changes your current working directory.
If no command-line argument is given, it makes your home directory the new
working directory.
Otherwise, there should be one command-line argument, which is the name of
the the directory that becomes the new working directory.
pwd
command displays the absolute pathname of the current
working directory.
It has no command-line arguments or options.
-l | - | list with more complete file information, including access permissions and the latest modification time |
-F | - | show subdirectories with a trailing slash (/) and executable programs with a trailing asterisk (*) |
-a | - | show hidden files and directories. Normally, files whose name begins with a period are not shown by ls. |
-rw-r--r-- 1 gshute users 13875 Mar 10 13:17 UNIX |\-/\-/\-/ | \----/ \---/ \---/ \----------/ \--/ | | | | | | | | | | t u g o l user group size time stamp nameThe meanings of these fields are:
chmod
command is used to change access permissions on files
and directories.
The first argument specifies the desired permissions and the remaining
arguments name the files and directories.
The first argument can be formed as a sequence of characters containing
either a plus sign for adding permission or a minus sign for removing
permissions.
Letters preceding the sign indicate who is affected by the change.
Letters after the sign indicate what kind of permission is affected.
For the letters preceding the sign use one or more of the following:
u | - | you |
g | - | your group |
o | - | others |
a | - | all (you, your group, and others) |
For the letters after the plus or minus sign use one or more of the following:
r | - | read permission |
w | - | write permission |
x | - | execute permission |
For example, if you want to deny all types of access to files named filea and fileb to others, you would give the following command:
chmod o-rwx filea filebYou can check the permissions on files and directories using the ls command with the -l option.
mkdir
command creates a new directory for each of its
arguments.
The arguments are the names of the new directories.
mv
command moves or renames files or directories.
It has two forms.
To rename a file or directory use the following form:
mv oldName newNamewhere oldName is the name of an existing file or directory and newName is the new name for the file or directory.
To move files or directories to a new location use the following form:
mv fileOrDirectory ... directoryAll arguments except the last name existing files or directories, which are are moved into the directory named by directory. directory must be the name of an existing directory.
rm
command removes files and the rmdir
command removes directories.
For either command you can specify any number of arguments, which are the
names of files or directories that you want to remove.
In order to remove a directory, you must first remove all of its files and
subdirectories.
On most UNIX systems, the rm
command is set up to request
verification prior to removing each file.
more
and less
.
These commands are used for reading files a page (screenful) at a time.
For both of these commands, the name of the files should be given as
command-line arguments.
For example, to read a file named lab1a.C
, give one of the
following commands:
more lab1a.Cor
less lab1a.CAfter the program starts up, the file can be read a page at a time by hitting the space bar. Type q to terminate the program. While the program is running, you can get information on the commands that the program understands by typing a question mark.
In addition, any UNIX editor can be use for browsing files.
javac | - | compiler for the Java language |
cc | - | compiler for the C language |
CC | - | compiler for the C++ language |
f77 | - | compiler for the Fortran language (1977 standard) |
pc | - | compiler for the Pascal language |
gcc | - | compiler for the C language |
g++ | - | compiler for the C++ language |
.java | - | Java |
.c | - | C |
.C, .cc, .cpp, or .cxx | - | C++ |
.f | - | Fortran |
.p or .pas | - | Pascal |
NOTE: The following does not apply to Java programming, which uses a different model of computation and execution.
If a program in any language is contained in a single source code file,
then a UNIX compiler can directly produce an executable file using the
-o
option to specify the name of the executable file.
For example, if you have a C or C++ source code file named
myprog.C
and you want to produce an executable file named
myprog
, then you give one of the following commands:
CC -o myprog myprog.Cor
g++ -o myprog myprog.CUNIX compilers are also designed for separate compilation, where a program is broken up into several files. To do this, first each file is compiled separately to produce a file called an object file, then the object files are linked together to form an executable file. Object files produced by UNIX compilers use the same name as the source code file except the suffix is changed to
.o
.
For example, if a C or C++ language program is split into two files
main.C
and other.C
then it can be compiled into
an executable file named myprog
with the following commands:
g++ -c main.C g++ -c other.C g++ -o myprog main.o other.oThe
-c
option in the first two commands direct the compilers
to produce object files.
The first command produces an object file named main.o
.
The second produces an object file named other.o
.
The third links these object files together to produce an executable file
named myprog
.
cp oldName newNameoldName is the name of the existing file and newName is the name for the new copy.
To copy files to a new location use the following form:
cp file ... directorydirectory must be the name of an existing directory. The remaining arguments name existing files. These files are copied into the directory named by directory, keeping their original names.
cat
command displays files.
The arguments to the cat
command should be names of files.
All of the files are displayed on the screen without pausing.
vi
and emacs
.
Often, there is a third editor: pico
.
Use of these programs is not described here.
man
command.
For example, to get documentation on the ls
command give the
command:
man lsThe quality of documentation given by the
man
command varies
considerably.
mail
and
elm
.
Often, there is a third mail program: pine
.
Use of these programs is not described here.
lpr
command for printing, and some
also use the enscript
command.
For all printing commands, the name of the file to be printed is specified
as a command-line argument.
The printing commands also accept a -P
option to specify which
printer to print on.
For example, to print a file named lab1a.C
using enscript to a
printer named mwah177
you give the following command:
enscript -Pmwah177 lab1a.C
script
command can be used to record a sequence of
UNIX commands and the output that they generate.
It takes one optional command-line argument.
If the argument is given it specifies the name of the file in which the
record will be placed.
If the argument is missing then the record is placed in a file named
typescript
.
As soon as you give the script
command, the program begins
recording characters that you type along with output generated by programs
that you run.
You can terminate the script
program by typing ctrl-D.
You should not run an editor or a text browsing program while the
script
program is running.
Editors and text browsing programs put out a lot of screen control
characters that make the typescript difficult to read.
If you want to display a file and have it captured in the typescript, give
the UNIX command
cat filename
[an error occurred while processing this directive]