Home>Article>Operation and Maintenance> How to copy and rename files in Linux

How to copy and rename files in Linux

醉折花枝作酒筹
醉折花枝作酒筹 Original
2021-05-13 17:02:46 76293browse

In Linux, you can use the "cp option source file or directory target file or directory" command to copy files and rename them. The cp command is used to copy files or directories. If two or more files or directories are specified at the same time, and the final destination is an existing directory, it will copy all previously specified files or directories to this directory.

How to copy and rename files in Linux

#The operating environment of this tutorial: centos7 system, thinkpad t480 computer.

File/directory copy

cp [选项] 源文件或目录 目标文件或目录

This command can change the name while copying
eg,

cp abc.log def.log //abc.log 和 def.log 都是文件 cp -r test.quancheng/ quancheng //加 -r 参数,目录复制

Parameter description:

  • -a: means archive, also means copying all directories

  • -d: If the source file is a link file, copy the link file Attributes rather than the file itself

  • -f: force, if there are duplicates or other questions, the user will not be asked and forced to copy

  • -i: If the target file (destination) already exists, it will first ask whether to really operate when overwriting.

  • -l: Establish a hard link connection file , instead of copying the file itself

  • -p: Copy together with the file's attributes, instead of using the default attributes

  • -r: Copy recursively , used for directory copy operation

  • -s: Copy into a symbolic link file (symbolic link), that is, a "shortcut" file

  • -u: If the target file is older than the source file, update the target file

(recommended learning:linux tutorial)

The above is the detailed content of How to copy and rename files in Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn