mv - move (rename) files
man mv 查看文檔
常用命令
mv -ifu 源文件/源碼目錄 目標文件/目標目錄
-i 如果文件存在,提示是否覆蓋
-f 強制覆蓋
-u 如果目標文件存在,源文件是最新的,才移動
栗子 : f1 、f2, 代表文件 d1、d2 代表目錄
mv f1 f2 當f2不存在的時候,f1 重命名爲f2,如果存在f1重名f2 並且覆蓋f2
mv f1 d1 當d1不存在,f1重命名爲d1 ,如果存在則移動到d1目錄中
mv d1 d2 當d2不存在,d1重命名爲d2,如果存在則移動到d2目錄
mv d1 f1 當f1不存在,d1重命名爲f1,如果存在這報錯cannot overwrite non-directory install.log' with directory
java’
root@guofeng ~
# ll
total 432
-rw-------. 1 root root 1073 May 26 22:40 anaconda-ks.cfg
-rw-r--r--. 1 root root 0 Jun 1 09:05 f1.txt
-rw-r--r--. 1 root root 22179 May 26 22:40 install.log
-rw-r--r--. 1 root root 5890 May 26 22:38 install.log.syslog
-rw-r--r--. 1 root root 400753 May 31 09:38 wget-log
root@guofeng ~
# mv f1.txt f2.txt
root@guofeng ~
# ll
total 432
-rw-------. 1 root root 1073 May 26 22:40 anaconda-ks.cfg
-rw-r--r--. 1 root root 0 Jun 1 09:05 f2.txt
-rw-r--r--. 1 root root 22179 May 26 22:40 install.log
-rw-r--r--. 1 root root 5890 May 26 22:38 install.log.syslog
-rw-r--r--. 1 root root 400753 May 31 09:38 wget-log
mv f1 f2 如果f2 存在會提示是否覆蓋 mv -f 強制不會提示
root@guofeng ~
# mv f1.txt f2.txt
mv: overwrite `f2.txt'? y
root@guofeng ~
# mv -f f1.txt f2.txt
mv: cannot stat `f1.txt': No such file or directory
root@guofeng ~
# ll
total 432
-rw-------. 1 root root 1073 May 26 22:40 anaconda-ks.cfg
-rw-r--r--. 1 root root 0 Jun 1 09:09 f1.txt
-rw-r--r--. 1 root root 0 Jun 1 09:08 f2.txt
-rw-r--r--. 1 root root 22179 May 26 22:40 install.log
-rw-r--r--. 1 root root 5890 May 26 22:38 install.log.syslog
-rw-r--r--. 1 root root 400753 May 31 09:38 wget-log
root@guofeng ~
# mv -f f1.txt f2.txt
root@guofeng ~
# ll
total 432
-rw-------. 1 root root 1073 May 26 22:40 anaconda-ks.cfg
-rw-r--r--. 1 root root 0 Jun 1 09:09 f2.txt
-rw-r--r--. 1 root root 22179 May 26 22:40 install.log
-rw-r--r--. 1 root root 5890 May 26 22:38 install.log.syslog
-rw-r--r--. 1 root root 400753 May 31 09:38 wget-log