One day a linux base command switch directory Move command MV

Source: Internet
Author: User
Tags syslog

MV : Move a file or directory

1 , command format

MV [option] SRC ( source directory or file ) DEC ( destination directory )

2 , command functions

MV linux frequently used commands in the system to back up files or directories.

MV command to finish renaming or move files, if renamed, the source file can only have one Span style= "font-family: ' Times New Roman ', Serif;color: #333333; background: #FFFFFF;" > ( can also be a directory name ) When you move a file, the source file can be more than one, the destination directory When moving files across file systems, MV copy first, then delete the original file, and the link to the file will be lost.

3 , common options

- b : Before moving, if the target file is moved, back up the destination file before moving

- F : Forced move, with file same overwrite not prompted

- I. : Interactive move for the presence of a target file, asking the Administrator

- N : Does not overwrite destination file if the target file exists

- T : For multiple cases where the source file is present, the destination file is in front of the source file or directory after

- u : If the target file is newer than the source file when moving the file, do not move

- v,--verbose : Show more information

--help : Help

--version : Show command version

4 , common examples

Example 1 : Move Script info.sh to the /sh in the catalog

command: MV Info.sh/sh

[[email protected]~]# lsanaconda-ks.cfg  iflogin.sh  info.sh  install.log  install.log.syslog  yum.log[[email protected]~] # mv info.sh /sh[[email protected]~]# ls /sh/info.sh[[email protected]~]# 

Example 2 : The /sh under the directory info.sh renamed, changed to userinfo.sh

command: mv/sh/info.sh/sh/userinfo.sh

[Email protected]~]# mv/sh/info.sh/sh/userinfo.sh[[email protected]~]# ls/shuserinfo.sh[[email protected]~]#

Example 3 : Move multiple files to /sh directory, and display the Mobile information

command: mv-v iflogin.shautoadd.sh autodel.sh/sh

[[email protected]~]# lsanaconda-ks.cfg  autoadd.sh  autodel.sh  iflogin.sh  install.log install.log.syslog     Yum.log[[email protected]~]# mv -v autoadd.sh autodel.sh iflogin.sh /sh ' autoadd.sh '->  '/sh/autoadd.sh ' autodel.sh '->  '/sh/autodel.sh ' ' iflogin.sh '->  '/sh/ Iflogin.sh ' [[email protected]~]# ls /sh/autoadd.sh  autodel.sh iflogin.sh   userinfo.sh[[email protected]~]# 

through the above ls command to know that in the current directory there are 3 one to SH At the end of the file, and are all the files we want to move, we can use the following command, or we can do the above

Mv-v *.sh/sh

Example 4 : The target file exists, then the target file is backed up, and the file is moved over and the detailed mobile information is displayed.

command: MV-BV userinfo.sh/sh

[[Email protected]~]# ll /sh/total 8-rw-r--r--. 1 root root 276 dec  10 22:13 USERINFO.SH[[EMAIL PROTECTED]~]# LLTOTAL 48-RW-------. 1 root  root  1442 dec  7 21:28 anaconda-ks.cfg-rw-r--r--. 1 root  Root 27312 dec  7 21:28install.log-rw-r--r--. 1 root root  7572  dec  7 21:27 install.log.syslog-rw-r--r--. 1 root root   276  DEC 10 22:12USERINFO.SH-RW-------. 1 root root     0  Dec 9 20:39 yum.log[[email protected]~]# mv -bv userinfo.sh /shmv:o verwrite  '/sh/userinfo.sh '?  y ' userinfo.sh '->  '/sh/userinfo.sh '   (backup:  '/sh/ Userinfo.sh~ ') [[Email protected]~]#[[email protected]~]# ll /sh/total 12-rw-r--r--. 1  root root 276 Dec 10 22:12 userinfo.sh-rw-r--r--. 1 root root 276 dec 10 22:13  userinfo.sh~[[email protected]~]#

Example 5 : The destination file does not move if it exists and is newer than the source file

command: Mv-uv userinfo.sh/sh

[Email protected]~]# lltotal 52-rw-r--r--. 1 root root 27312 Dec 7 21:28install.log-rw-r--r--. 1 root root 7572 Dec 7 21 : Install.log.syslog-rw-r--r--. 1 root root 276 Dec 22:12userinfo.sh-rw-------. 1 root root 0 Dec 9 20:39 yum.lo G[[email protected]~]# ll/sh/total 4-rw-r--r--. 1 root root 276 Dec 22:13 userinfo.sh[[email protected]~]# mv-u Userin Fo.sh/sh/[[email protected]~]# ll/sh/total 4-rw-r--r--. 1 root root 276 Dec 22:13 userinfo.sh[[email protected]~]#

Example 6 : Does not move if the file exists

command: mv-n userinfo.sh/sh

[[email protected]~]# lltotal 5-rw-r--r--. 1 root  root 27312 dec  7 21:28install.log-rw-r--r--. 1 root root   7572 dec  7 21:27 install.log.syslog-rw-r--r--. 1 root root    276 DEC 10 22:12USERINFO.SH-RW-------. 1 root root      0 dec  9 20:39 yum.log[[email protected]~]# ll /sh/total 4- Rw-r--r--. 1 root root 276 dec 10 22:13 userinfo.sh[[email protected]~] #[[email protected]~]# mv -n userinfo.sh /sh/ [[email protected] ~]#  ll /sh/total 4-rw-r--r--. 1 root root 276 dec 10 22:13  userinfo.sh [[email protected] ~]# 

7 : Multiple options are used at the same time, after options are in effect

[[email protected]~]# lltotal 5-rw-r--r--. 1 root  root 27312 dec  7 21:28install.log-rw-r--r--. 1 root root   7572 dec  7 21:27 install.log.syslog-rw-r--r--. 1 root root    276 DEC 10 22:12USERINFO.SH-RW-------. 1 root root      0 dec  9 20:39 yum.log[[email protected]~]# ll /sh/total 4- Rw-r--r--. 1 root root 276 dec 10 22:13 userinfo.sh[[email protected]~] # mv -v -n -f userinfo.sh /sh/' userinfo.sh '->  '/sh/userinfo.sh ' [[Email  protected]~]# ll /sh/total 8-rw-r--r--. 1 root root 276 dec 10  22:20 userinfo.sh[[email protected]~]# 

Example 8 : Move Directory

command: Dir1 DR2

[[Email protected]~]# ll test/total 4-rw-r--r--. 1 root root   0  dec 10 22:05 autoadd.sh-rw-r--r--. 1 root root   0 dec  10 22:05 autodel.sh-rw-r--r--. 1 root root 239 dec  9 21:25  Iflogin.sh[[email protected]~]# ll /sh/total 8-rw-r--r--. 1 root root   276 dec 10 22:20 userinfo.sh-rw-r--r--. 1 root root  276 dec  10 22:13userinfo.sh~[[email protected]~]# mv test/ /sh/test[[email protected]~]#  ll /sh/total 12drwxr-xr-x.2 root root 4096 Dec 10 22:29  Test-rw-r--r--. 1 root root  276 dec 10 22:20 userinfo.sh-rw-r--r--. 1  root root  276 dec 10 22:13userinfo.sh~[[email protected]~]#

description:

If the catalog Dir2 does not exist, the directory Dir1 renamed to Dir2 ; otherwise, the Dir1 move to Dir2 the.


This article is from "Linux rookie" blog, please be sure to keep this source http://geekb0y.blog.51cto.com/10743719/1881562

Switch directory of a Linux base command one day move command MV

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.