Skip to main content

3.1) Making Copies Of Files


Suppose you want to make an extra copy of the data1 file and you want it called firstdata. You can do this by typing:
cp data1 firstdata
If you type ls you can check to see if the file was indeed made and if you type ‘more firstdata’ you will see that a copy has been made and placed in your directory. Both firstdata and data1 now exist in the directory.
If you want to rename the data file called ‘firstdata’ instead as ‘data1backup’ then use the mv command. It changes the name so note that ‘firstdata’ will not exist after you do the following command.
mv firstdata data1backup
To remove a file, you just type "rm" followed by the name of the file you would like to remove.
rm data1backup
You may be asked to confirm you want to remove the file (accept by typing 'y' for yes).
You can confirm the file is removed by typing ls. Now in preparation for the next exercise, let's make another copy of the data1backup file by typing:
cp data1 data1backup
Tip
If you type cp data1 dat and then hit tab then Unix will often complete the sentence to be cp data1 data1backup as long as the data1backup directory is the only one that starts with dat.   Experiment with this as it can save a lot of time.