"My Linux, I am the Master" Linux system file operation CP, RM, MV detailed

Source: Internet
Author: User

The operation of the text file is very basic and important, and you will be more comfortable with manipulating the text after mastering them. To copy a file, use the CP command, the CP command can be used in many ways, in addition to simple replication, you can also establish a shortcut to compare the old and new two files to determine whether to update, and copy the entire directory of files and other functions. For moving directories and files, use MV (move), which can also be used as a direct file rename function. As for deleting files, using RM (remove) This command, let's take a look at the specific
"1" Copy files or directories: CP
format:
CP [-ADFILPRSU] source file destination file
CP [-adfilprsu] source1 source2 source3 ... directory
options and Parameters:
-A: Copy files while retaining source file attributes
-D: If the source file is an L-link type file, copy the linked text of the linked file instead of copying the file itself
-F: Indicates that there is no need to interact with the system at the time of replication, directly force the operation without asking
-I: Indicates the process of human-computer interaction during replication, and if the file exists, there will be an action to ask before overwriting the file
-L: Create a hard link to a file, and the hard link value will change instead of copying the file itself
-P: Together with the file's attribute information, including the permissions, the owner group, the time to copy the past, rather than the default properties
-R: Recursive replication, commonly used for directory replication behavior
-S: Create a soft link to a file, or a symbolic link (symbolic link), i.e. a shortcut file
-U: Copy only if the source file is newer than the target file, which is equivalent to the update
Example:
(1) CP ~/.BASHRC/TMP/BASHRC
Copy with default properties of the CP command
(2) Cp-i ~/.BASHRC/TMP/BASHRC
With the I option, before overwriting the file, the user is asked to confirm that the user can make two confirmations by N or Y.
(3) Cp-r/etc/tmp
-r means to copy all files under the/etc directory to the/tmp directory using recursive replication of files under directory
"2" Delete file or directory: RM
format:
RM [-fir] File or directory
options and Parameters:
-F: Delete the file or directory, do not interact with the user, directly delete the operation without asking
-I: interactive mode, before deleting, asks whether to delete the operation
-R: Recursive deletion, that is, when a directory is deleted, all files under the directory are deleted together
Example:
(1) Rm-i BASHRC
If you add the-I option, you will be asked to avoid deleting the wrong file.
(2) Rm-r/tmp/etc
Delete all files in the/tmp/etc directory, recursively delete
(3\rm-r/tmp/etc
Precede the command with a backslash, you can ignore the default option of Alias, the default option for RM is rm-i, and after the backslash, not the default and user interaction
"3" Move the file or directory, rename the file or directory: MV
format:
MV [-FIU] source destination
options and Parameters:
-F: Forced to move the meaning, if the target file already exists, will not ask but directly overwrite
-I: If the target file already exists, you will be asked to overwrite
-U: Updates if the target file already exists and the source data is newer
Example:
(1) MV Mvtest Mvtest2
Implementing renaming of directory names
(2) MV Bashrc1 BASHRC2 Mvtest2
Set up two files and move them all to the directory Mvtest2

"My Linux, I am the Master" Linux system file operation CP, RM, MV detailed

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.