linux命令mv作用,Linux命令之mv

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值