SESSION 10		COPYING, MOVING, REMOVING FILES


1. cp

The copy command `cp' has several forms:

cp  oldfile  newfile		copy oldfile to newfile (same directory)

cp  oldfile  directory		copy oldfile into directory; the copy retains 
				the same filename
cp  oldfile directory/newfile	copy oldfile into directory; give it the new 
				name newfile
cp -r  olddir  newdir		copy a complete directory, olddir, to a new 
				directory, newdir


2. rm

The remove command `rm' (rm -i with confirmation) deletes files 
(see Session 4):

		rm  filename

CAUTION		rm *		removes all files in working directory
		rm -i *		removes all files in working directory
				with confirmation of each deletion

The `*' is a wildcard which can match any string of characters and so is able 
to refer to all the files in a directory (see below). It is very useful but 
care is required in its use.


3. mv

The move command `mv' is equivalent to the `copy and remove' combination. 
It has the same variations as `cp':

mv  oldfile  newfile		rename oldfile to newfile

mv  oldfile  directory		moves oldfile into directory

mv  oldfile  directory/newfile	moves oldfile into directory; renames it
				newfile


4. Wildcards

The shell recognises certain special characters , * and ?, called wildcards 
which make it possible for a single filename argument to match more than 
one actual filename.

First create a short file, called `hom1' say, in the directory courses/ph251/
homework. Make 3 copies of it with filenames `hom2', `hwork3', `work4'.

Then the first three files in this directory may be referred to as `h*'. The * 
refers to any string of characters following the `h'. For example, type

			ls h*

This lists all those files in the working directory beginning with the 
letter `h'.

The wildcard `?' stands for any single character. Thus, all those files 
beginning `hom' and containing 4 characters only could be referred to as

			hom?

Files with 5 characters and beginning `h' would be `h????'.

Such wildcards can be used in conjunction with many commands.


5. Exercises

a) Practise copying, moving and removing the files hom1, hom2, hwork3, work4 
into, out of and between directories as appropriate.
b) Copy all files beginning with `ho' in the directory courses/ph251/homework 
into the directory courses/ph222/labwork.
c) Remove hom2 from courses/ph221/labwork


END OF SESSION 10					file: copfil10
