Copying files and folders in Linux

Source: Internet
Author: User
When operating Linux remotely, there are many powerful shell commands that can help us. copying files and folders is a very powerful function. 1. copy command cp on the same machine. Replay

When operating Linux remotely, there are many powerful shell commands that 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. The command for cp is as follows:

Syntax:Cp [-abdfilpPrRsuvx] [-S <备份字尾字符串> ] [-V <备份方式> ] [-- Help] [-- spares = <使用时机> ] [-- Version] [source file or directory] [target file or directory] [Target Directory]

Note:The cp command is used to copy files or directories. for example, if you specify more than two files or directories at the same time, and the final 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.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.