UNIX Skills (I)
Sun Yu, 2001
1. Introduction to UNIX
Three parts of UNIX
Good features of UNIX
2. UNIX commands
Login and Logout
"yppasswd" (change password)
wild cards (save typing, make commands
more flexible)
"mkdir directoryname" (create
a directory)
"rmdir directoryname" (remove an empty
directory)
"pwd" (show which directory you are currently
in)
"cd directoryname" (go to the indicated directory)
"ls" (get a list of files in an indicated directory)
"cat filename" (dump a file to the screen)
"more filename", "head",
"tail" (show a file one screen full at
a time, or the specified lines)
"cp source-filename1(2...) destination"
(copy files to an indicated destination)
"mv source-filename destination" (move a file
to a new location; rename a file)
"rm filename(s)" (remove a file(s))
redirection (redirect output of
a command to another file)
pipe (make output of one command input
of another)
"chmod" (change access permission of files)
"finger" (get information on specified users)
"ps", "who",
"kill", "top"
(process control)
"man command" (provide detailed online information
of all commands)
"du", "df", and "diff"
(file system)
"module" (interface to module packages)
"find" (find a file in the system)
"uname" (check what Operating System you are
running on)
"wc -lwc filename" (count the number of lines,
words, and characters in a file)
"file filename" (report file types)
"groups userID" (display a list of the groups
you are a member of)
Other useful commands
3. UNIX's
file system
4. UNIX's
process control
5. Editing
6. Printing
7. Internet
8. X11 Window
System
9. More
10. More UNIX
tutorials & UNIX links
Introduction
UNIX is a powerful operating system that was created in
the late 1960s, in an effort to provide a multi-user,
multitasking
system for use by programmers. The philosophy behind the design of UNIX
was to provide simple, yet powerful utilities that
could be pieced together in a flexible manner to perform a wide
variety of tasks. One good point of UNIX is its "portability",
which means that UNIX of various versions could be run on different computer
platforms such as Sun Sparc, SGI, and Intel x86.
The UNIX operating system comprises three
parts: the kernel, the standard utility programs, and the system
configuration files.
-
The kernel
The kernel is the core of the UNIX operating system. Basically, the
kernel is a large program that is loaded into memory when the machine is
turned on, and it controls the allocation of hardware
resources from that point forward. The kernel knows what hardware
resources are available (like the processor(s), the on-board memory, the
disk drives, network interfaces, etc.), and it has the necessary programs
to talk to all the devices connected to it.
-
The standard utility programs
These programs include simple utilities like cp, which copies files,
and complex utilities, like the shell that allows you to issue commands
to the operating system.
-
The system configuration files
The system configuration files are read by the kernel, and some of
the standard utilities. The UNIX kernel and the utilities are flexible
programs, and certain aspects of their behavior can be controlled by changing
the standard configuration files.
Though UNIX does not seem quite user friendly
as Windows98, UNIX has several good aspects such as it is more efficient
at handling multiple users. Simply speaking, the features of UNIX are:
Multitasking
UNIX is capable of running multiple programs for multiple users simultaneously.
Multi-user
Multiple people can log in one workstation running UNIX to work on
their own files and programs. This is supported because UNIX is a timesharing
system, which means that the processes (a process is an instance
of running a program.) take turns running. Each turn is a called a timeslice.
UNIX determines the sizes of timeslices for each process.
Powerful network ability
In effect, most of the internet "backbone" is run using UNIX servers
of one sort or another. UNIX can be configured to allow users to communicate
effectively with other machines on the network.
For example, users can remotely log in a UNIX workstation. Thus, at
any given time one workstation can be used by multiple users who may be
in different geographical locations.
Another example is file sharing. Unix is able to share files (sources)
with other machines over the network.
UNIX commands
For users familiar with Dos or Windows, the UNIX shell commands seem
cryptic. When logging in to a UNIX system, you are placed in a program
called the shell. A shell is a program that inputs Unix commands from the
keyboard and relays them to the Unix system (the kernel) for execution.
Shells typically include various shortcuts for users to use in stating
their commands, and also a programming feature, in which users can make
programs out of sets of their commands.
*NOTE: different system vendors have different command options on machines.
What happens when a command is typed?
When we type a command,
the shell reads the environment variable $path,
which contains a list of directories containing program files. The shell
looks
through this set of
directories to find the program file for the command. The shell then passes
the true filename to the kernel.
Below are the elaboration
of most commonly used commands that a good UNIX user should be familiar
with.
Login and logout.
-
Login
No matter you are logging in via the network, or doing a console login
(log in the machine in itself), simply type in the username and password.
Note:
commands in UNIX are case sensitive.
Then
you are on your way in UNIX.
-
Logout
-
case 1: you logged in via the network. Exit the shell
by "exit" or "logout".
-
case 2: you logged in from the console. Exit UNIX
by selecting "Log Out" or "Exit FVWM" from the root menu.
What happens when you log in and out?
During
login, when you type your username, getty issues a "password:"
prompt to the monitor. After you type your password, getty calls
login,
which
scans for a matching entry in the file /etc/passwd. If a match is
made, login proceeds to take you to your home directory and then passes
control
to
a session startup program; both the username and password are specified
by the entry in /etc/passwd.
(When
you use a Bourne shell) From here, the shell program reads the files /etc/profile
and .profile, which set up the system-wide and user-specific environment
criteria. At this point,
the
shell issues a command prompt such as $.
When
the shell is terminated, the kernel returns control to the init program,
which restarts the login process. Termination can happen in one of two
ways:
with the exit command or when the kernel issues a kill command to
the shell process. At termination, the kernel recovers all resources used
by
the
user and the shell program.
-
"yppasswd" - change password. (Refer
to Kaszeta's document on "Secure Passwords"
on page 15)
-
"mkdir directoryname" -
create a directory.
-
"rmdir directoryname" - remove a directory
(Note: the directory must be
empty.). Alternatively, you can use "rm -r directorynaem".
-
"pwd" - show which directory you are currently
in.
-
Wild cards. These will save you a lot of
typing, and they make the commands more flexible. There are two wild-card
characters in Unix: '*' and `?'.
`*' - match with any string of characters. For example,
"rm *.c"
deletes all files in the current directory whose names end with `.c'.
`?' - match with any single character. For example,
"rm x?b.c"
deletes all files whose names consisted of five characters, the first of
which was `x' and the last three of which were `b.c'. The files x3b.c
and xrb.c would be deleted, while the file xuvb.c would not.
In addition,
'[0-9]' - match character from `0' through `9'
'[a-z]' - match character from `a' through `z'
For instance,
"rm test[1-3].c"
removes test1.c, test2.c and test3.c but not test4.c.
-
"cd directoryname" - go to the indicated
directory.
-
"cd" - go to your home directory. When you first log in to
a UNIX system, you are located in your home directory. Refer to the file
and directory system of UNIX part to get a full understanding. Type
"cd", you will be automatically taken to your home directory no matter
where you are now at.
-
"cd .." - go to the directory that is one level above the
current directory. ".." stands
for the directory one level above the current directory.
-
Other important symbols for "cd" are: "~"
stands for your home directory, "."
for the current directory, and "/"
for the root directory (the very top of the file
system).
-
Sometimes, you have a directory's name like pro-e model where
there is a space in the directory's name. This often happens when you transfer
directories of such type from Windows to UNIX. When use "cd"
to go into the directory, use "cd pro-e/ model" with a back
slash followed by a space.
-
"ls directoryname" - get a list of files
in the indicated directory.
-
"ls -a directoryname" - show all the files in the indicated
directory, including hidden files ("Dot" files). (Refer to Kaszeta's document
on "dot files" on page 14)
e.g."ls -a ~/ftp"
shows you the files that are in the
subdirectory ftp(ftp is a subdirectory of your home directory.), including
hidden files.
-
"ls -l" - show files in long format, including file permission
(each file is assigned access permission, refer to the command "chmod"for
detailed information.), owner of file, creation date, and filename.
-
"ls -s" - display the sizes of files and directories in blocks
that equals 512 bytes or half a kilobyte. Note the difference from "ls
–l" that displays the sizes of files and directories in bytes.
-
"ls -F" - show which files are executable (their names will
be appended with asterisks), and which are subdirectories (their names
will be appended with slashes).
Note: The options such as the
above "-a", "-l", and "-F" can
be used in combination. For example:
-
"ls -sF" - list files in standard format with a number to
the left of the filename. This number is the size of the file in blocks
(1 block = 512 bytes). The "F" option allows directories to be distinguished
from files in that they appear with a slash (/) at the end of their names.
-
"cat filename" - dump a file to
the screen; "cat" command also can type out more than one
file to the screen, for example,
"cat filename1 filename2"
shows you the content of both files on the screen. Actually "cat"
is the abbreviation of the word 'concatenate'.
-
"more filename" - similar to
"cat"
command in dumping a file to the screen, but dissimilar in that it allows
you to page through a file, scrolling down through a file one screen full
at a time. Therefore, it is better when a file is longer than the size
of the window. For example,
"more *.txt"
shows the content of all the .txt files. Press space-bar to see the next
page; press 'q' to quit reading; press return to see the next line."more
file1 file2" can display the contents of multiples files sequentially.
In addition, there are 3 commands related to the "more"
command.
-
"less filename" - similar to "more", but with additional
functionality. "man less" for more information.
-
"head -n filename" - show the first n lines of a file.
-
"tail -n filename" - show the last n lines of a file.
-
"cp source-filename1 (souce-filename2) destination"
- copy files to an indicated destination. For example,
"cp test1.txt ~/ftp"
copies the file test1.txt in the current directory to the subdirectory
ftp of your home directory.
"cp test1.txt new.txt"
makes a copy of test1.txt, and name the newly created file new.txt. For
multiple file copying, the destination part in the "cp"
command has to be a directory rather than a file. For example,
"copy *.c ~/ftp".
Two useful options:
-
"cp -i source-filename destination"
Before copying files, this command confirms overwrites.
-
"cp -r directory1 directory2"
copies directory1 and name it directory2.
-
"mv -i source-filename destination" - two
functions: 1. move a file to another location (directory); 2. rename a
file to a new name. For example,
"mv -i ./sun.txt ~/ftp"
moves the file sun.txt in the current directory to the subdirectory ftp
of your home directory. The "-i" option prompts you for confirmation if
the file sun.txt already exists in the ftp
folder. Another example is
"mv sun.txt sun_new.txt"
that changes the name sun.txt into sun_new.txt.
"mv -i oldDirecotryName newDirectoryName" can either
rename a folder or move a folder into another folder.
-
"rm filename(s)" - remove a file(s).
"rm -i filename(s)"
is to have "rm" ask you about each file in case you delete
something that you do not mean to.
"rm -r directoryname"
can work as "rmdir" to remove a directory.
Two useful options:
-
"rm -i filename(s)"
Before deleting files, this command confirms removal."i" is the inquiry
mode.
-
"rm -r directory"
Recursively remove a directory and its contents.
-
Redirection. Sometimes you will find it
useful to save the output of a command. You can do this by redirecting
the output to a file. For example,
"ls > y"
send the output of the "ls" command to a file y, instead
of to the screen.
By default, a command treats your terminal as the standard input file
from which to read in information. Meanwhile, your terminal is also treated
as the standard output file to which information is sent from the command.
Redirection can change this default setup. To redirect the standard
input for a command use '<' followed by the name of the input file.
For example,
"mail somebody@hotmail.com < sun.txt"
mails the contents of sun.txt to the indicated E-mail address. Similarly,
"sun.out > store"
redirects the standard output of sun.out to the file store. If you do "more
store", the result of sun.out will show up.
Using redirection, we can use "cat > message.txt" to
output its standard input from keyboard to create a file message.txt.
This is useful to create a short text file.
In sum,
-
">" - output redirection (create new, overwrites existing
file).
-
">>" - output redirection (append).
For example, "ls >> sun.out" redirects the output from
the "ls" command to the end of the file sun.out.
-
"<" - input redirection from file.
-
"<<" - input redirection from script.
-
Pipes. Often it is useful to pipe the output
of one command as input to another command. For example, you find the output
of "ls" to be very long, zooming by on the screen before
you have had a chance to read all of it. One solution to this problem would
be to send the output to a file and then view the file as your leisure,
but an easier, more direct method would be to pipe the output of "ls"
into "more", i.e.
"ls | more"
which would allow you to see the output of ls one screen
at a time. You would hit the space bar whenever you are
ready to go to the next screen. Another example is
"more sun.txt | grep search-string"
which output the results of sun.txt to "grep". "grep"
command
finds all lines within the input file sun.txt containing the search-string,
and prints these line out. Of course you can redirect the printed out results
to a file instead of display the results on the screen.
Two more pipe example, "ls | wc -w" counts the number
of files in the current directory; "who | wc -w" check the
number of users on the system.
-
"chmod" - change access permission of
files. Refer to the file and directory system
of UNIX below.
-
"diff file1 file2"- compare the contents
of file1 and file2 on a line-by-line basis.
"diff directory1 directory2" - compare the contents of
directory1 and directory2.
-
"finger" - return information about
users on the system.
They may or may not be logged in. "finger" by itself
returns the list of currently logged in users.
"finger" followed by a username or an e-mail -style address,
for example,
"finger sunyu@umn.edu"
will return information about the user sunyu, the last time they logged
into the system where you are fingering them, their full name, whether
or not they have unread mail and, finally, the contents of two files they
may have created: .plan and .project
Process control commands, such as "who",
"ps", "top", "kill" and more.
-
"man command" - provide detailed online
information of all commands.
Type
"man command"
which provides a detailed description of a specified UNIX command. For
example,
"man ls"
lists all the usage, and options pertaining to "ls". Also, you can use
"man man"
to find more about the "man" command.
-
"find ~ -name filename" - find the file
through the home directory.
"find / -name filename" - find the file on the whole
system.
"find ~ -user yus" - find and display the files owned
by the user "yus".
"find ~ -group adv_microsys" - find and display the files
owned by the group "adv_microsys".
"find ~ -mtime -4" - find and display all the files that
have been modified in the last 4 days.
"find ~ -mtime +3" - find and display all the files that
have not been modified in the last 3 days.
"find /etc -type d" - find and display all the directories
in /etc.
"find /etc -type l" - find and display all symbolic linked
files in /etc.
"find ~ -size +1000000c" - find all files in the home
directory that are OVER ("+") 1Mb; "c" indicates the size
is in BYTE.
"find ~ -size 100c" - find files that are exactly 100
bytes.
"find ~ -size +10" - find files that are over 10 blocks
( 1 block = 512 bytes).
More "find" options such as "cpio", and "xargs", refer
to the man page.
-
"uname" - return the Operating System
type that you are running on.
-
"wc -lwc filename" - count the number of
lines, words, and characters. "-l" counts lines; "-w" words defined by
a sequence of characters surrounded by tabs, and spaces; "-c" characters.
-
"file filename" reports the file type.
-
"groups userID" displays a list of all
of the groups that you are a member of. The only way to create a new group
is to ask the system administrator to add it.
-
"uniq -c filename" displays the input
file with all lines by only one occurrence (but not delete the lines).
The "-c" option causes each line to be preceded by the number of occurrence.
-
"sort filename" - sort a file into ascending
order; the order is based on the characters' ASCII values that can be listed
by "man ascii";
"sort -r filename" - sort a file into descending order;
"sort +0 -1 filename" - sort first field only, specifying
the starting field to be 0 and ending 1;
"sort +0 -1 -bM filename" - sort first field only; "-b"
option ignores leading spaces; and "-M" sorts the field in
order by month.
-
"su username" - to create a temporary shell
with "username"
logging in. This is useful when a different user
does something quick in his own account without having to have the current
user logged out. If no username is specified, "su" assumes
that "su root" is specified.
-
"ln file_to_be_linked label_file" - to create
a hard link for a file. In a sense, now we have two copies of the file.
Use "ls -l", the hard link count can be found. When changes
are made to either file_to_be_linked or to label_file, both files are changed.
Removing one file does not remove the other.
"ln -s file_to_be_linked label_file" - to create a soft
link (symbolic link). This could span file systems. Use "ls -a",
you can find the label_file appended with @. We do not have two copies
of the original file. When changes are made to the label file, we are actually
changing the real file. If the real file is removed, the label file is
empty.
-
"biff" - instant mail notification. "biff"
shows us if this utility is enabled. "biff y" enables it, and "biff n"
disables it.
-
"crypt keystring <sunyu.txt> sunyu.crypt"
creates a encrypted file sunyu.crypt from the file sunyu.txt (the file
sunyu.txt is not removed). "keystring" is the key for decoding. To decode
the file sunyu.crypt, use "crypt keystring <sunyu.crypt> sunyu.txt."
(Refer to Kaszeta's document on "UNIX
command table" on page 13)
File system
-
Structure
All the stored information on a UNIX computer is kept in a file
system. Any time you interact with the UNIX shell, the shell considers
you to be located somewhere within a file system. Although it may seem
strange to be "located" somewhere in a computer's file system, the concept
is not so different from real life. After all, you can't just be,
you have to be somewhere. The place in the file system tree where
you are located is called the current working directory.
The UNIX file system is hierarchical (resembling a tree structure).
The tree is anchored at a place called the root, designated by a slash
"/".
Every item in the UNIX file system tree is either a file, or a directory.
A directory is like a file folder. A directory can contain files, and other
directories. A directory contained within another is called the child
of the other. A directory in the file system tree may have many children,
but it can only have one parent. A file can hold information, but cannot
contain other files, or directories.
To describe a specific location in the file system hierarchy, you must
specify a "path." The path to a location can be defined as an absolute
path from the root anchor point, or as a relative path, starting
from the current location. When specifying a path, you simply trace a route
through the file system tree, listing the sequence of directories you pass
through as you go from one point to another. Each directory listed in the
sequence is separated by a slash(/). UNIX provides the shorthand notation
of "." to refer to the current location, and ".."
to refer to the parent directory.
The first few levels of the hierarchical tree are illustrated
below:
/
|
---------------------
/ | | | \
etc. bin usr tmp dev
| |
------ --------
/ \ / \
ls ... csh ucb ... lib
Your own files form a subtree of this tree. Usually the user files are
subdirectories of a directory named `home' within `usr'; if we had users
Sun and Jim, for example, Sun's home directory would be /usr/home/sun,
and all his files would be within that subtree, and the analogous statement
would hold for Jim.
Let us familiarize ourselves with an example. Suppose Sun's directory
looks like this:
Sun
|
----------------------
/ | | | \
work course ECE program ME
| |
----- --------
/ \ |
Files: VLSI VHDL control
File names can be given either in relative terms, or with full path names.
Look at the file `VLSI' above. If we are in the directory 'course', we
can refer to this file as simply
VLSI
If we are in the directory above, i.e. the one named `Sun',
then we must write
course/VLSI
If we are in the directory 'program', we can write either
../course/VLSI
or
~/course/VLSI
If we are not in any of Sun's directories, we can write
~Sun/course/VLSI or simply ~/course/VLSI
Alternatively, in any case, the full path name will work:
/usr/home/Sun/course/VLSI
-
File types
There are four types of files in the Unix file system.
-
Ordinary Files
An ordinary file may contain text, a program, or other data. It can
be either an ASCII file, with each of its bytes being in the numerical
range 0 to 127, i.e. in the 7-bit range, or a binary file, whose bytes
can be of all possible values 0 to 255, in the 8-bit range.
-
Directory Files
Suppose that in the directory x I have a, b and c, and that b is a
directory, containing files u and v. Then b can be viewed not only as a
directory, containing further files, but also as a file itself. The file
b consists of information about the directory b; i.e. the file b has information
stating that the directory b has files u and v, how large they are, when
they were last modified, etc.
-
Device Files
In Unix, physical devices (printers, terminals etc.) are represented
as ``files.'' This seems odd at first, but it really makes sense: This
way, the same read() and write() functions used to read and write real
files can also be used to read from and write to these devices.
-
Link Files
Suppose we have a file X, and type
"ln X Y"
If we then run
"ls",
it will appear that a new file, Y, has been created, as a copy of X, as
if we had typed
"cp X Y"
However, the difference is the cp does create a new file, while ln merely
gives an alternate name to an old file. If we make Y using ln, then Y is
merely a new name for the same physical file X.
Naming UNIX files, it is legal to contain all numbers, all letters (both
upper case and lower case), “. dot”, “_ underscore”,
“- dash”. For example, 1.2.3 is a legal filename. Note that
symbols such as # and $ are not allowed.
-
File and directory permissions
UNIX supports access control. Every file and directory has associated
with it ownership, and access permissions. Furthermore, one is able to
specify those to whom the permissions apply.
Permissions are defined as read, write, and execute.
The read, write, and execute permissions are referred to as r,
w,
and x, respectively. Those to whom the permissions apply
are the user who owns the file, those who are in the same group as the
owner, and all others. UNIX allows users to be placed in groups, so that
the control of access is made simpler for administrators.The user,
group,
and others. Permissions are referred to as u,
g,
and o, respectively.
user(u)
group(g) others(o)
r w x
r w x
r w x
The meaning of file and directory permissions are:
-
Read permission
For a file, having read permission allows you to view the contents
of the file. For a directory, having read permission allows you to list
the directory's contents.
-
Write permission
For a file, write permission allows you to modify the contents of the
file. For a directory, write permission allows you to alter the contents
of the directory, i.e., to add or delete files.
-
Execute permission
For a file, execute permission allows you to run the file, if it is
an executable program, or script. Note that file execute permission is
irrelevant for non executable files. For a directory, execute permission
allows you to "cd" to the directory, and make it your current
working directory.
-
Viewing permissions
To see the permissions on a file, use the "ls -l" command.
For example, "ls -l /etc/passwd" to view the information
on the system password database. The output should look similar to this:
-rw-r--r-- 1 root sys 414 Apr 17 2000
/etc/passwd
The first 10 characters describe the access permissions. They can be divided
into:
-|rw-|r--|r--
-
The first dash indicates the type of file (d for directory,
s
for special file, - for a regular file).
-
"d" - directory;
-
"l" - symbolic link ( a pointer to another file);
-
"s" - domain socket;
-
"b" - special block file;
-
"c" - character special file;
-
"p" - named pipe file;
-
"-" - a normal file.
-
The next three characters ("rw-") describe the permissions
of the owner of the file: read and write, but no execute.
-
The next three characters ("r--") describe the permissions
for those in the same group as the owner: read, no write, no execute.
-
The next three characters ("r--") describe the permissions
for all others: read, no write, no execute.
-
The "1" after is the number of hard links the file has.
-
"414" is in bytes, not in kilobytes.
-
Setting permissions
UNIX allows you to set the permissions on files that you own. The command
to change the file permission mode is "chmod". To set file
permissions, you may use to the "rwx" notation to specify
the type of permissions, and the "ugo" notation to specify
those the permissions apply to.
user(u) group(g)
others(o)
r w x
r w x
r w x
To define the kind of change you want to make to the permissions, use the
plus sign (+) to add a permission, the minus sign (-)
to remove a permission, and the equal sign (=) to set a permission directly.
For example,
"chmod g=r-- ~/.shrc"
to change the file permissions on the file .shrc, in your home directory.
Specifically, you are specifying group read access ,with no write nor execute
access. The command
"chmod go=r-- ~/.shrc"
would change the permissions on the .shrc file in your home directory so
that group and others have read permission only. More examples,
"chmod u+x file1"
gives you execute permission for file1;
"chmod a+r file2"
gives everyone read access to file2;
"chmod a-r file3"
removes read access to all users for file3.
"u" - user permissions;
"g" - group permissions;
"o" - other permissions;
"a" - all (user, group, and others).
Instead of using u+x, a+r, a-r shown
above, we can conveniently use corresponding pre-defined numbers.
0 nothing
1 execute only
2 write only
3 write and execute (1+2)
4 read only
5 read and execute (4+1)
6 read and write (4+2)
7 read, write and execute (4+2+1)
For example,
"chmod 777 file1" makes file1:
user group others
rwx rwx
rwx
"chmod 700 file1" makes file1:
user group others
rwx ---
---
After execute "chmod 000 sunyu.txt," if you run "more sunyu.txt," the
file sunyu.txt cannot be displayed for the reason of 000 in the command
that you should understand at this point.
When dealing with directories,
"r" - can list the files in the directory;
"w" - can create or delete files in the directory;
"x" - can search or use "cd" into the directory.
Permissions set on a directory will override whatever permissions set
on files in the directory.
-
More commands
-
"du" - display the sizes in kilobytes of all files in the
specified directory, and the total of all those sizes; if no directory
is specified, the current directory is assumed.
-
"df" - display the amount of unused space left in your disk
systems.
-
"chown owner file_name" - change a file's owner. For example,
"chown
paul sunyu_file" gives the ownership of the file to another user
paul.
Talk to the administrator to get it back.
-
"chgrp group file_name" - change a file's group. For example,
"groups"
to show what groups you are in. Then, "chgrp group1 sunyu_file"
makes the file belong to group1.
-
"umask" - when you log in to the system, a command called
umask sets your default file creation mode. The system administrator should
have set a reasonable value.
-
"diff" - display line-by-line differences between two ASCII
files. If for example, you have two versions of a C source file but don't
remember how the new version differs from the old one, you could type
"diff oldprog.c newprog.c"
Process control
-
Unix processes
A process is an instance of running a program. There can be more than
one process running even with only person executing the program.
Keep in mind that all Unix commands, for example, "cc"
and "mail" are programs, and thus contribute processes to
the system when they are running. If 10 users are running "mail"
right now, that will be 10 processes. At any given time, a typical Unix
system will have many active processes, some of which were set up when
the machine was first powered up.
Every time you issue a command, Unix starts a new process, and suspends
the current process (the C-shell) until the new process completes (except
in the case of background processes, to be discussed later).
Unix identifies every process by a Process Identification Number (pid)
which is assigned when the process is initiated. When we want to perform
an operation on a process, we usually refer to it by its pid.
Unix is a timesharing system, which means that the processes take turns
running. Each turn is a called a timeslice; on most systems this
is set at much less than one second. The reason this turns-taking approach
is used is fairness: We don't want a 2-second job to have to wait for a
5-hour job to finish, which is what would happen if a job had the CPU to
itself until it completed.
-
Determining status
of current processes
To check on running jobs, we can use:
-
"ps" - list all processes of yours and associated with your
terminal. Some useful options are:
-
"ps -a" - get a list of all processes on the machine.
-
"ps -u username" - get a list of the username's own processes.
-
"ps -ef" - get a list of all users' processes.
For example, "ps" will produce the following output
PID TTY TIME
CMD
3891 pts/14 0:50 emacs
3321 pts/14 0:06
tcsh
where PID stands for Process Identification; TTY information gives terminal
names, which you can see by "who" command; TIME is the amount of CPU time
the process has acquired so far; and CMD is the name of the command that
is issued the process.
-
"top" - similar to "ps", only shows the processes
using the most CPU on the machine.
-
Try this example to see if you understand how "ps" functions.
Command "sleep 10" asks the system to sleep for 10 seconds.
To cancel a process, type Control-c.
To suspend a process (allowing it to be activated again), type Control-z.
Using the command "fg" can always bring a suspended process
back into foreground.
-
Foreground and background
processes
Suppose we want to execute a command but do not want to wait for its
completion, i.e. we want to be able to issue other commands in the mean
time. We can do this by specifying that the command be executed in the
background.
There are two ways to do this - put jobs in the background.
-
Append an ampersand (`&') to the end of the command. For example, suppose
you have a very large program, which will take a long time to compile.
We could give the command
"cc hugeprog.c &"
which will execute the compilation while allowing you to submit other commands
for execution while the compile is running. Another example is when we
start a window during a X session. We would like to start the window from
an existing window, but we still want to be able to use the original window.
Then we execute the command
"xterm &"
This will start a new window, and allow us to keep using the current
window.
-
Use Control-z; when suspend it, note the jobid (the
number in square brackets); use another command, "bg %jobid",
to move the process to the background. For example, suppose we started
our long-running compilation, "cc hugeprog.c" but we forget to append the
ampersand. We can type Control-z to suspend/stop the job, and then
type bg to resume the job in the background, allowing us
to submit other commands while the compilation takes place. Unix will tell
us when the background job has completed, with a statement like
[1] Done
cc hugeprog.c
Note: If you log out, whatever background
processes you have running at the time will not be killed; they will continue
to run.
-
Terminating a process
"kill PID(process ID)" - terminate a process. We can
find its PID by using the command "ps". "kill PID"
gives the application a chance to exit gracefully, for example, clean up
temp files. If "kill PID" does not work, you can always use
"kill -9 PID"
to kill a process in a forceful manner.
If the process is in the foreground, though, the easiest way to kill
it is to simply type Control-c.
In sum,
-
Control-c - cancel a process (job).
-
Control-s - pause a process (job); Control-q - resume a process
(job).
-
Control-z - suspend a process.
-
"jobs" - get a list of background jobs.
-
"fg" - bring a background job into foreground.
-
"bg" - bring a foreground job into background.
-
& - appended to a command, place the job into background.
-
"ps" - check processes.
-
"kill" - terminate a process.
-
Run programs when you logged
out
When you exit a shell, all the background processes in the shell exit.
To make a program(large computation) able to run even after you log out.
Suppose sun.out is your executable file, then the following command may
be used to achieve the goal - continue running even when log out.
"nohup sun.out &"
You can one example "nohup sleep 1000 &", then exit.
Re-log in, "ps -ef" to find the process "sleep 1000."
To ensure that all users make efficient use of limited resources, all
background jobs submitted should be niced. Nicing a job reduces its priority
level and preferentially allocates the CPU to interactive processes. Good
thing is that in the absence of any other interactive or un-niced jobs,
maximum CPU is allocated to the niced job.
"nice +n nohup sun.out &"
where n can be any number between 1 to 19. Higher the value of n, the lower
the priority for the job.
If you want to find more information on the command "nice",
you should 'man csh' or 'man tcsh' instead of 'man nice'. This happens
because the system '/usr/bin/nice' command uses a different syntax.
Additionally,, if you already have jobs running (either in the foreground
or in the background), you can 'renice' them with
"renice +n pid"
where "pid" is the process id of the process obtained from the "ps"
command.
Emacs
-
General features of the
Emacs editor
Emacs is a visual editor. That means that you have a representation
of your entire document on your screen, and you can move around freely,
editing any part of the document you wish.
Emacs uses Control and Esc characters to distinguish editor
commands from text to be inserted in the buffer. In this document, the
notation "Control-x" means to hold down the Control key,
and type the letter x. You don't need to capitalize the x. "Esc
-x" means to press the Esc key down, release it, and then type
x.
-
Working with buffers
When you edit a file in emacs, you're not really editing the file itself,
as it sits out on a disk somewhere. Instead, emacs makes a copy of the
file, and stores the copy in a part of memory(RAM) called a buffer. All
the changes you make to the file are applied to the buffer. When you save
the file, emacs writes the contents of the buffer to the disk. Because
the buffer exists in memory(RAM), you should use the save command often,
flushing your current buffer to disk.
-
Basic operations in emacs
Type emacs & at the Unix prompt. The editor Emacs
will be activated. If you want emacs to start with a file already loaded
into a buffer, type emacs filename &.
The display in emacs is divided into three basic areas. The top area
is called the text window. The text window takes up most of the screen,
and is where the document being edited appears. At the bottom of the text
window, there is a single mode line. The mode line gives information about
the document, and about the emacs session. The bottom line of the emacs
display is called the minibuffer. The minibuffer holds space for
commands that you give to emacs, and displays status information.
-
To create a new file, go to the File menu and select Open
File (type Control-x, and then type Control-f) and
type the filename you want.
-
To open an already existing file, do the same as the above except use the
name of the file you want to open.
-
To save a file, go to File menu and select Save Buffer
(type Control-x, and then type Control-s).
-
To save a file as a different file, go to File menu and Save
Buffer As (type Control-x, and then type Control-w).
-
To close a file, select Kill Buffer (type Control-x,
and then type k) from the File menu.
-
To get help, type Control-h. Control-h t will start the Emacs
tutorial.
-
To quit Emacs, select Exit Emacs (type Control-x,
and then type Control-c) from the File menu.
Note: Control-g - If
you typed the wrong thing, you can type this to kill/undo/abort the current
command .
Copy, cut and past
-
To select a region, place the cursor at one end of the region and press
Control-spacebar.
This sets a mark. Then, move the cursor to the other end of the region.
The text between the mark and the cursor defines the region.
-
To copy a selected region, type ESC-w.
-
To cut a region of text, and place it in the kill buffer, type Control-w.
-
To paste, type Control-y.
Vi (Visual Editor)
There are two modes: command mode and text-entry
mode. To enter text-entry mode from command mode, press one of the
keys listed in the following table.
|
Key
|
Action
|
|
i
|
Text is inserted before the cursor.
|
|
I
|
Text is inserted at the beginning of the current line.
|
|
a
|
Text is added after the cursor.
|
|
A
|
Text is added at the end of the current line.
|
|
o
|
Text is added after the current line.
|
|
O
|
Text is inserted before the current line.
|
|
R
|
Text is replaced (overwritten).
|
To switch from the text-entry mode to the command mode, press the ESC
key at any time.
Range expression in Vi:
"$"- denote the line number of the last line in the file;
"." - denote the line number of the currently containing the cursor.
For example, :1,5d<enter> deletes line 1 to 3; :.,.+3d<enter>
delete the current line and the 3 lines after it. The following table are
some other examples of commands for line ranges.
|
Range
|
Selects
|
|
1,$
|
all of the lines in the line
|
|
1,.
|
all of the lines from the first line (included) to the current
line (included)
|
|
.,$
|
all of the lines from the current line (included) to the
last line (included)
|
|
.-2
|
the line that is two lines above the current line
|
Cursor movement:
Besides using the cursor keys, there are the following commands available.
|
To line n
|
:n<enter>
|
|
To the start of a line
|
^
|
|
To the end of a line
|
$
|
|
Back one word
|
the "b" key
|
|
Forward one word
|
the "w" key
|
|
Scroll down a half screen
|
Control-d
|
|
Scroll up a half screen
|
Control-u
|
|
Forward one screen
|
Control-f
|
|
Backward one screen
|
Control-b
|
Deleting text:
|
To delete:
|
Key operation
|
|
a character
|
position the cursor over the character, press "x"
|
|
a word
|
position the cursor over the character, press "w"
|
|
a line
|
position the cursor anywhere on the line, press "dd"
|
|
from the current position to the end of the current line
|
press "D"
|
|
block of lines
|
:<range>d<enter>
|
Copying and pasting can be done by using the mouse.
Replacing text:
|
To replace:
|
Key operation
|
|
a character
|
position the cursor over the character, press "r", then type the
replacement
|
|
a word
|
position the cursor at the start of the word, press "cw", type
the replacement, then press "ESC" key
|
|
a line
|
position the cursor anywhere on the line, press "cc", then type
the replacement, then press "ESC" key
|
Searching:
/string/<enter> to search forward from the current position for the
string;
?string?<enter> to search backward from the current position for the
string.
For example, :1<enter> to move to the first line, then /sunyu/<enter>
to search for the string "sunyu".
Searching and replacing:
:<range>s/string_old/string_new/<enter> to replace the first occurrence
of string_old of each line with string_new;
:<range>s/string_old/string_new/g<enter> to replace every occurrence
of string_old on each line with string_new (global replace).
For example, :1,$s/sunyu/sunyu_new/g<enter> to replace all sunyu with
sunyu_new.
Saving and loading files:
| save file as <filename> |
:w <filename><enter> |
| save file with current name |
:w<enter> |
| save certain lines to another file filename |
:<range> w <filename><enter> |
| read in contents of another file at current position |
:r <filename><enter> |
Quitting Vi:
:q<enter> - quit Vi if the file is saved;
:q!<enter> - quit Vi and discard the unsaved data;
:!<command><enter> - enable users to execute shell commands without
exitting Vi, after execute the command, return to Vi.
More editors
Printing
-
"lpr -P printername file1 file2 ..." - print files to the
specified printer.
-
"lpq -P printername" - check the printing queue for the specified
printer.
-
"lprm -P printername jobid" - cancel a printing job. The
jobid can be found when using "lpq" command.
-
"mpage -2 -P printername file" - reformat the file so that
2 pages can be shrinked down and printed on 1 page.
This command can print both text files and .ps files.
-
"nenscript -2rG -P printername file" - similar to "mpage",
besides place a header on the page. This command can print text files.
Note: To print 4 pages in one page, change 2 to 4 in the above "mapge"
and "nenscript" commands.
For example,
"mpage -2X (-h SunYu) -b Letter -P me10a sun.txt/sun.ps"
"nenscript -2rG -P me10a sun.txt"
-
"ghostview file.ps" - Preview the file to be printed.
Internet
-
E-mail
When mail messages are sent to
you, it is stored in a file called "/var/mail/<username>."
-
"mail sunyu@umn.edu" - good for sending short messages.
Type Control-d, the message is sent away. If you like to send
the content of an existing file to somebody, you can use the redirection
operators:
"mail sunyu@umn.edu < sunyu.txt"
"mail" enables you to read messages. "mail -h"
shows the headers of messages.
"q" exits the mail utility. To find out more options,
type "mail" only. Then issue the command "ls"
within the mail utility. For example, "h a" shows the headers
of all messages. "r" replies to one message.
-
"pine"
PINE is a full-screen interactive mailer, developed at UW, that is
very straightforward to use. It offers on-screen menus and help. This help-file
provides basic directions for using Pine. Other advanced features that
can be learned through Pine's "Help" menu.
-
Start Pine:
Type: pine
-
Read Email:
Type: i
-
Delete a message:
Type: d
-
Postpone a Message
Press: CTRL-O.
The mail message you are currently working on will be closed temporarily
and saved for later editing. You will be returned to the Main Menu. Note:
Only one message can be postponed at a time.
-
Quit Pine
Type: q
-
"elm"
-
"mailx"
-
forward email:
For example, if you want email messages addressed to usrname@me.umn.edu
to be delivered to usrname@hotmail.com, you can do this by creating a file
in your home directory with the file name .forward, and within this
file, just type down the email address
usrname@hotmail.com
Note: E-mail culture, ":-)" denoting
a smile (turn your head 90 degrees to the left to view it!); ":-(" for
a frown.
As a courtesy to the person whom you are sending the e-mail, when you
are typing an e-mail message, PLEASE hit the Enter key every time you want
to make a new line. Do NOT simply allow the cursor to automatically go
to the next line, because your message will then have very long lines which
make it very difficult for the recipient to use > marks in replying to
you.
-
Talk
talk is a program which allows two users to hold a conversation. It
divides the screen so that the things you type appear in the top half and
the things written to you appear in the bottom half.
To talk to users on the same computer:
"% talk username "
To talk to users on another computer use the address format of username@nodename:
"% talk usrname@ena.me.umn.edu"
If the callee agrees to the invitation, he or she will type "talk
caller's_username@hostname."
When you want to end your conversation, just type Control-c.
-
File Transfer
-
"scp [options] file1 host:file2" - secure copy; copy files between
host machines on a network using the ssh protocol.
Examples:
-
"scp sunyu yus@bern.ece:sunyu_new" - this command will copy
the file sunyu from the current host to another machine bern.ece.umn.edu
with username yus, and the new file is renamed as sunyu_new.
-
"scp -r folder1 yus@bern.ece:folder_new" - this command will
copy the directory folder1 from the current host to another
machine bern.ece.umn.edu with username yus,
and the new folder is renamed as folder_new.
-
"scp yus@bern.ece.mn.edu:file1 file2" - this command will
copy the file file1 from the remote host bern.ece.umn.edu
with username yus, to the current host, and the new file
is renamed as file2.
-
FTP (File Transfer Protocol)
-
Use FTP to move files between machines. type:
ftp machinename (e.g. ftp ena.me.umn.edu)
Once connected, type in your username and password.
-
Retrieve files from the remote machine (the files are on the remote machine)
"get filename"
You can also retrieve multiple files, e.g.
"get file1 file2" or "get file*.out".
-
Browsers
-
"lynx" - text mode browser.
For example,
"lynx www.lib.umn.edu"
WWW also provides a very convenient way to browse through an anonymous
ftp site. You could, for instance, access the Oakland University ftp site
as follows:
"lynx ftp://rigel.acs.oakland.edu"
(Note the `ftp' in place of `http'.) This forms a much more convenient
way to browse through the ftp site than does the ftp program. You can also
use it to download text files which you find at the site.
-
"netscape"
-
More utilities:
"mesg" - allow you to prevent other users from writing to your
terminal. You can say either "mesg n" or "mesg y" to enable or disable
the display of messages.
"write username" - copy keyboard input, one line at a time to
another user's terminal. To exit, press Control-d.
"wall" - (stand for write all) allow you to send a message to
all users as "write". "wall filename" sends the message in a file to all
users. It is most often used by system administrators.
"users" or "who"- display the users on the machine you
are on.
"rusers hostname" - display a list of the users on the host
machine in the local network. In order for a host to respond, it must be
running the rusersd daemon. "rusers -a" causes the rusers to print information
for all responding machines, not just those with users logged in.
"w" or "w username" - display a list that describes what
the specified user is doing.
"hostname" - display the name of the local machine.
"finger username"
X11 Window System
-
Introduction
The X11 windows system allows you to use several terminals at once.
Each one is called a window. Each of these terminal-like windows, called
xterm
windows because they are invoked by the xterm program, has its own invocation
of the Unix shell, and thus they work independently. So, you might be editing
a file in one window, using talk in another, and so on.
You will want to use X11 windows whenever possible. It will make your
work faster and more pleasant, since most programs written today do have
some kind of windows interface (X-windows on Unix, Microsoft Windows on
PCs, etc.).
-
Window managers
An X11 window manager controls the manipulation of windows, such as
moving and resizing windows, and also provides icons, which are ``buttons''
which the user can click to start execution of programs.
Which window manager you use is a matter of personal taste. If the machine
you use has been set up by someone else, it probably already has a default
window manager in place, but you can run some other ones if you wish. Common
examples of window managers are twm, fvwm, fvwm2, icewm, Enlightenment,
KDE and many, many others. Except for twm, they all have eye-catching user
interfaces, program buttons and so on, and tend to appeal to people who
are used to the Microsoft or Macintosh window systems. Many examples in
this tutorial are for fvwm, but the tutorial is intended to be general,
and thus usable for those using other window managers as well.
-
Startup files
Analogous to .cshrc for csh, .exrc for vi, .emacs for emacs, etc.,
various X11 windows programs have startup files. The one used for your
X11 windows environment depends on how that environment is invoked at bootup
time; examples are .xinitrc, .xsession and .Xdefaults.
The fvwm window manager, for instance, uses .fvwmrc as
its startup file. Startup files are usually in your home directory; you
will have to check the man pages for details.
Among other things, a startup file configures the layout of your screen,
that is which windows you want to have, and where you want them to be placed.
For instance, the entry
xterm -geometry 80x45+410+185 -fn 9x15bold &
in a startup file such as .xinitrc will set up an xterm window of 80 rows
and 45 columns, at the X and Y coordinates 410 and 185, respectively (the
upper-left corner of the screen is (0,0)), using `9x15bold' fonts.
The line
xrdb -merge .Xenv
in .xinitrc would tell xinit to read in from the file .Xenv some settings
of various X-windows variables, and add them (``merge'') to its current
list of settings.
The line
xterm*scrollBar: on
in .Xenv sets the variable xterm*scrollBar to the value `on' (the other
possible value is `off'), so that mouse-window-scrolling is enabled.
Windows managers tend to have myriad options, thus complex startup files.
If you are new to a window manager, it is easiest to copy the sample startup
file which typically comes with the window manager, such as the file
/etc/X11/fvwm/system.fvwmrc
in the Red Hat Linux distribution, to your own startup file ( /.fvwmrc
in the case of fvwm), and then use your favorite text editor to customize
it to your liking. Also, you can experiment, clicking the various mouse
buttons while the mouse pointer is in the background of the screen, i.e.
not within any window.
-
Manipulating windows
Here are various actions which you can perform.
-
Typing in a Window
To type in any window, move the mouse to that window. Depending on
the window manager you are using, you may have to click the left mouse
button in the window before you can type there.
-
Copy-and paste operations
To copy text from one window to another, or from one point in a given
window to another point in the same window: Click the left mouse button
on the first character of the copy region, and then drag the mouse pointer
to the last character, which will result in a region being highlighted
on the screen. (In some application programs, you may also need to hold
down the left Shift key.) Then insert the text at your desired target point
by clicking the middle mouse button at that point: it will be inserted
at the pointer of the window where the mouse points at the time you click
the middle button.
-
Using the mouse to scroll a window
Suppose you wish to see previous output which has already scrolled
out the top of a window. You can recover some of it (the number of lines
which are recoverable is set by the xterm variable xterm*saveLines) as
follows: Click the middle mouse button while the mouse is in the scrollbar
of the window (the narrow strip on the left edge); the position of the
mouse in that bar will determine how much scrolling takes place. You can
scroll back down in the same way (or just hit the carriage return).
If the scrollbar is not showing, press the Control key and the middle
mouse button simultaneously, and then choose Enable Scrollbar from the
menu. To have the scrollbar showing automatically when you start an xterm
window, use the -sb option in xterm.
-
Moving a window
An existing window can be moved by clicking the left button on the
bar at the top of the window, holding the button down while dragging the
window to the desired location, and then releasing the button.
-
Raising a window
One of the biggest differences between window managers is in how they
handle autoraise capability for windows. What this capability does is to
``raise'' a window, i.e. expose it completely and have it ready for typing
within that window. With fvwm, for instance, you can set the AutoRaise
variable in .fvwmrc so that any window is raised automatically when the
mouse pointer is moved to that window.
If your window manager as currently configured does not automatically
raise windows, under that configuration you will have to raise windows
manually by clicking the left mouse button in the window. (It is safest
to click in the top bar of the window; clicking in the body of the window
may adversely affect the operation of some application programs which might
be running there.) If you wish to reconfigure so that windows are automatically
raised, check your window manager's documentation.
-
Iconify windows
If you find your screen too cluttered at some time, you can temporarily
iconify some windows, i.e. reduce them to icons, tiny squares or other
symbols (including no symbol at all). The method you use to do this will
depend on your window manager, so again you will need to check its documentation.
In fvwm, for instance, one can click the left mouse on the little down-arrow
symbol at the top of a window. The window will disappear from the screen;
when you wish it to re-appear, click on the right mouse button anywhere
in the background of the screen; a little window listing all windows will
appear, with iconified ones in parentheses. Click on the appropriate entry
to make the window re-appear.
The fvwm window manager allows your ``virtual screen'' to be larger
than your physical screen. So, you can temporarily move a window out of
the way, by using the mouse to drag the window off the edge of the screen,
into the portion of the virtual screen not currently shown on the physical
screen. (Note, by the way, that if you have your mouse pointer very close
to the edge of your screen, fvwm will then move to the previously-invisible
portion of the virtual screen. If that happens and you wish to return to
the main portion of the screen, move the mouse pointer to the edge.)
-
Creating new windows
You can invoke xterm from the command line in one of your existing
windows, or you can ask your window manager to do it for you. Window managers
generally offer you menus for this, which can be invoked by clicking one
of the mouse buttons in the background portion of the screen.
-
Running X-windows ``remotely''
-
Suppose you are at the console of Machine A(ena.me.umn.edu), and have X11
windows running there, and in one of those windows you use "rlogin"
or
"telnet"
to log in to Machine B(pearl.me.umn.edu). Suppose you then wish to run
some X11 windows application (e.g. xv) on Machine B(pearl), and display
results on Machine A(ena). Take the following steps:
xhost +pearl
rlogin pearl.me.umn.edu
-
On Machine B(pearl), type:
setenv DISPLAY ena.me.umn.edu:0
-
Run programs on Machine B, e.g.:
xv &
-
"ssh [options] machinename" - secure shell;
a program for logging into a remote machine providing encrypted communications
between machines. All the options can be access on the man page.
A useful option is:
"ssh -l username machinename",
which allows you to log into a remote machine using a different username.
Another useful option is:
"ssh -C machinename",
which compresses the data transported between machines. If you work
over a slow connection such as a modem, this -C (Note:
uppercase) option can speed your data transferring up.
-
"scp [options] filename1 host:(filename2)" - remotely copying
files and directories. Copy files between hosts on a network using the
ssh protocol. For example,
"scp sun.txt xu@tropical.ece.umn.edu: sun.txt.backup"
copies the file sun.txt to the host tropical.ece.umn.edu with the login
name xu, and name it sun.txt.backup. Another example,
"scp -r ftp xu@tropical.ece.umn.edu: ftp1"
copies the ftp directory to tropic.ece.umn.edu and rename the directory
ftp1.
Why SSH is more secure?
Ssh (Secure Shell)
is a program to log into another computer over a network, to execute commands
in a remote machine, and to move files
from one machine to another.
It provides strong authentication and secure communications over unsecured
channels. It is intended as a
replacement for rlogin,
rsh,
and
rcp.
The traditional BSD (Berkeley
Software Distribution) 'r' - commands (rsh, rlogin,
rcp)
are vulnerable to different kinds of attacks.
Somebody who has root access
to machines on the network, or physical access to the wire, can gain unauthorized
access to systems in a
variety of ways. It is also
possible for such a person to log all the traffic to and from your system,
including passwords (which ssh never
sends in the clear).
The X Window System also
has a number of severe vulnerabilities. With ssh, you can create secure
remote X sessions which are
transparent to the user.
As a side effect, using remote X clients with ssh is more convenient for
users.
Users can continue to use
old .rhosts and /etc/hosts.equiv files; changing over to ssh
is mostly transparent for them. If a remote site
does not support ssh,
a fallback mechanism to rsh is included.
-
Printing a hard copy
of a window
-
The most effective and the simplest, use "snapshot" if it
is available, you can grab any part of the screen you want!
Otherwise,
-
Specify the window by clicking the mouse in that window. (Make sure the
window is not partly hidden. If it is, move some windows out of the way
first.)
Use "xwd" to dump a window to a file: xwd -out filename
-
Convert to postscript using "xpr": xpr -device ps filename
-output filename.ps
The print filename.ps using "lpr".
Programming
and compiling
-
C
Two different C compilers are cc and gcc. To compile
.c source files(for example, sun.c), use:
-
"gcc sun.c"
When successful, an executable file sun.out is created.
-
"gcc -o myfile sun.c"
Compile the source file sun.c in the same manner. The difference is
that the compiler places the executable file in myfile.
-
Makefile
The purpose of the make utility is to determine automatically which
pieces of a large program (maybe composed of several separate programs,
multimodule programs) need to be recompiled, and recompile them. This is
accomplished by creating an input file called Makefile.
As a simple example of using Makefile, we use emacs to create a file
Makefile.
-
emacs Makefile
-
in emacs, we type:
CC=gcc
output: sun1.c (Note:
before sun.c, it must be tab, not spaces)
$(CC) -o sun sun1.c sun2.c(Note: before $(CC),
it must be tab, not spaces)
here, make sun1.c and sun2.c
are
two source files.
-
make output
Now I can type make output any time to generate an up-to-date version
of output.
For more information on make, use "man make".
-
System calls
The UNIX kernel is a program that is loaded from disk into RAM when
the computer is first turned on. It always stays in RAM, and it runs until
the system is turned off or crashes. Although it is mostly written in C,
some parts of the kernel are written in assembly language for efficiency
reasons. User programs make use of the kernel via the system calls. The
UNIX system calls can be loosely grouped into 3 main categories, file
management, process management and error handling. The
system call hierarchy is shown below.

-
Java
"module load(unload) software" -
load (unload) the environment settings for a particular software.
"module avail" - display the available modules.
"module list" - display the loaded modules.
To compile the java soucefile HelloWorldApp.java, use:
-
"module load javadev"
-
"javac HelloWorldApp.java" - HelloWorldApp.class is created.
-
"java HelloWorldApp"
Applications
-
Graphics
-
XV - type xv
-
ImageMagic - composed of several graphical manipulation programs
-
"display" - display an image file
-
"convert" - convert image files from one format into another
-
"identify" - tell you what format and size an image file
is
-
Xanim - type xanim
-
"movieplayer" - an animation player
-
"xfig" - a drawing program
-
Scanning
type gscan, then use xv to convert files into desired
format.
-
Acrobat Reader: "acroread".
-
More programs
use "module avail" to find more.
Compressing
and un-compressing
-
"gzip filename" - compress files
The original file is replaced with the compressed file filename.gz
"gunzip filename.gz" - uncompress files
-
"tar cvf filename.tar directoryname" - creates the file filename.tar
containing all the files in directoryname.
"tar xvf filename.tar" - extract the content of filename.tar
In many cases, a tar-file will also be compressed, both to reduce network
transfer time and to save space on the disk. Use "compress filename.tar"
- the filename.tar is replaced with a smaller file filename.tar.Z
.
To retrieve the original file, use
"uncompress filename.tar.Z"