How do I copy a file to another directory in Linux?

In Linux, you can use the command “cp” to copy a file to another directory.

The basic syntax of the cp command is as follows:

cp [选项] 源文件 目标文件或目录

Among them, the options can include the following commonly used options:

  1. -r or -R: recursively copy directories and their contents
  2. – Before copying, please confirm.
  3. -v: Display detailed information about the copy operation.

Here are some common usage examples:

  1. Copy the file file.txt to the directory dir.
cp file.txt dir/
  1. Copy files file1.txt and file2.txt to directory dir.
cp file1.txt file2.txt dir/
  1. Copy directory dir1 to directory dir2.
cp -r dir1/ dir2/

Please select the appropriate options and parameters to use the cp command for file copying based on your actual needs.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds