UNIX USER TRAINING
Session 1 : UNIX Fundamentals
Objectives
This session will cover the following topics:
UNIX Background
Logging in to a UNIX System through a PC via telnet
UNIX Passwords
Online Help
Directories and Paths
Directory and Filename Wildcards
Directory and File Permissions
Basic File Maintenance Commands
1) UNIX Background
History
The history of the UNIX operating system stretches back to 1969. Ken Thompson and Dennis Ritchie, working at Bell Labs, wrote the first version to run on a DEC PDP-7 system. In 1972 – 1974, UNIX was re-written in the C language (itself invented by Ritchie), a step that was to make UNIX the first source-portable operating system in the world. (At the time, operating systems were largely hardware specific and could not easily be made to run on machines other than those they were designed for.) Many different people from businesses and academic institutions in the USA subsequently had a hand in the development of UNIX, perhaps the most (in)famous being the University of California, Berkeley, whose BSD distribution formed the basis of SunOS, and Microsoft Corporation’s Xenix.
Throughout the 80’s UNIX veered off on several tangents, leading to the development of many different distributions or flavours. These distributions were often vendor-specific and included Sun’s SunOS, SGI’s IRIX, Hewlett-Packard’s HP-UX and IBM’s AIX. Since the early 90’s, the Linux operating system – a freely distributable UNIX-like OS designed to run on Intel x86 hardware, has increased the visibility of UNIX in general.
What version of UNIX runs on ProQuest’s systems?
We are using Sun Microsystems Solaris operating system. Solaris is Sun’s flavour of UNIX (SunOS) packaged together with other optional software, such as X Windows, administration software, utility programs, RAID management, and so on. Our main servers (mclaren, ferrari, jordan and those which host our web-products) are Solaris 7, a version of that has been stable in production environments worldwide for 3 – 4 years.
Why UNIX and, more importantly, why Sun Solaris?
UNIX is a stable, powerful, well-documented operating system. This has not always been the case, admittedly, but over the course of UNIX’s 30-year development history, the major performance and security holes have been plugged. UNIX is a flexible and developer-friendly operating system.
Sun Solaris was developed from UNIX System V, Release 4, the base from which future UNIX standards will be developed. For backward compatibility Solaris retains many features from the earlier SunOS. Solaris runs on Sun’s own SPARC architecture servers and Intel x86 platforms.
Solaris on SPARC platforms is the operating system of choice for applications where scalability, power and high-availability are required. Such application areas include banking, engineering, oil exploration, scientific research and, of course, website hosting.
2) Logging In
This lecture course concentrates on command line UNIX. It's therefore necessary to log in to a UNIX machine on the command line. On a standard Windows 9x/NT PC, use the following method.
From the Start Menu, select the Run... option. A command box pops up. Into that box type
telnet mclaren

and click OK. After a short while, a white window will pop up, displaying the following prompt

Enter your username. After this, you will be prompted for your UNIX password. Type this in, but note that it will not be displayed on screen. After the password is accepted, you should see information similar to the following:
The "mclaren%" information is the C-shell command prompt. At this prompt you can start typing UNIX commands.
3) The Word on Passwords
The Chadwyck-Healey Password Policy is described in the Employee Handbook. This specifies that your password must contain a mixture of letters, both upper case and lower case, numbers and punctuation marks. Further, the punctuation mark should not be the first or last character.
Examples of poor passwords
Real dictionary words
Anything that can be traced back to you, eg your car registration number, your post code, the name of your 'significant other', your date of birth
Examples of good passwords
Song titles
p@raN0!d (Black Sabbath - Paranoid)
luV8!tez (Def Leppard or Judas Priest - Love Bites)
0vaD@Top (Motorhead - Over the Top)
G3taGr!p (Aerosmith - Get a Grip)
fR3eW!lL (Rush - Freewill)
Phrases
Frc.Lmy3 ("Friends, Romans, countrymen. Lend me your ears")
SL&t4adf (So Long and Thanks for All the Fish)
Ill8b@ck ("I'll Be Back")
OneR2r+a ("One Ring to Rule Them All")
Punctuation and Numbers
Use @ symbol for a or A
Use & for the word 'and'
Use ( symbol for c or C
Use ! symbol for i or I
Use 8 for uppercase B
Use 3 for uppercase E
Use 0 (zero) for o or O
Use + (plus sign) for lowercase t
Connect two short words with - _ . or =
Colour Abbreviations
rd = red yl = yellow or = orange
gn = green bl = blue in = indigo
vi = violet wh = white bk = black
gr = grey br = brown ma = magenta
cy = cyan lt = light dk = dark
Setting Passwords Under Solaris
UNIX passwords are easy to set. When your account is created a default new user password will be set by the IT Department. Please change this password the first time you log in to your UNIX account. A member of the IT Department will often be on hand to help out.
To change your password, first log into a UNIX server (mclaren or ferrari , typically) and use the following command:
mclaren% passwd -r nis
You will then be prompted for a new password:
mclaren% passwd -r nis
Changing NIS password for colinbr
New Password:
New Password (confirm):
At the prompts, enter your new password. This will not be echoed to the screen, so please type carefully! If the two passwords do not match, you will be prompted again until the password is accepted.
4) On Line Help
There is extensive on line help available on UNIX if
You know what you are looking for
You know what you are looking at
The principal source of on line help is the man command. This is short for manual and displays the UNIX manual page associated with the command you are interested in.
For example
mclaren% man ls
displays the manual page for the ls command. The 'man page' should describe the command in exhaustive detail, describing options, arguments, and parameters to the command. Some man pages offer examples of usage, descriptions of bugs which may exist in the command. Almost all man pages have a SEE ALSO section which lists related commands. Try the manual page for the man command itself
mclaren% man man
The man command is, largely, useless unless you know what command you need help with. In a case where you only have a rough idea of what you need help on, the man command has the facility to perform a keyword search and display a list of commands which may relate to your subject.
As a simple example, if you want to know how to list the contents of a directory (assuming you don't already know about the ls command) try the following.
mclaren% man -k list
DtDtsDataTypeToAttributeList DtDataTyping (3) - Data Typing operations
facl acl (2) - get or set a file's Access Control List (ACL)
fc history (1) - process command history list
ff ff (1m) - list file names and statistics for a file system
ff_ufs ff_ufs (1m) - list file names and statistics for a ufs file system
listen listen (1m) - network listener daemon
ls ls (1) - list contents of directory
ls ls (1b) - list the contents of a directory
xlsclients xlsclients (1) - list client applications running on a display
xlsfonts xlsfonts (1) - server font list displayer for X
xlswins xlswins (1) - server window list displayer for X
The output shown above is abridged. Solaris 7 lists 333 hits from this command! It will display a large number of command names that contain the word list in their SYNOPSIS section. It includes those commands which list X Windows resources, some subroutines from the C language and so on. Some of these commands will also be 'Systems Administrator' commands and, therefore, not usable by non-privileged users. Not very helpful but a start. In such a case, try changing the keyword, eg:
mclaren% man -k directory
Again, Solaris 7 will list multiple hits, 65 in this case. To further narrow your search, you can try changing the 'Section' of the UNIX manual you want to look at. Notice in the output above, there are two hits for the ls command, each in different sections of the manual, 1 and 1b. For example:
mclaren% man -s 1 ls
You cannot use the following command:
mclaren% man -s 1 -k list
To see why, look at the SYNOPSIS section of the man page. This is shown below:
NAME
man - find and display reference manual pages
SYNOPSIS
man [ - ] [ -adFlrt ] [ -M path ] [ -T macro-package ]
[ -s section ] name ...
man [ -M path ] -k keyword ...
man [ -M path ] -f file ...
The SYNOPSIS shows three ways of invoking the man command. From this it can be seen that the s and k options do not appear together in any of these examples: they are therefore incompatible.
Notice that some of these parameters are in square brackets [ ] . Parameters shown like this are optional. Where a parameter is not surrounded by square brackets, it is compulsory. Optional and compulsory parameters can be combined. To explain:
The name parameter is compulsory: it must be specified or the man command will not know which page to display.
The -a , -d , -F (and so on) parameters are optional: they do not need to be present on the command line. If they are present, they will modify the behaviour of the man command. Such parameters are often called flags or switches.
The keyword parameter to the -k option is compulsory only if you specify -k .
Lastly, the -M flag is optional in all cases but the path parameter must be specified with this option.
As a further example, the SYNOPSIS section of the ls command looks like:
NAME
ls - list contents of directory
SYNOPSIS
/usr/bin/ls [ -aAbcCdfFgilLmnopqrRstux1 ] [ file ... ]
/usr/xpg4/bin/ls [ -aAbcCdfFgilLmnopqrRstux1 ] [ file ... ]
Notice that there are actually two versions of the ls command in different directories. The first version, /usr/bin/ls , is the standard Solaris program – referred to as the “historical Solaris utility” in the man page – which has existed within Solaris for several years. Certain UNIX standards, of which XPG4 (X/OPEN Portability Guide version 4) is one, specify different behaviour for certain commands; ls is one such command. In a case where the XPG4 version’s behaviour differs from the historical Solaris version, Sun provide both commands, with the XPG4 command kept under /usr/xpg4 . In day-to-day operation, you will only need to use /usr/bin/ls .
5) Directories and Paths
Directories in UNIX are analogous to folders in Windows. Directories are arranged within the UNIX file system in an inverted tree structure, the top of which is called the root directory and is given the symbol / (slash).
An absolute pathname addresses a directory or file from the root directory, for example:
/dc/pci/segments/seg17
/dc/medieval/acta/greek
/dc/medieval/acta/doc/routines
A relative pathname addresses a file or directory from the current working directory. But what is the current working directory? To find out, use the pwd (print working directory) command. For example:
mclaren% pwd
You will get a response similar to
/home/colinbr
A relative path does not begin with a / . For example, given the current working directory of /home/colinbr/CH and the contents shown below
mclaren% pwd
/home/colinbr/CH
mclaren% ls
athens domains sun_calls unix_procedures
ch_docs oracle sun_docs veritas
change server_config training
The following are all examples of relative pathnames
ch_docs
athens/supplement.doc
training/examples/binaries.html
../PROJECTS/netras
The first example references the ch_docs directory. The second example identifies the MS Word document supplement.doc in the athens subdirectory. The third example refers to the HTML file binaries.html in the examples subdirectory of training .
The last example is more interesting. The abbreviation .. (dot dot) is used to signify a directory one level up from the current directory. In this case, the .. component refers to the /home/colinbr directory and the rest of the path identifies the PROJECTS subdirectory (ie /home/colinbr/PROJECTS) and the netras directory within PROJECTS . The full path would be /home/colinbr/PROJECTS/netras
More than one .. component can appear in a relative path. So, for example, given the pathname below as the current working directory
mclaren% pwd
/home/colinbr/CH/training/examples/Backups
the relative path
../Interactive/cshrc
refers to the file cshrc in the /home/colinbr/CH/training/Interactive directory
The relative path
../../..
refers to the /home/colinbr/CH directory (i.e. three levels up from the Backups directory). For example
mclaren% ls ../../..
athens domains sun_calls unix_procedures
ch_docs oracle sun_docs veritas
change server_config training
The directory name of . (dot) refers to the current directory.
File name wildcards are used to save a lot of tedious typing. Briefly, the wildcard characters are as follows:
* matches zero or more occurrences of any character
? matches exactly one occurrence of any character
[] defines a set of characters that may be matched
Wildcard characters can be used with many file manipulation commands in UNIX; typically the ls , cat , cp , mv and rm commands benefit from a knowledge of these wildcards. Some examples, using the ls command, follow
mclaren% ls *.txt
will list all those files ending with '.txt' but the command
mclaren% ls ?.txt
will list only those files whose names consist of a single character and ending with '.txt' e.g. 1.txt , A.txt , a.txt , b.txt .
To narrow the search further, specify a set or range of characters that will be matched using the [] wildcards. The command
mclaren% ls [aA].txt
will list only the files a.txt and A.txt . The command
mclaren% ls [a-d].txt
lists those files a.txt , b.txt , c.txt and d.txt .
Combining these features lets us build up more complicated expressions. For example:
mclaren% ls [aA][bB]*.txt
lists those '.txt' files which start with either ab , aB , Ab or AB , followed by any other string of characters (even zero characters).
Using wildcards is particularly useful for 'mass deletes' using the rm command. But in order to ensure you are deleting only those files you really want to delete, use the same combination of wildcards with the ls command first. This will help prevent mistakes.
7) Directory and File Permissions
Central to basic UNIX user security is the concept of access permissions. Permissions are set at the individual file (or directory) level and allow or deny certain operations on that file or directory. In a typical ls -l listing (discussed in more detail below), you will see information similar to the following:
drwxr-x--- 2 colinbr it 1024 Jul 10 20:08 training
-rw-r--r-- 1 colinbr it 1757601 Jun 22 1999 unix_admin.pdf
The first ten characters, the arcane strings like -rw-r--r--, show the file type and the permissions set on that file. Briefly, the first character indicates file type and the next nine characters - read in three groups of three - show the permissions set on that file.
The first character is most commonly one of the following
d indicates the file is a directory
l indicates the file is a symbolic link
- indicates the file is a normal file
Other characters seen in this first column include b, c and p for block special devices, character special devices, and named pipes respectively. These file types are outside the scope of this course.
The next nine characters are the 'permissions bits'. The first three characters show the permissions the user or owner of that file has; the next three show the permissions members of the owner's group has on that file; the last three show the permissions everyone else (i.e. 'other' users) has on that file. The permissions bits are normally one of the following
r read access
w write (create, edit, delete) access
x execute access (eg for shell scripts, search access to a directory)
- no access
Particularly important are the write permissions. If write permission is set on a directory, new files can be created in that directory. If write permission is set on a file it can be edited by those for whom the permission is set. Furthermore, if write permissions is set on a file and on the directory it is in, the file can be deleted by those for whom permission is set. Take care!
Consider the entry for training as shown above. The first ten characters of the ls -al listing are
drwxr-xr-x
The first character 'd' indicates that 'training' is a directory. The next three groups of permissions bits specify, respectively, that the directory's owner (colinbr) can read it, create files in it and search it (rwx); members of the owner's group (it) can read and search within that directory but cannot delete or change anything (r-x); lastly, other users can not access the directory at all (---).
Under Solaris you will occasionally see a + (plus sign) appended to these permissions bits, for example
drwxr-x---+
The + indicates that there is an Access Control List (ACL) in force on the file or directory. This is a security feature which further refines the basic UNIX file permissions system. More details on this follow.
8) Basic File Maintenance Commands
mkdir - Making Directories
To create a directory use the mkdir command. For example:
mclaren% mkdir TEST
This will create the directory TEST in the current directory. Note that, because UNIX is case sensitive, the directory TEST is different to Test , test or TeSt . You can create a number of directories simultaneously:
mclaren% mkdir dir1 dir2 dir3
Or, you can create a complete path of directories under the current directory
mclaren% mkdir -p TEST/dir1/dir2
The -p flag to mkdir says to recursively make all the directories in the given path.
cd - Changing Directories
To change to the TEST directory you have just created use
mclaren% cd TEST
Given the earlier current working directory of
/home/colinbr/CH/training/examples/Backups
the following command will change to a new directory, say, Working , under the examples directory:
mclaren% cd ../Working
The cd command with no other arguments will automatically change your working directory to your UNIX home directory.
ls - List Contents of Directories
The ls command will display the contents of a directory. In its simplest form, with no options, its output is similar to that shown below:
mclaren% ls
DOCS Desktop MEDIA Mail UNIX_INFO Xrootenv.0 nsmail
DOWNLOADS GAMES MINE TEST WEB autosave
mclaren%
It has many different options, some of which are described briefly below.
-a List all files, even those whose names begin with a . (dot)
-l List in long format
-d List just the directory attributes, not the contents of that directory
-F Show a file type identifier with the listing
-R List subdirectories recursively
Check out the man page for further details. The -l option deserves special mention. A fragment of the output from the ls -la command is shown below:
mclaren% ls -al
total 190
drwxr-xr-x 5 colinbr it 1024 Sep 4 15:18 .
drwxr-xr-x 3 colinbr it 512 Sep 4 15:27 ..
drwxr-xr-x 2 colinbr it 512 Aug 16 15:20 Backups
drwxr-xr-x 2 colinbr it 512 Sep 4 15:25 Interactive
drwxr-xr-x 2 colinbr it 512 Sep 4 15:16 Working
-rw-r--r-- 1 colinbr it 2415 Aug 16 13:54 binaries.html
-rw-r--r-- 1 colinbr it 7421 Aug 16 13:54 build.html
-rw-r--r-- 1 colinbr it 2196 Sep 4 14:34 clancy_bio.txt
-rw-r--r-- 1 colinbr it 19817 Aug 16 13:54 configure.html
-rw-r--r-- 1 colinbr it 26888 Sep 4 14:58 dba1a.pdf
-rw-r--r-- 1 colinbr it 1727 Sep 4 14:34 elf.txt
-rw-r--r-- 1 colinbr it 1657 Aug 16 13:53 install_gcc
-rw-r--r-- 1 colinbr it 2427 Aug 16 13:53 install_make
-rw-r--r-- 1 colinbr it 16007 Aug 16 13:55 jordan
-rw------- 1 colinbr it 1100 Sep 4 14:55 news.txt
-rw-r--r-- 1 colinbr it 920 Sep 4 14:25 words1
-rw-r--r-- 1 colinbr it 2933 Sep 4 14:26 words2
The permissions bits were discussed previously. In order, the columns of information presented here are
The file type and permissions bits
The link count to the file (see Symbolic Links)
The file owner (colinbr)
The group ownership of the file (it)
The file size in bytes
The date/time of last modifcation
The file name
cat, more, pg, head, tail - Displaying files
UNIX contains a number of methods of displaying files. By far the simplest is the cat command (short for concatenate and print). For example
mclaren% cat news.txt
will display the contents of the ods.txt file to the screen. Multiple files can be specified:
mclaren% cat news.txt elf.txt
Multiple files can be combined into a single large file using output redirection, more details of which will follow. For now, the following example can be used to combine elf.txt and news.txt into a single file, bigfile.txt
mclaren% cat elf.txt news.txt > bigfile.txt
However, when using cat long files will scroll off the top of the screen and you will miss a lot of the output. To display a file one page at a time use either the more or pg commands:
mclaren% more news.txt
mclaren% pg elf.txt
The more and pg commands do the same job but differ in the way they scroll from page to page or line by line. In general, with more use the space bar to move to the next page and Enter to scroll line by line; use b to move back one page.
The head and tail commands can be used to display the beginning and end (respectively) of a file. By default the first (or last) ten lines of a file are displayed, for example
mclaren% tail news.txt
will display the last ten lines of the file news.txt while the command
mclaren% head elf.txt
will display the first ten lines of elf.txt . The number of lines displayed can be changed as shown below
mclaren% head -20 elf.txt
will display the first 20 lines of elf.txt while the command
mclaren% tail -25 news.txt
will, obviously, display the last 25 lines of news.txt . A further useful option to the tail command is -f (for 'follow') which will display the last ten lines of the file and then automatically display more lines as they are added to the output file. This is useful for following the progress of a log file, for example
colinbr% tail -f logfile.txt
cp - Copy Files
A very useful command for creating backups of files before editing! At its simplest, the format is:
cp filename1 filename2
For example, to create a backup of the ods.txt file prior to editing, use:
mclaren% cp news.txt news1.txt
Of course, cp can be used to copy files into another directory. Given the directory of
/home/colinbr/CH/training/examples
which contains the subdirectories of Working and Backups , first cd to the Working directory and use
mclaren% cp fred.txt ../Backups
to create a backup of the fred.txt file in the backup directory. Or, perhaps create a dated backup of fred.txt with
mclaren% cp fred.txt ../Backups/fred120701.txt
mv - Move or Rename Files
Similar to the cp command, mv renames files or moves them to a new directory. The format is also similar to the cp command, for example:
mclaren% mv fred.txt old_fred.txt
or
mclaren% mv fred.txt ../Backups/fred040901.txt
rm - Remove (delete) Files
Removing files is always important. But it is equally important to do so safely. Please take care when using rm not to
Delete files you may need later
Delete files others in your team (or other teams) may need
Be particularly careful when removing files that have global write permissions set: you may not even own such files but can still remove them!
The format of the rm command, at its simplest, is:
rm filename
For example:
mclaren% rm news.txt
Multiple files or filename wildcards can be specified:
mclaren% rm news.txt elf.txt
or
mclaren% rm *.pdf
With this last example please be particularly careful with wildcards. A carelessly used 'rm *' command will blow away the contents of an entire directory!
rmdir - Remove a directory
If a directory is empty, i.e. contains no files or subdirectories, it can be removed with the rmdir command. For example
mclaren% rmdir my_dir
If the directory my_dir still contains files, perhaps those whose names begin with a '.' (dot), you will get an error message saying so ('Directory not empty'). In such a case, either cd into the directory and remove all the files before removing the directory itself or use the rm command with the -r option as shown below:
mclaren% rm -r my_dir
The -r option recursively descends through my_dir removing all files and subdirectories it contains before finally deleting my_dir itself.
Be very careful using such a drastic command!
The -i option: Interactive Commands
The cp , mv and rm commands all have a useful -i option. This is for interactive mode and will prompt for a yes/no response before carrying out the operation on a file. When using cp or mv , for example, -i causes the command to prompt if you might overwrite a file with the same name; with rm , the -i option asks if you really want to delete the file in question. Examples follow. Given the directory contents shown below:
mclaren% ls -alF
total 78
drwxr-xr-x 2 colinbr it 512 Sep 4 15:25 .
drwxr-xr-x 5 colinbr it 1024 Sep 4 15:18 ..
-rw-r--r-- 1 colinbr it 411 Sep 4 15:21 cshrc
-rw-r--r-- 1 colinbr it 330 Sep 4 15:22 cshrc.diff
-rw-r--r-- 1 colinbr it 402 Sep 4 15:23 cshrc.prev
-rw-r--r-- 1 colinbr it 16591 Sep 4 15:23 ls
-rw-r--r-- 1 colinbr it 16539 Sep 4 15:25 ls.txt
mclaren% cp -i ls.txt ls
cp: overwrite `ls'? n
This command attempts to copy ls.txt onto the ls file. At the prompt answer 'n' and the file will not be overwritten.
mclaren% mv -i cshrc cshrc.diff
mv: overwrite `cshrc.diff'? y
This command overwrites the cshrc.diff file with the contents of cshrc . Answering 'y' at the prompt confirms the overwrite action; the effects on the directory contents are shown below:
mclaren% ls -al
total 18
drwxrwx--- 2 colinbr it 1024 Jul 13 12:29 .
drwxr-xr-x 33 colinbr it 2048 Jul 13 11:53 ..
-rw-r--r-- 1 colinbr it 668 Jul 13 12:16 cshrc.diff
-rw-r--r-- 1 colinbr it 668 Jul 12 14:44 cshrc.prev
-rw-r--r-- 1 colinbr it 5817 Jul 13 12:25 ls
-rw-r--r-- 1 colinbr it 6239 Jul 13 12:24 ls.txt
mclaren% rm -i *
rm: remove `cshrc.diff'? y
rm: remove `cshrc.prev'? n
rm: remove `ls'? n
rm: remove `ls.txt'? y
This command interactively removes all files but answers of 'y' or 'n' at the prompt confirm that we actually want to keep the files cshrc.prev and ls as shown below:
mclaren% ls -al
total 10
drwxrwx--- 2 colinbr it 1024 Jul 13 12:31 .
drwxr-xr-x 33 colinbr it 2048 Jul 13 11:53 ..
-rw-r--r-- 1 colinbr it 668 Jul 12 14:44 cshrc.prev
-rw-r--r-- 1 colinbr it 5817 Jul 13 12:25 ls
ln - Link Files and Directories
In the previous listing, the second column is the 'link count' to each of the files or directories shown. What is a link? In UNIX, a link can be thought of as an alias to a file. An analogy in Windows might be a shortcut. There are two types of links: hard links and symbolic links.
The differences are somewhat esoteric. A hard link cannot cross filesystem boundaries while a symbolic link can point to any file or directory in the UNIX filesystem. Furthermore, hard links do not create any new files while a symbolic link does create a new file.
The concept of the UNIX 'inode' is necessary when understanding links. 'Inode' is short for 'information node', a data structure which stores pertinent information about files and directories in what UNIX calls the 'inode table'. Inodes contain data like the file name, owner, size, creation, access and modification times and an index of block numbers in which the file's contents can be found on disk. Each file in the UNIX filesystem has an inode number. Links manipulate these inode numbers. To create a hard link to a file, use the ln command as follows
ln source_file link_name
e.g.
mclaren% ln data mydata
To create a symbolic link use the ln command with the -s option as follows
ln -s source_file link_name
e.g.
mclaren% ln -s data mydata
A simple example should help clarify matters. Consider the directory listing below:
mclaren% ls -li wo*
1732074 -rw-r--r-- 1 colinbr it 74 Feb 9 2001 words1
1732075 -rw-r--r-- 1 colinbr it 134 Feb 27 2001 words2
The -i option to ls displays the file's inode number in the extreme left hand column. Take note of the inode numbers and link count columns in the following examples.
Create a hard link to the file words1
mclaren% ln words1 words1_hard
mclaren% ls -li wo*
1732074 -rw-r--r-- 2 colinbr it 74 Feb 9 2001 words1
1732074 -rw-r--r-- 2 colinbr it 74 Feb 9 2001 words1_hard
1732075 -rw-r--r-- 1 colinbr it 134 Feb 27 2001 words2
Note that the link counts of words1 and words1_hard are now 2 and the inode number of both files is the same, 1732074. This is because words1_hard is simply a reference to the inode of the original file.
Now create a symbolic, or soft, link from words2
mclaren% ln -s words2 words2_soft
mclaren% ls -li wo*
1732074 -rw-r--r-- 2 colinbr it 74 Feb 9 2001 words1
1732074 -rw-r--r-- 2 colinbr it 74 Feb 9 2001 words1_hard
1732075 -rw-r--r-- 1 colinbr it 134 Feb 27 2001 words2
1732042 lrwxrwxrwx 1 colinbr it 6 Aug 29 14:59 words2_soft ->
words2
The link target words2_soft is a new file, as indicated by the new inode number. The link count of the original data file has not increased.