Copying Files to a New Location
In addition to copying files to the same directory, you can also copy files to a new location, such as a different directory or even a different file system.
Specifying the Destination Directory
To copy a file to a new directory, you need to provide the full path of the destination directory. For example, to copy the file document.txt
from the current directory to the /home/user/backups
directory, you would use the following command:
cp document.txt /home/user/backups
This will create a new copy of document.txt
in the /home/user/backups
directory, while the original file remains in the current directory.
Renaming the Copied File
When copying a file to a new location, you can also choose to rename the copied file. To do this, simply specify the new filename as the destination:
cp document.txt /home/user/backups/new_document.txt
This will create a new file named new_document.txt
in the /home/user/backups
directory, while the original document.txt
file remains unchanged.
Copying Multiple Files
You can also copy multiple files at once by specifying multiple source files. The destination can be either a directory or a specific filename (in which case, the last source file will be renamed):
cp file1.txt file2.txt file3.txt /home/user/backups
This will create copies of file1.txt
, file2.txt
, and file3.txt
in the /home/user/backups
directory.
cp file1.txt file2.txt file3.txt /home/user/backups/new_files.txt
This will create a new file named new_files.txt
in the /home/user/backups
directory, containing the contents of file1.txt
, file2.txt
, and file3.txt
.
By understanding these basic concepts and commands, you can effectively copy files to new locations in your Linux system, ensuring data backup, organization, and sharing.