Getting Started : Copying, Renaming, and Deleting Files

To copy a file, use the command

cp file1 file2

This will make a copy of file1, giving it the name file2. There is no concept of version numbers in Unix, and if file2 already exists, its contents will be OVERWRITTEN with the contents of file1, thus destroying what was originally in file2. The option -i may be used to cause the machine to prompt for confirmation before overwriting the output file.

Examples

% cp plantslist plantsback

will make a copy of the file plantslist, calling the copy plantsback.

% cp -i try1 try2

Overwrite try2?

will copy the file try1 to try2, confirming that the file should be overwritten.

The cp command leaves the original file (file1) intact. If you simply wish to change the name of a file, use the mv command.

To change the name of a file (move it) use the command

mv file1 file2

This renames file1 to be called file2. As with cp, if file2 already exists, its contents will be OVERWRITTEN and lost. Again, there is an option -i to cause the machine to confirm that the second file should be overwritten if it already exists.

Example

% mv newdata olddata

To delete a file (or files), use the rm command

rm file1 [...]

The rm command can take a number of filenames as parameters, with each file being deleted in turn. By default the files will simply be deleted with no confirmation; the option -i may be used to cause the machine to ask for each file whether it should be deleted or not.

Example

% rm -i data*

This will cause any file beginning with the characters data to be deleted, with confirmation being sought for each file.

These three commands, cp, mv, rm have all been implemented on the OUCS linux.ox.ac.uk with the -i option set by default.