Linux basic commands -cp

cp command is used to copy one or more source files or directory to the specified file or directory object. Or the next directory already exists it can copy the source file into a single file name designated specific file. cp command also supports copying multiple files at the same time, when a copy multiple files, object files argument must be a directory that already exists, or an error.

grammar

cp (option) (parameters)
Options
-a: effect of this parameter and specify " -dpR " the same parameters;
 - D: When copying symbolic link, the target file or directory is a symbolic link is also established, and connected to a source point to the original document file or directory or directories ;
- f: forced to copy a file or directory, regardless of whether the target file or directory already exists;
 - i: first ask the user before overwriting existing files;
 - L: source file hard links instead of copying files;
 - the p-: reserved attributes of the source file or directory;
 -R & lt / R & lt: recursive processing, all files in the specified directory and subdirectories processed together;
 - S: Creates a symbolic link to the source file, rather than copy the file;
 - U: use this when compared to only update the target file in the source file or change the time corresponding to the name of each destination file does not exist after parameter before copying files;
 - S: when you back up files with the specified suffix "sUFFIX" instead of the file the default suffix;
 - b: before the target file will overwrite the existing file backup target;
 -v: operation command shown in detail.

parameter

  • Source File: Develop list of source files. By default, cp command can not copy a directory, if you want to copy a directory, you must use -Roption;
  • Target file: specify the target file. When the "source" for multiple file, requires "destination file" specified directory.

Examples

If you copy a file to a target file, the target file already exists, then the contents of the target file will be destroyed. In this command, all parameters can be either an absolute pathname, or a relative path name. Typically used points .or little ..form. For example, the following command copies the specified file to the current directory:

cp ../mary/homework/assign .
All files in the specified target directory must already exist, cp command can not create the directory. If you do not have permission to copy the file, the system will display an error message.

The document file is copied to a directory /usr/men/tmpunder, and renamed file1

cp file /usr/men/tmp/file1
The directory /usr/mencopy all files to the directory and its subdirectories under /usr/zhthe
Chp in -r / Usr / / Usr / Sh
Interactively directory /usr/mencopy in all the m .c files starting with the directory /usr/zhin the
cp -i /usr/men m*.c /usr/zh
We use under Linux cp command to copy files when sometimes need to cover some of the same file, the file will be covered when prompted: need to keep press Y to determine the execution coverage. The number of files much better, but if hundreds of press Y estimated to be vomiting blood, so toss a half-day to summarize one method:
cp aaa / * / bbb
Copy all to the next directory aaa / bbb directory, then if there is under / bbb aaa directory and file of the same name, we need to press Y to confirm and will skip the subdirectories under the aaa directory.
cp -r aaa / * / bbb
The still need to press Y to confirm the action, but there is no ignoring the subdirectory.
cp -r -a aaa / * / bbb
Still need to press Y to confirm the action, and the aaa directory and sub-directories and file attributes are also passed to / bbb.
\ Cp -r -a aaa / * / bbb
Success, there is no prompt, press Y, passed directory properties, not to skip the directory.

Guess you like

Origin www.cnblogs.com/lj7xun/p/10983434.html