mv
功能说明:
移动或剪切文件或目录,也可以改名
语法:
mv [-fiu] source destination
mv [options] source1 source2 source3... directory
参数:
-f :force强制的意思,若目标文件已经存在,不会询问而直接覆盖
-i :若目标文件已经存在,就会询问是否覆盖
-u :若目标文件已经存在且source比较新,才会更新
若有多个源文件或目录,则最后一个目标文件一定是目录
命令实践:
[root@yubinghost tmp]# mv yubing.txt /root
mv: overwrite `/root/yubing.txt'? y
[root@yubinghost tmp]# cd ;ll
total 8480
-rw------- 1 root root 939 Apr 3 12:38 anaconda-ks.cfg
-rw-r--r-- 1 root root 3422452 Apr 8 10:57 etc.tar.bz2
-rw-r--r-- 1 root root 5172939 Apr 8 10:55 etc.tar.gz
-rw-r--r-- 1 root root 23947 Apr 3 12:37 install.log
-rw-r--r-- 1 root root 3619 Apr 3 12:37 install.log.syslog
-rw-r--r-- 1 root root 18 Apr 5 14:43 o1
-rw-r--r-- 1 root root 0 Apr 5 14:36 oldboy.txt
-rw-r--r-- 1 root root 18 Apr 5 14:47 test.txt
drwxr-xr-x 2 root root 4096 Apr 11 11:53 yubing
-rw-r--r-- 1 root root 0 Apr 11 12:01 yubing.txt
[root@yubing ~]# alias
alias cp='cp -i'
alias l.='ls -d .* --color=tty'
alias ll='ls -l --color=tty'
alias ls='ls --color=tty'
alias mv='mv -i' 系统中已经有命令别名
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
[root@yubing ~]# unalias mv 暂时取消
[root@yubing ~]# alias
alias cp='cp -i'
alias l.='ls -d .* --color=tty'
alias ll='ls -l --color=tty'
alias ls='ls --color=tty'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
[root@yubing ~]# touch yubing
[root@yubing ~]# ll
total 60
-rw------- 1 root root 887 Apr 7 01:47 anaconda-ks.cfg
-rw-r--r-- 2 root root 255 Jan 6 2007 crontab1
lrwxrwxrwx 1 root root 12 Apr 8 04:06 crontab2 -> /etc/crontab
-rw-r--r-- 1 root root 23947 Apr 7 01:47 install.log
-rw-r--r-- 1 root root 3619 Apr 7 01:46 install.log.syslog
-rw-r--r-- 1 root root 0 Apr 12 06:58 yubing
[root@yubing ~]# mv yubing 提示后面没加目的文件
mv: missing destination file operand after `yubing'
Try `mv --help' for more information.
[root@yubing ~]# mv yubing /tmp
[root@yubing ~]# cd /tmp
[root@yubing tmp]# ll
total 12
drwx------ 2 root root 4096 Apr 12 06:58 ssh-QwmHGU2792
-rw-r--r-- 1 root root 0 Apr 12 06:58 yubing
[root@yubing ~]# cd /tmp
[root@yubing tmp]# mv -i yubing /root 加-i 想看下是否有互动,发现系统没有任何提示
[root@yubing tmp]# cd 翻阅资料,发现-i是在覆盖已存在的目标文件才会有提示
[root@yubing ~]# ll
total 60
-rw------- 1 root root 887 Apr 7 01:47 anaconda-ks.cfg
-rw-r--r-- 2 root root 255 Jan 6 2007 crontab1
lrwxrwxrwx 1 root root 12 Apr 8 04:06 crontab2 -> /etc/crontab
-rw-r--r-- 1 root root 23947 Apr 7 01:47 install.log
-rw-r--r-- 1 root root 3619 Apr 7 01:46 install.log.syslog
-rw-r--r-- 1 root root 0 Apr 12 06:58 yubing
[root@yubing ~]# cd /tmp
[root@yubing tmp]# ll
total 12
drwx------ 2 root root 4096 Apr 12 06:58 ssh-QwmHGU2792
-rw-r--r-- 1 root root 0 Apr 12 06:58 yubing
[root@yubing tmp]# cd /mnt
[root@yubing mnt]# touch yubing
[root@yubing mnt]# ll
total 4
-rw-r--r-- 1 root root 0 Apr 12 07:09 yubing
[root@yubing mnt]# touch yubing
[root@yubing mnt]# mv -i yubing /tmp/ 果然,覆盖时会有提示
mv: overwrite `/tmp/yubing'? y
[root@yubing mnt]#
[root@yubing mnt]# alias mv='mv -i' 设置命令别名
[root@yubing mnt]# alias
alias cp='cp -i'
alias l.='ls -d .* --color=tty'
alias ll='ls -l --color=tty'
alias ls='ls --color=tty'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
[root@yubing mnt]# touch yubing
[root@yubing mnt]# mv yubing /tmp/
mv: overwrite `/tmp/yubing'? n
[root@yubing mnt]# mv -f yubing /tmp/ -f 强制,所以没有任何提示
[root@yubing mnt]# ll
total 0
转载于:https://blog.51cto.com/yubing208/1196140