Continuing with the basic Linux commands, in this tutorial, you will learn how to move and copy files in Linux using examples.
The basic commands used in copying and moving files are cp and mv
- cp: used in copying files from one location to the other
- cp –r : used to copy directories recursively.
- mv: used in moving files from one location to the other just like cut and paste in the windows environment.
Let’s be practical with some examples as usual.
using the usual chart below , Let’s make some examples.
Using the above chart, do the following:
1. Copy the N_managers file to EMC_STORAGE_TEAM directory
Note: If one is already in the directory where the file is, the file can be copied straightaway to the directory you want it to be
# cp N_managers /home/tomisinuno/IT_DEPARTMENT/STORAGE_TEAM/EMC_STORAGE_TEAM
If one is not in the directory where the file is, the whole path will be copied
# cp IT_DEPARTMENT/NETWORK_TEAM/N_managers IT_DEPARTMENT/STORAGE_TEAM/EMC_STORAGE_TEAM
cp /home/tomisinuno/IT_DEPARTMENT/NETWORK_TEAM/N_managers /home/tomisinuno/IT_DEPARTMENT/STORAGE_TEAM/EMC_STORAGE_TEAM
I believe by now, you understand the differences between the two.
2. In the NEXUS_STORAGE_TEAM directory, copy the Full_staff file to the DELL_SWITCH_TEAM directory
cp /home/tomisinuno/IT_DEPARTMENT/STORAGE_TEAM/NEXUS_STORAGE_TEAM/Full_staff /home/tomisinuno/IT_DEPARTMENT/NETWORK_TEAM/DELL_SWITCH_TEAM
3. Copy the IT_DIRECTORS directory to the DELL_SWITCH_TEAM directory.
cp IT_DIRECTORS /home/tomisinuno/IT_DEPARTMENT/NETWORK_TEAM/ DELL_SWITCH_TEAM
You can see that IT_DIRECTORS wasn’t copied. IT_DIRECTORS is a directory and not a file. The error was explicitly stated “cp: omitting directory “IT_DIRECTORS”
What next? From one of the previous lessons, It was mentioned that there are a lot of options associated with a command and there are ways help can be gotten. In this case, we need help and to get it, we use the command,
# cp - -help
you can see that –R is an option to copy directories recursively, so we use -R
4. Move the SAN_Team file to the STORAGE_TEAM directory
1. Copy the temp_file to IT_DIRECTORS directory.
2. Move the EMC_STORAGE_TEAM directory to DELL_SWITCH_TEAM directory.
NEXT MODULE: How to use the vi and vim text editor.
Your feedback is welcomed. If you love others, you will share with others