ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

[linux] 循序渐进学运维-mv

2021-04-14 17:56:22  阅读:189  来源: 互联网

标签:学运 test1 -- zmedu mv linux txt root



文章目录


mv命令介绍

功能:

Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.
重命名或者移动文件名字
常用选项:
-b 目标文件存在创建备份,备份文件是"文件名后跟~"
-u 当源文件比目的文件修改时间新时才移动
-v 显示移动信息

–help的内容如下:

Usage: mv [OPTION]... [-T] SOURCE DEST
  or:  mv [OPTION]... SOURCE... DIRECTORY
  or:  mv [OPTION]... -t DIRECTORY SOURCE...
Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.

Mandatory arguments to long options are mandatory for short options too.
      --backup[=CONTROL]       make a backup of each existing destination file
  -b                           like --backup but does not accept an argument
  -f, --force                  do not prompt before overwriting
  -i, --interactive            prompt before overwrite
  -n, --no-clobber             do not overwrite an existing fileIf you specify more than one of -i, -f, -n, only the final one takes effect.
      --strip-trailing-slashes  remove any trailing slashes from each SOURCE
                                 argument
  -S, --suffix=SUFFIX          override the usual backup suffix
  -t, --target-directory=DIRECTORY  move all SOURCE arguments into DIRECTORY
  -T, --no-target-directory    treat DEST as a normal file
  -u, --update                 move only when the SOURCE file is newer
                                 than the destination file or when the
                                 destination file is missing
  -v, --verbose                explain what is being done  --help     display this help and exit  --version  output version information and exitThe backup suffix is `~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.
The version control method may be selected via the --backup option or through
the VERSION_CONTROL environment variable.  Here are the values:

  none, off       never make backups (even if --backup is given)
  numbered, t     make numbered backups
  existing, nil   numbered if numbered backups exist, simple otherwise
  simple, never   always make simple backups

Report mv bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils 'mv invocation'

案例:

1. -b 如果要拷贝过去的文件夹下有目标文件,则加~

[root@zmedu ~]# mkdir test1 test2[root@zmedu ~]# touch test1/a.txt[root@zmedu ~]# touch test1/b.txt[root@zmedu ~]# touch test/a.txttouch: cannot touch `test/a.txt': No such file or directory[root@zmedu ~]# touch test2/a.txt[root@zmedu ~]# mv -b test2/a.txt test1
mv: overwrite `test1/a.txt'? y[root@zmedu ~]# ls test1/a.txt  a.txt~  b.txt[root@zmedu ~]# 可以看到多了一个a.txt,而且第二个a.txt后面有~符号

2. -f 强制覆盖

[root@zmedu ~]# lstest1  test2[root@zmedu ~]# ll test1/total 0
-rw-r--r-- 1 root root 0 Nov 17 20:42 a.txt
-rw-r--r-- 1 root root 0 Nov 17 20:42 a.txt~
-rw-r--r-- 1 root root 0 Nov 17 20:42 b.txt[root@zmedu ~]# ll test2/total 0
-rw-r--r-- 1 root root 0 Nov 17 20:48 a.txt[root@zmedu ~]# mv -f test2/a.txt test1/[root@zmedu ~]# ll test1/total 0
-rw-r--r-- 1 root root 0 Nov 17 20:48 a.txt
-rw-r--r-- 1 root root 0 Nov 17 20:42 a.txt~
-rw-r--r-- 1 root root 0 Nov 17 20:42 b.txt[root@zmedu ~]#

3. -i:默认选项,当目标文件存在时,提示是否覆盖

[root@zmedu ~]# touch a.txt[root@zmedu ~]# lsa.txt  test1  test2[root@zmedu ~]# mv -i a.txt test1/mv: overwrite `test1/a.txt'? y[root@zmedu ~]#

4. -n 如果文件存在则不覆盖

[root@zmedu ~]# lsa.txt  test1  test2[root@zmedu ~]# mv -vn a.txt test1/[root@zmedu ~]# ll test1/total 0
-rw-r--r-- 1 root root 0 Nov 17 20:51 a.txt
-rw-r--r-- 1 root root 0 Nov 17 20:42 a.txt~
-rw-r--r-- 1 root root 0 Nov 17 20:42 b.txt

5. -v 显示详细信息

[root@zmedu ~]# mv -v a.txt  test1/mv: overwrite `test1/a.txt'? y`a.txt' -> `test1/a.txt'[root@zmedu ~]#

总结:

学习的过程中多用 --help是必要的 ,如果有不懂的参数,直接–help一下,英文的解释会更清晰明了。

标签:学运,test1,--,zmedu,mv,linux,txt,root
来源: https://blog.51cto.com/xinsz08/2706434

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有