Linux第二周学习笔记

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux第二周学习笔记相关的知识,希望对你有一定的参考价值。

Linux第二周学习笔记(6)


2.12.MV命令

mv命令:用来对文件或目录重新命名,或者将文件从一个目录移到另一个目录中。

---------------------------------------------------------------------------------------------

文件更名:把/tmp/目录里面的01.txt改名为01.1.txt

[[email protected] ~]# ls /tmp/

01.txt

daizhihong

daizhihong1

daizhihong3

ks-script-9pf2WE

yum.log

[[email protected] ~]# cd /tmp/

[[email protected] tmp]# mv 01.txt 01.1.txt(把01.txt名称改为01.1.txt

[[email protected] tmp]# ls /tmp/

01.1.txt

daizhihong

daizhihong1

daizhihong3

ks-script-9pf2WE

---------------------------------------------------------------------------------------------

把文件移动到其它分区并且改名字:

/tmp/目录下的01.1.txt文件移动到root分区下并且把01.1.txt改名为02.txt

[[email protected] tmp]# ls

01.1.txt

daizhihong

daizhihong1

daizhihong3

ks-script-9pf2WE

 [[email protected] tmp]# mv 01.1.txt /root/02.txt(把/tmp/目录下的01.1.txt文件移动到root分区下并且把01.1.txt改名为02.txt

[[email protected] tmp]# ls

daizhihong

daizhihong1

daizhihong3

ks-script-9pf2WE

[[email protected] tmp]# ls /root/

02.txt  anaconda-ks.cfg01.1.txt已经移动到/root/目录下并且更名为02.txt

---------------------------------------------------------------------------------------------

把文件移动到目录下:把/tmp/目录下的11.txt文件移动到/tmp/daizhihong/目录下

[[email protected] tmp]# tree daizhihong/

daizhihong/

0 directories, 0 files

[[email protected] tmp]# ls

11.txt

daizhihong

daizhihong1

daizhihong3

ks-script-9pf2WE

yum.log

[[email protected] tmp]# mv 11.txt daizhihong/

 [[email protected] tmp]# ls

daizhihong

daizhihong1

daizhihong3

ks-script-9pf2WE

yum.log

[[email protected] tmp]# tree daizhihong/

daizhihong/

└── 11.txt

0 directories, 1 file

-----------------------------------------------------------------------------------------------

-i”的参数:在我们使用which查询命令绝对路径的时候会出现一个“-i”的参数,这个参数的意义是一个安全参数,询问是否执行就是因为加了“-i”的参数

[[email protected] tmp]# touch 11.txt

[[email protected] tmp]# ls

11.txt

daizhihong

daizhihong1

daizhihong3

ks-script-9pf2WE

yum.log

[[email protected] tmp]# mv 11.txt daizhihong/

mv:是否覆盖"daizhihong/11.txt" n((加了“-i”参数就会提示是否需要覆盖或者执行rm命令的时候是否需要删除,所以“-i”是一个安全参数))

键入命令的时候不询问命令格式如下:

[[email protected] tmp]# /usr/bin/mv 11.txt daizhihong/使用

[[email protected] tmp]#

绝对路径命令格式执行就不会提示询问,直接覆盖

[[email protected] tmp]# ls

daizhihong

daizhihong1

daizhihong3

ks-script-9pf2WE

yum.log

[[email protected] tmp]# ls daizhihong

11.txt

-----------------------------------------------------------------------------------------

移动目录:把/tmp/daizhizhong1/目录移动到/tmp/daizhizhong/目录下,如果该目录存在,则会把源文件或目录移动到该目录当中

[[email protected]ihong01 tmp]# ls

daizhihong

daizhihong1

daizhihong3

ks-script-9pf2WE

[[email protected] tmp]#  mv daizhihong1/ daizhong/

[[email protected] tmp]# ls

daizhihong

daizhihong3

daizhong

ks-script-9pf2WE

--------------------------------------------------------------------------------------------

目录移动的时候目标目录不存在,就会把源目录从命名为给定的目标文件名

[[email protected] tmp]# ls

Daizhihong(源文件)

daizhihong3

daizhong

ks-script-9pf2WE

yum.log

[[email protected] tmp]# mv daizhihong/ daizhihong2/

[[email protected] tmp]# ls

daizhihong2(源目录从命名为给定的目标文件名)

daizhihong3

daizhong

ks-script-9pf2WE

yum.log

-----------------------------------------------------------------------------------------

移动时目标目录存在的时候,就会把原目录放到目标目录下面

[[email protected] tmp]# ls

daizhihong2

daizhihong3

daizhong

ks-script-9pf2WE

yum.log

[[email protected] tmp]# mv daizhihong2/ daizhong/

[[email protected] tmp]# ls

daizhihong3

daizhong

ks-script-9pf2WE

yum.log

[[email protected] tmp]# ls daizhong/目标目录

01  daizhihong  daizhihong2(原目录)

[[email protected] tmp]#

---------------------------------------------------------------------------------------------

移动目录时时如果该目录存在则会询问是否覆盖

[[email protected] tmp]# rm daizhhong/

rm: 无法删除"daizhhong/": 没有那个文件或目录

[[email protected] tmp]# mkdir daizhihong

[[email protected] tmp]# touch daizhihong/01.txt

[[email protected] tmp]# tree daizhihong/

daizhihong/

└── 01.txt

0 directories, 1 file

[[email protected] tmp]# tree daizhihong3

daizhihong3

└── daizhihong

    └── 11.txt

1 directory, 1 file

 [[email protected] tmp]# mv daizhihong/ daizhihong3/

mv:是否覆盖"daizhihong3/daizhihong" y

mv: 无法将"daizhihong/" 移动至"daizhihong3/daizhihong": 文件已存在


以上是关于Linux第二周学习笔记的主要内容,如果未能解决你的问题,请参考以下文章

Linux第二周学习笔记

Linux第二周学习笔记

Linux第二周学习笔记

Linux第二周学习笔记(13)

Linux第二周学习笔记(11)

Linux第二周学习笔记(10)