Article Title: copying files and folders in Linux. Linux is a technology channel of the IT lab in China. Some basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source are included. When operating Linux remotely, many powerful shell commands can help us. Copying files and folders is a very powerful function.
1. Copy command cp on the same machine.
Copy the cp filename1 filename2 file, copy filename1 and name it filename2.
Add the parameter-f without any prompt when overwriting the renamed file.
For example, cp-f filename1 filename2.
Add the parameter-r to the preceding command to copy the folder. For example, cp-rf dic1 and dic2. more detailed cp commands are as follows:
Note: The cp command is used to copy files or directories. For example, if two or more files or directories are specified at the same time, and the last destination is an existing Directory, then it copies all the previously specified files or directories to this directory. If multiple files or directories are specified at the same time, and the last destination is not an existing Directory, an error message is displayed.
Parameters:
-A or -- archive: the effect of this parameter is the same as that of the "-dpR" parameter.
-B or -- backup is deleted to overwrite the backup before the target file. A backup string is added at the end of the backup file.
-D or -- no-dereference when copying a symbolic connection, the target file or directory is also established as a symbolic connection and points to the original file or directory connected to the source file or directory.
-F or -- force forcibly Copies files or directories, regardless of whether the target file or directory already exists.
-I or -- interactive ask the user before overwriting existing files.
-L or -- link establishes a hard connection to the source file instead of copying the file.
-P or -- preserve retains the attributes of the source file or directory.
-P or -- parents retains the path of the source file or directory.
-R recursive processing: processes the files in the specified directory along with subdirectories.
-R or -- recursive processing: All files in the specified directory are processed together with subdirectories.
-S or -- symbolic-link establishes a symbolic connection to the source file instead of copying the file.
-S <备份字尾字符串> Or -- suffix = <备份字尾字符串> After you use the "-B" parameter to back up the target file, a backup string is added at the end of the backup file. The default backup string is the symbol "~ ".
-U or -- update when this parameter is used, the file will be copied only when the source file is updated later than the target file or the target file with the corresponding names does not exist.
-V or -- verbose displays the command execution process.
-V <备份方式> Or -- version-control = <备份方式> After you use the "-B" parameter to back up the target file, a backup string will be added at the end of the backup file. This string can be changed not only by the "-S" parameter, when you use the "-V" parameter to specify different backup methods, different backup strings are generated.
-X or -- one-file-system: the file system in which the file or directory is copied must be the same as the file system in which the cp command is executed; otherwise, the file system will not be copied.
-- Help Online help.
-- Sparse = <使用时机> Set the time to save sparse files.
-- Version: displays the version information.
2. Copy command scp between different machines
Scp is similar to cp, but it runs on different machines.
Copy a file to another machine: scp-rf filename1 username@bak.benxiaohai.com:/usr/local/apache/htdocs/bak
The preceding Command copies the filename1 file (or folder) in the current directory as username to the/usr/local/apache/htdocs/bak directory on the machine bak.benxiaohai.com.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.