Unix Tutorial

Author: Jeff Ormerod


 

File and Directory Structures

To utilise the applications software successfully you will need a basic grasp of how files and directories are organised on the CAD server.

The following diagram illustrates a typical structure for a Bolton Institute student.

File and Directory Structures

The top level directory (given the symbol / ) is referred to as the root  directory. Under this are a number of other directories defining areas where the UNIX operating system software is held (e.g. bin, usr),  the applications software (e.g. cad) and user directories (e.g. rb1ele, mh5ele).

At any point in time you will be located at a particular level in the directory structure. This is your Working Directory. When an account is created, a user directory is created with the same name as your account name. This is referred to as your Home Directory and will be your working directory at log in.

Directories and files have a pathname from the root directory so for a user with the account name rb1ele the pathname of the home directory would be:

/students/rb1ele

You can create any number of files and directories downwards from your home directory. In the example above a design directory cadencework and two design directories assignment and walkthroughs have been created by user rb1ele. Typically as applications software is invoked and a design proceeds, a number of additional directories and files will be created automatically by the software. Again in the example above, the CADENCE software has created a further directory schematics,  two files cds.lib and cds.log and two more files sheet1 and sheet2 inside schematics.

The pathname of the file sheet2 would therefore be:

/students/rb1ele/cadencework/walkthroughs/schematics/sheet2

 


Using a UNIX Terminal Window

UNIX provides a comprehensive set of commands for interacting with the operating system and manipulating files and directories.

All commands are entered into the system via a Terminal Window.
Typically one Terminal Window will be present at log in.

To open another Terminal Window or to create one if one doesn't exist:

There are a number of potential routes:

Using the Desktop Menu

If you move the mouse cursor over the desktop background and use the right hand mouse button the context sensitive menu will be displayed.

If you look in the "Tools" submenu you will see a menu entry for "Terminal" displayed. Selecting this option will open up a terminal.

 

Using the menu bar at the base of the UINX window

Click on the arrow above the CPU and Disk icon ( currently third from the right) on the CDE toolbar.

Now click on the "This Host" option to open the window.

Do not use a "Console" window as this has a specific purpose on the UNIX systems and will not give you the same results as a termainl window.

Commands are typed after the operating system prompt ($) and entered by pressing the Return key. UNIX is case sensitive and requires that all commands are entered in lower case.

The example terminal window below shows the response to entering the UNIX cal command which displays the calendar for the current month.

Using a UNIX Terminal Window

 


Some Basic UNIX Commands  

The following sections identify some useful commands together with associated practical exercises that you can try if you are unfamiliar with the UNIX operating system.

 

Directory Related Commands

Command Description
pwd Display the pathname of the present working directory
mkdir make directory
ls list a directory contents
cd change directory
mv move (and rename) a directory
cp copy a directory
rm remove a directory

Exercises in Directory Management

Enter the following commands in order in a terminal window and observe their effect.
Commands with more than one component (e.g.  cd  / ) require a space between each component.
 

Command Description
pwd

ls
Displays the pathname of your current working directory. If you have just logged on this will be your home directory.

Lists the contents of this directory
cd /


ls
Changes directory to the root directory. This is now your new working directory. The '/'  addition to the cd command is a quick way of moving to the root from anywhere in the system

Lists the contents of this directory. Here you will see subdirectories for the operating system, user accounts and applications software
cd


pwd

ls
Changes back to your home directory. The cd command issued by itself will always set your working directory to your home directory from anywhere in the directory structure

Displays the pathname of this directory

Lists the contents of this directory
mkdir test

ls

Creates a subdirectory called test inside your home directory

Lists the contents of your home directory. You will now see the newly created directory test added to the listing
cd test

pwd

touch testfile

ls
Changes into the test directory

Displays the pathname of this directory

Creates an empty file called testfile

Lists the contents of this directory. The one file testfile will be listed
cd  ..

pwd

ls
Changes back up one level to your home directory. This is accomplished by the addition of the '..' to the cd command. The command can be extended to move up any number of levels e.g. cd .. /..  will move up two levels

Checks that the current working directory is now your home directory

Lists the contents of this directory
cp -r test  project

mv test design

ls
Creates a copy of the test directory named project. The '-r' (recursive) option enables all subdirectories and files within a directory to be copied

Renames the test directory as design

Lists the directory contents. Directories project  and design will be added.
rm  -r  project design

ls
Deletes the directories project and design. The '-r' (recursive) option enables all subdirectories and files within a directory to be deleted.

Lists the directory contents. There should now be no entry for directories project or design.

 

File Related Commands
 

Command Description
touch Create a file or modify a file's date/time stamp
cat catenate (display) the contents of a file
more Display a large file in sections
cp copy a file
mv move a file
rm remove a file

Exercises in File Management

Enter the following commands in order in a terminal window and observe their effect.
 

Command Description
cd

mkdir calendar

cd calendar

touch cal.dat

ls
Changes to your home directory

Creates a directory called calendar

Moves into directory calendar

Creates a file called cal.dat

Lists the directory contents with file cal.dat added
cal  2001 > cal.dat

cat cal.dat

more cal.dat
Executes the calendar command for the year 2001 and writes the information to the file cal.dat. The symbol '>' is used to redirect the output of the command from the display to a file

Displays the contents of file cal.dat

Displays the first section of the file cal.dat. Continually press the spacebar to display more of the file
cp cal.dat   cal1.dat

mv cal.dat  cal2.dat

ls

rm cal2.dat

ls
Copies file cal.dat to a new file called cal1.dat


Renames the file cal.dat to a new file called cal2.dat


Lists the directory contents. It will contain files cal1.dat and cal2.dat

Deletes file cal2.dat

Lists the directory contents. It will contain only file cal1.dat

 

Use of Pathnames in Directory and File Management

Application packages such as Cadence generate deep directory structures. Occasionally it becomes necessary to move, copy, rename or delete files between directories. Using pathnames in the directory and file management commands enables other directories to be modified from the current working directory. Here are some examples.
 

Command Description
ls  ../

  ls ../..

ls /students/mp3/project

ls cadence/design
Lists the contents of the directory one above the current working directory

Lists the contents of the directory two above the current working directory

Lists the contents of directory  /students/mp3/project

Lists the contents of the directory design within the directory cadence in the current working directory. Note the omission of the '/' symbol at the beginning of  the pathname when going down from the working directory. 
cp test.vec  ../test.vec

  cp test.vec  ../project/test.vec

cp test.vec /students/mp3/project/test.vec

cp test.vec  design/test1.vec
Copies file test.vec to the directory one above the current working directory

Copies file test.vec to the directory project in the directory one above the current working directory


Copies file test.vec to directory /students/mp3/project

Copies file test.vec as test1.vec to the directory design in the current working directory
mv test.vec  ../test.vec

  mv test.vec  ../project/test.vec

mv test.vec /students/mp3/project/test.vec

mv test.vec  design/test1.vec
Moves file test.vec to the directory one above the current working directory

Moves file test.vec to the directory project in the directory one above the current working directory

Moves file test.vec to directory /students/mp3/project


Moves file test.vec as test1.vec to the directory design in the current working directory 
rm  ../test.vec

rm  ../project/test.vec

rm  /students/mp3/project/test.vec

rm  design/test.vec
Deletes file test.vec in the directory one above the current working directory

Deletes file test.vec in the directory project in the directory one above the current working directory

Deletes file test.vec in directory /students/mp3/project


Deletes file test.vec in the directory design in the current working directory 

 

Other Useful UNIX Commands  

Command Description
ls  -la Provides a full directory listing with file/subdirectory  dates, times, access rights etc.
ps Lists all the processes active in your session. Each process has a name and a Process Identification (PID) number
kill -9 PID Terminates a process with a particular PID. For example kill -9 1234 will terminate the process whose PID is 1234. The '-9' option will kill any process regardless of type. This command is useful if an applications package locks up
man command Provides help information on a particular command. For example man ls will list all the uses of the ls  command

 


The Common Desktop Environment (CDE)  

The Common Desktop Environment toolbar provides a number of functions you will find useful when running applications software.

The Text Editor

The Text Editor can be used to create a new file or read/edit an existing file.

The Text Editor

Click on the Notepad and Pencil icon to open up the Text Editor

To create a new file select File - New from the editor toolbar to open up the Text Editor

To read or edit an existing file select File -Open from the editor toolbar to display the Open a File menu as shown below

The Text Editor

Scroll down the Folders list to locate the required directory. You can double click on a directory entry to move down into its subdirectories or  the '..' entry to move up to the parent directory. Double click on the required file in the Files list to display the selected file in the Text Editor.

File - Save on the editor toolbar will save the file. A new file will require a filename specifying in the Enter file name:  box of the Text Editor - Save As menu and an appropriate destination directory selected from the Folders list. An existing file will automatically be saved in its current location.

More information on the features and facilities of the Text Editor can be obtained by selecting Help on the Text Editor toolbar

File - Close on the editor toolbar will close the Text Editor

 

The File Manager

The File Manager enables you to see your directory structure and manipulate directory and file entries. It provides a graphical alternative to using the UNIX file and directory commands.

The File Manager

Click on the Filing Cabinet icon next to the calendar to open a display of the directories and files in your home directory as shown below

The File Manager

Directories are denoted by folder icons
Files are denoted by text icons
Executable files are denoted by yellow ziz-zag icons

You can display the contents of a directory by double clicking on its icon
You can display the contents of a file in the Text Editor by double clicking on its icon
You can move up into the parent directory by double clicking on the ..(go up) icon

You can move a file or directory from one directory to another as follows:
Open up the File Manager and select the required source directory
Open up a second File Manager (select the filing cabinet icon again) and select the destination directory
Click on the required source entry and check that it highlights
Now drag the entry from the source directory to the destination directory

You can copy a file or directory using the same procedure as for the move but hold down the Ctrl key whilst dragging the entry from source to destination

You can delete a file or directory by selecting the required entry and pressing the Delete key

More information on the features and facilities of the File Manager can be obtained by selecting Help on the File Manager toolbar

Select File - Close on the File Manager toolbar to close the File Manager

 

The Workspaces

The CDE provides four workspaces identified on the toolbar with default names One, Two, Three and Four

The Workspaces

They enable four customised desktops to be defined. This is particularly useful when you have a number of application packages running (e.g. Netscape and Cadence) and wish to keep their associated windows separate or a time consuming activity (e.g. simulation) during which you wish to do other work.

The default workspace is One. Click on each of the other workspaces in turn and observe that they define separate desktops with different backgrounds.
You can open up Terminal Windows, issue UNIX commands, run applications software, call up the File Manager and Text Editor from any workspace

You can also rename each workspace to indicate more accurately the activity you intend to use it for.
Simply double click on the workspace name, type in the new name and press Return

Each of the workspaces can also be customised for colour scheme and background by clicking on the Mouse, Pallette and Ttt icon on the toolbar.
This will open up the Style Manager. Click on the Help option on the Style Manager toolbar for further information

Comprehensive information is available on all the CDE facilities by selecting the Book and Question Mark icon on the toolbar.

 


Updated 10.10.05 RA Updated 22 02 07 NC