Copy 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. 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 above command www.2cto.com to copy the folder. For example, cp-rf dic1 and dic2.

The command for more details about cp is as follows: Syntax: cp [-abdfilpPrRsuvx] [-S <backup character string>] [-V <backup mode>] [-- 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 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. Parameter: www.2cto.com-a or -- archive. -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, whether or not the target file or directory already exists-I or -- interactive overwrites existing files, ask the user. -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 <backup suffix string> or -- suffix = <backup suffix string> 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 character 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 <backup mode> or -- version-control = <backup mode> use the "-B" parameter to back up the target file. A backup string is added at the end of the backup file, this string can be changed not only by the "-S" parameter, but also by using the "-V" parameter to specify different backup methods. -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. Www.2cto.com -- help Online help. -- Sparse = <> sets the time to save sparse files. -- Version: displays the version information.
2. The usage of the command scp between different machines is similar to that of the cp, but it is just running between different machines. Copy a file to another machine: scp-rf filename1 username @:/usr/local/apache/htdocs/bak the command above indicates to put the filename1 file (or folder) in the current directory) copy the username to the/usr/local/apache/htdocs/bak directory on this machine. By-syc

Related Article

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.