To copy a file to another directory in Linux, you use the cp command followed by the source file and the destination directory. The basic syntax is:
cp SOURCE_FILE /path/to/destination/
Example
If you want to copy a file named example.txt to a directory called backup, you would use the following command:
cp example.txt /path/to/backup/
Important Notes
- Ensure that the destination directory exists; otherwise, you will receive an error.
- If you want to copy the file and rename it in the destination directory, you can specify the new filename:
cp example.txt /path/to/backup/new_example.txt
This command copies example.txt to the backup directory and renames it to new_example.txt.
If you have any further questions or need more examples, feel free to ask!
