Linux commands (4)---cp, install, MV, RM commands

Source: Internet
Author: User

CP command: cp-copy files and directories

"Function" copy function, commonly used to do service configuration file backup


CP means copy, is the copy of the abbreviation, copy the file and the intention to rename the file, when copying multiple files, the target must be an existing directory, or the copy process will be error, theinstall command here does not describe the usage can be viewed The man document, similar to the CP usage, uses the CP command in several cases:

When the source file is a normal file:

grammar; CP options SRC Dest[src|dir]

if the target is a file that does not exist: Creates a new destination file and populates the source file with the destination file

if the target exists:

is a normal file: overwrites the source file to the destination file, prompting for overwrite , default -I interaction

is a catalog file: Saves the source file to the destination directory and creates a new file with the same name to populate the content

When the source file is a catalog file:

Syntax: CP option DIRDEST[DIR]

If the source file is a directory, you must use the option –r to copy otherwise error, indicating recursive replication

if the target does not exist: creates the specified directory, copying all the contents of the source file to the specified destination

if the target exists:

Target is document: Direct error, not explanation

Target is directory: Copy to this directory


MV Command: Mv-move (rename) files

function

MV Command Table move , rename, cut the meaning of the move 's abbreviation, you can move the file to the specified directory, you can rename the file name, moving conditions are the same as the CP condition

Syntax: mvoption src dest

RM command: Rm-remove files or Directorie

function

RmDir and RM command both mean delete meaning,rmdir can only delete empty directory, of course ,-p can delete the hierarchy directory, but can only delete single-level directory, if it is multi-level cannot be deleted. the RM command is a command that Linux often uses to delete files and directories, which must be used with great care, otherwise the world will be clean if one is careless. RmDir not stated here

syntax:RM Options Dests



"Options" CP command

-a--archive=-dr; an archive that represents all the information that holds a file, such as timestamp, permissions, symbolic links, etc.-D--no-dereference: Indicates that the connection is retained on copy-I--interactive: interactive, prompts whether the message confirms the message with the-F opposite-R- -recursive: Indicates that recursive replication is usually used when the source file is a directory, same as-R

The "Options" MV command

-I:--interactive means overwrite before asking is overwrite-f:--force means not asking before overwriting, direct overwrite, unsafe


The "Options" RM command

-F:--force forced deletion of the meaning of-r:--recursive recursive deletion of meaning-I: Do not delete a file requires prompt, such as: A directory of 100,000 files you just cry.


"Instance 1" source file is not directory copy, renaming several ways

copy [[email protected] ~]# cp/etc/passwd/tmp///copy etc passwd file to tmp directory [[email protected] ~]# ls/tmpdir1 dir2 dir3 pas Swd[[email protected] ~]#
rename [[email protected] tmp]# lsdir1 dir2 dir3 passwd[[email protected] tmp]# cp passwd dir1/pawd//Copy current directory passwd to Dir1 directory rename [[email protected] tmp]# ls dir1pawd[[email protected] ~]#[[email protected] tmp]# lsdir1 dir2 dir3 passwd[[email PR Otected] tmp]# CP Passwd{,.bak}
When modifying the configuration file, the most commonly used replication and renaming, and later to change the service profile is commonly used [[email protected] tmp]# lsdir1 dir2 dir3 passwd passwd.bak//source files are also renamed a backup file [Emai L protected] ~]#//when copying multiple files The destination file must be present in advance and is a directory otherwise error [[email protected] tmp]# lsdir1 dir2 dir3 dir4 passwd passwd.bak[[email Pro Tected] tmp]# CP passwd PASSWD.BAKDIR5//directory DIR5 and does not exist in advance error cp:target ' DIR5 ' is not a directory[[email protected] tmp]# CP p ASSWD passwd.bakdir4//directory DIR4 pre-existing replication successful [[email protected] tmp]# ls dir4passwd passwd.bak[[email protected]~]#


"Instance 2" CP Command copy Directory

[Email protected] tmp]# cp-r/etc Etc.bak//copy directory etc Rename to etc.bak[[email protected] tmp]# lsdir1 dir2 dir3 dir4 etc.ba K passwd Passwd.bak[[email protected] tmp]#[[email protected] tmp]# cp-r/etc/rc.ddir4///Copy the RC.D to DIR4 directory under the ETC directory [[Emai L protected] tmp]# ls dir4passwd passwd.bak rc.d[[email protected]]#

"Instance 3" MV Mobile Directory

[[email protected] tmp]# lsdir1 dir2  dir3   dir4 etc.bak  passwd  passwd.bak[[email protected] tmp]#  mv dir1 dir2     //Move the directory Dir1 to the dir directory [[email protected] tmp]#  Lsdir2 dir3  dir4  etc.bak passwd  passwd.bak[[email protected]  tmp]# ls dir2         //View Validation Dir1 dira[[email  protected] tmp]#[[email protected] tmp]# lsdir2 dir3  dir4   etc.bak passwd  passwd.bak[[email protected] tmp]# mv dir3 dir2/ data  //directory Dir3 move to Dir2 and rename to Data directory [[Email protected] tmp]# ls dir2data dir1   dira[[email protected]]# 

"Instance 4" MV Command move file and-I query prompt

[[email protected] ~]# tree/tmp/tmp|--filename '--test '--filename1 directory, 2 files[[email protected] ~]# cd/tmp [[email protected] tmp]# mv-i test/mv:missing destination file operand after ' test/' Try ' mv--help ' for more information . [Email protected] tmp]# mv-i filename test/mv:overwrite ' test/filename '? Yes[[email protected] tmp]# ls Test//Of course there is a need to verify that files need to view file contents filename


"Instance 5" RM command

Note: It is recommended to do exercises in the/tmp directory during study or practice, and do not use this command to do practice [[email protected] tmp]# lsdir2 dir4   etc.bak  passwd passwd.bak[[email protected] tmp]# rm -f  passwdpasswd.bak   //Delete This two files at the same time [[email protected] tmp]# lsdir2 dir4   etc.bak[[email protected] tmp]#[[email protected] tmp]# lsdir2 dir4   etc.bak[[email protected] tmp]# rm -rf dir2etc.bak    // Delete Two directories and delete all files in the directory [[email protected] tmp]# lsdir4[[email protected] tmp]#// Try the asterisk (*) file under the root directory [[email protected] /]# ls  *  boot     dev home  lib64       media mnt  opt    root selinux  sys  usrbin  cgroup  etc  lib   lost+found  misc    net proc  sbin  srv     tmp  var[[email  protected]/]#


This article is from the "Perthon" blog, make sure to keep this source http://perthon.blog.51cto.com/10484057/1761848

Linux commands (4)---cp, install, MV, RM commands

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.