Skip to main content

3.6) Moving Files Between Directories


Now let us copy a file into the new directory called research. We will make a copy of ‘data1backup’ and put it into the research directory. You can do this by using the cp command. Up until now, the cp command was just used to make copies of files but you will see below that if the last name in the command is a directory, then the cp command will make a copy of the file (data1backup) and put it into that directory (research).
cp data1backup research
You can do the same with the mv command. If the last word in the command is the name of a directory, it will move the file into that directory.
Tip
If you specify research with a / at the end then Unix will know you intend the file be copied into a directory named research and not just a copy of the file with a different name.    So you can type
cp data1backup research/
and it will warn you if there is no directory named research.