mv命令 移动文件或目录、重命令,是 move的缩写 centos
格式: ssh
mv [选荐] 源文件或目录 目标文件或目录 ide
-b 先备份再覆盖文件或目录 post
-f 目标文件已经存在时,不询问直接覆盖 centos7
-i 目标文件已经存在时,先询问是否覆盖,mv默认是加此参数的别名 spa
-u 目标文件已经存在,且source比较新才会更新 文档
-t -target-directory=DIRECTORY move all source arguments into DIRECTORY指定mv的目标目录,该选项适用于移动多个源文件到一个目录的状况,此时目标目录在前,源文件在后 get
a.更名 it
[root@24centos7-01 test]# touch test.txt class
[root@24centos7-01 test]# ls
test.txt
[root@24centos7-01 test]# mv test.txt showtime.txt
[root@24centos7-01 test]# ls
showtime.txt
b.移动目录
直接移动目录
[root@24centos7-01 tmp]# ls /tmp/
profile showtime test
[root@24centos7-01 tmp]# ls /root/
anaconda-ks.cfg
[root@24centos7-01 tmp]# mv ./showtime/ /root/
[root@24centos7-01 tmp]# ls /root/
anaconda-ks.cfg showtime
目标目录存在,移动至目标目录内
[root@24centos7-01 tmp]# mkdir tee
[root@24centos7-01 tmp]# ls
profile showtime.txt tee test
[root@24centos7-01 tmp]# ls ./test/
1.txt 2.txt 3.txt
[root@24centos7-01 tmp]# mv tee/ test/
[root@24centos7-01 tmp]# ls test/
1.txt 2.txt 3.txt tee
c.将多个文件移动到同一个目录
[root@24centos7-01 tmp]# touch 1.txt 2.txt 3.txt
[root@24centos7-01 tmp]# ls
1.txt 2.txt 3.txt profile test
[root@24centos7-01 tmp]# mv 1.txt 2.txt 3.txt ./test/
[root@24centos7-01 tmp]# ls ./test/
1.txt 2.txt 3.txt
d.将文件更名,若是目标名已存在,则询问是否覆盖
[root@24centos7-01 tmp]# ls
error.log profile showtime.txt test
[root@24centos7-01 tmp]# echo "showtime" > showtime.txt
[root@24centos7-01 tmp]# echo "error" > error.log
[root@24centos7-01 tmp]# cat showtime.txt
showtime
[root@24centos7-01 tmp]# cat error.log
error
[root@24centos7-01 tmp]# mv error.log showtime.txt
mv:是否覆盖"showtime.txt"? y
[root@24centos7-01 tmp]# ls
profile showtime.txt test
[root@24centos7-01 tmp]# cat showtime.txt
error
e.覆盖前作简单备份
[root@24centos7-01 tmp]# ls ./test/
1.txt 2.txt 3.txt
[root@24centos7-01 tmp]# ls /tmp/
profile showtime.txt tee test
[root@24centos7-01 tmp]# touch 1.txt
[root@24centos7-01 tmp]# echo " test" > 1.txt
[root@24centos7-01 tmp]# echo "1.txt" > ./test/1.txt
[root@24centos7-01 tmp]# cat 1.txt
test
[root@24centos7-01 tmp]# cat ./test/1.txt
1.txt
[root@24centos7-01 tmp]# mv -b 1.txt ./test/1.txt
mv:是否覆盖"./test/1.txt"? y
[root@24centos7-01 tmp]# cat ./test/1.txt
test
[root@24centos7-01 test]# ls
1.txt 1.txt~ 2.txt 3.txt
文档查看cat
cat 顺序查看文档
[root@24centos7-01 tmp]# cat showtime.txt
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-bus-proxy:x:999:997:systemd Bus Proxy:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:998:996:User for polkitd:/:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
chrony:x:997:995::/var/lib/chrony:/sbin/nologin
-n查看文档时显示行号
[root@24centos7-01 tmp]# cat -n showtime.txt
1 ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
2 nobody:x:99:99:Nobody:/:/sbin/nologin
3 systemd-bus-proxy:x:999:997:systemd Bus Proxy:/:/sbin/nologin
4 systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
5 dbus:x:81:81:System message bus:/:/sbin/nologin
6 polkitd:x:998:996:User for polkitd:/:/sbin/nologin