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:
- -r or -R: recursively copy directories and their contents
- – Before copying, please confirm.
- -v: Display detailed information about the copy operation.
Here are some common usage examples:
- Copy the file file.txt to the directory dir.
cp file.txt dir/
- Copy files file1.txt and file2.txt to directory dir.
cp file1.txt file2.txt dir/
- 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.