What command is used to copy a file to another directory?

QuestionsQuestions8 SkillsProBasic Files OperationsAug, 05 2025
0130

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!

0 Comments

no data
Be the first to share your comment!