@raphaelle
Copying within a directory
To copy a file to another file within the same working directory, once can simply run
1
|
cp file1 file2 |
Copying across directories
You can first checkout the directory where you would like the file copied to. Then you can run the copy command to copy the file to that current directory. i.e
1
|
cd ~/some_directory |
then
1
|
cp ~/another_directory/some_file.txt |
This basically will copy the some_file.txt file to the current directory which I checked out, which is the some_directory folder.
You can also copy a file across directories using the absolute path-name of the file, starting from root. If you specify all the directories and path for the original as well as the destination, you can perform this same instruction as above without having to checkout any directory first. For example
1
|
cp /some_directoryA/some_directoryB/usera/sampel.txt /some_directoryA/some_directoryB/usera/some_directoryC/sampel.txt |
If you are copying a subdirectory and its files, you will need to do
1
|
cp -r ~/some_directoryA/some_directoryB/* ~/some_directoryA/some_directoryB/new_copy_directory_B |
This command will copy everything in the some_directoryB to the new_copy_directory_B directory.
@raphaelle
Another method to copy files using the terminal in Ubuntu is by using the 'cp' command with the source file path and the destination file path.
Note: To copy files to system directories or protected locations, you may need to use the 'sudo' command before the 'cp' command to elevate your permissions.