mv 移动和重命名文件
选项:
-i #当文件已经存在时,移动的时候,提示是否覆盖目标文件 系统自带别名
-f #强制覆盖,不提示
-t #把原文件的位置跟目标目录的位置进行调换
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
[root@clf ~]# ll /opt/ total 12 -rw-r--r--. 1 root root 501 Jul 9 09:28 fstab -rw-r--r--. 1 root root 158 Jul 9 09:28 hosts -rw-r--r--. 1 root root 51 Jul 9 09:28 resolv.conf [root@clf ~]# mv /opt/hosts ./ [root@clf ~]# ll total 4 -rw-r--r--. 1 root root 158 Jul 9 09:28 hosts [root@clf ~]# ll /opt/ total 8 -rw-r--r--. 1 root root 501 Jul 9 09:28 fstab -rw-r--r--. 1 root root 51 Jul 9 09:28 resolv.conf [root@clf ~]# cp -r /mnt/ /opt/ [root@clf ~]# ll /opt/ total 8 -rw-r--r--. 1 root root 501 Jul 9 09:28 fstab drwxr-xr-x. 2 root root 6 Jul 9 09:59 mnt -rw-r--r--. 1 root root 51 Jul 9 09:28 resolv.conf [root@clf ~]# mv /opt/mnt/ ./ #在移动目录的时候,不需要加任何的选项 [root@clf ~]# ll total 4 -rw-r--r--. 1 root root 158 Jul 9 09:28 hosts drwxr-xr-x. 2 root root 6 Jul 9 09:59 mnt [root@clf ~]# cp /etc/hosts /opt/ [root@clf ~]# ll /opt/ total 12 -rw-r--r--. 1 root root 501 Jul 9 09:28 fstab -rw-r--r--. 1 root root 158 Jul 9 10:00 hosts -rw-r--r--. 1 root root 51 Jul 9 09:28 resolv.conf [root@clf ~]# ll total 4 -rw-r--r--. 1 root root 158 Jul 9 09:28 hosts drwxr-xr-x. 2 root root 6 Jul 9 09:59 mnt [root@clf ~]# mv /opt/hosts ./ #文件已经存在时,提示是否覆盖 mv: overwrite ‘./hosts’? n [root@clf ~]# alias alias cp='cp -i' alias egrep='egrep --color=auto' alias fgrep='fgrep --color=auto' alias grep='grep --color=auto' alias l.='ls -d .* --color=auto' alias ll='ls -l --color=auto' alias ls='ls --color=auto' alias mv='mv -i' #强制覆盖不提示 [root@clf ~]# \mv /opt/hosts ./ #强制覆盖不提示 [root@clf ~]# mv -f /opt/hosts ./ [root@clf ~]# ll total 4 -rw-r--r--. 1 root root 158 Jul 9 10:00 hosts drwxr-xr-x. 2 root root 6 Jul 9 09:59 mnt [root@clf ~]# ll /opt/ total 8 -rw-r--r--. 1 root root 501 Jul 9 09:28 fstab -rw-r--r--. 1 root root 51 Jul 9 09:28 resolv.conf [root@clf ~]# mv -t /opt/ ./hosts [root@clf ~]# ll total 0 drwxr-xr-x. 2 root root 6 Jul 9 09:59 mnt [root@clf ~]# ll /opt/ total 12 -rw-r--r--. 1 root root 501 Jul 9 09:28 fstab -rw-r--r--. 1 root root 158 Jul 9 10:00 hosts -rw-r--r--. 1 root root 51 Jul 9 09:28 resolv.conf #在移动文件或者目录的过程中,修改了名称 [root@clf ~]# mv mnt/ mot [root@clf ~]# ll total 0 drwxr-xr-x. 2 root root 6 Jul 9 09:59 mot [root@clf ~]# mv /opt/hosts ./host [root@clf ~]# ll total 4 -rw-r--r--. 1 root root 158 Jul 9 10:00 host drwxr-xr-x. 2 root root 6 Jul 9 09:59 mot |