linux mv命令

 

mv命令是最后是否带“/”的区别:

 

/root/file/file01/目录下有一个123.txt文件,需要移动到/root/file01目录下;

# ls /root/file/file01/
123.txt
# ls /root/file01/
# 

总结:

正确的命令是:

直接移动目录下的文件

# mv /root/file/file01/* /root/file01/
# ls /root/file/file01/
# ls /root/file01/
123.txt
#

  或者移动整个文件夹,但是文件夹如果出现同名,会提示覆盖;

# mv /root/file/file01/ /root/
mv: overwrite ‘/root/file01’? y
# ls /root/file01/
123.txt
# ls /root/file

 

容易出错的命令:

# mv 需要移动的文件夹 移动到的目标目录

# mv /root/file/file01/ /root/file01
# mv /root/file/file01/ /root/file01/
# mv /root/file/file01 /root/file01
# mv /root/file/file01 /root/file01/
# ls /root/file01/file01/
123.txt

  这4个效果一样,都是直接把/root/file目录下的整个“file01”文件夹,移动到了 /root/file01目录下 ,而不是我们所想的 /root/file01

 
# mv /root/file /root/file01
# ls /root/file01/file/file01/
123.txt

  而这个命令,却是直接把  /root目录下的file文件夹移动到了 /root/file01目录下;








posted @ 2022-05-20 15:20  凡事预则立,不预则废  阅读(216)  评论(0编辑  收藏  举报