zoukankan      html  css  js  c++  java
  • linux系列(七):mv命令

    1、命令格式:

      mv [选项] 源文件或目录 目标文件或目录

    2、命令功能:

      Linux mv命令用来为文件或目录改名、或将文件或目录移入其它位置。

    3、命令参数:

    -b :若需覆盖文件,则覆盖前先行备份。 
    -f :force 强制的意思,如果目标文件已经存在,不会询问而直接覆盖;
    -i :若目标文件 (destination) 已经存在时,就会询问是否覆盖!
    -u :若目标文件已经存在,且 source 比较新,才会更新(update)
    -t  : --target-directory=DIRECTORY move all SOURCE arguments into DIRECTORY,即指定mv的目标目录,该选项适用于移动多个源文件到一个目录的情况,此时目标目录在前,源文件在后。

    4、简单实例:

    (1)、文件改名

    命令:

      mv test.txt ttt.txt

    输出:

    felix@felix-computer:~/test$ ls
    test.txt
    felix@felix-computer:~/test$ mv test.txt ttt.txt
    felix@felix-computer:~/test$ ls
    ttt.txt
    felix@felix-computer:~/test$ 

    (2)、移动文件

    命令:

      mv ttt.txt test3

    输出:

    felix@felix-computer:~/test$ tree
    .
    ├── test3
    └── ttt.txt
    
    1 directory, 1 file
    felix@felix-computer:~/test$ mv ttt.txt test3/
    felix@felix-computer:~/test$ tree
    .
    └── test3
        └── ttt.txt
    
    1 directory, 1 file
    felix@felix-computer:~/test$ 

    (3)、移动多个文件到指定目录

    命令:

      mv -t test4/ test3/*

    输出:

    felix@felix-computer:~/test$ tree
    .
    ├── test3
    │   ├── 1.txt
    │   ├── 2.txt
    │   ├── 3.txt
    │   ├── 4.txt
    │   └── ttt.txt
    └── test4
    
    2 directories, 5 files
    felix@felix-computer:~/test$ mv -t test4/ test3/*
    felix@felix-computer:~/test$ tree
    .
    ├── test3
    └── test4
        ├── 1.txt
        ├── 2.txt
        ├── 3.txt
        ├── 4.txt
        └── ttt.txt
    
    2 directories, 5 files
    felix@felix-computer:~/test$ 

    (4)、将文件1命名为文件2,如果文件2已存在,询问是否覆盖

    命令:

      mv -i 3.txt 1.txt

    输出:

    felix@felix-computer:~/test/test4$ ls
    1.txt  2.txt  3.txt  4.txt  ttt.txt
    felix@felix-computer:~/test/test4$ mv -i 3.txt 1.txt 
    mv:是否覆盖'1.txt'? y
    felix@felix-computer:~/test/test4$ ls
    1.txt  2.txt  4.txt  ttt.txt
    felix@felix-computer:~/test/test4$ 

    (5)、将文件1命名为文件2,如果文件2已存在,直接覆盖

    命令:

       mv -f 2.txt 1.txt

    输出:

    felix@felix-computer:~/test/test4$ mv -f 2.txt 1.txt 
    felix@felix-computer:~/test/test4$ ls
    1.txt  4.txt  ttt.txt
    felix@felix-computer:~/test/test4$ 

    (6)、目录移动,如果目录dir2不存在,将目录dir1改名为dir2;否则,将dir1移动到dir2中

    命令:

      mv test4 test3

    输出:

    felix@felix-computer:~/test$ tree
    .
    ├── test3
    └── test4
        ├── 1.txt
        ├── 4.txt
        └── ttt.txt
    
    2 directories, 3 files
    felix@felix-computer:~/test$ mv test4 test3
    felix@felix-computer:~/test$ tree
    .
    └── test3
        └── test4
            ├── 1.txt
            ├── 4.txt
            └── ttt.txt
    
    2 directories, 3 files
    felix@felix-computer:~/test$

    (7)、文件被覆盖前做简单备份

    命令:

      mv 2.txt -b 1.txt

    输出:

    felix@felix-computer:~/test/test3/test4$ ls
    1.txt  2.txt  3.txt  4.txt  5.txt  6.txt
    felix@felix-computer:~/test/test3/test4$ mv 2.txt -b 1.txt 
    felix@felix-computer:~/test/test3/test4$ ls
    1.txt  1.txt~  3.txt  4.txt  5.txt  6.txt
    felix@felix-computer:~/test/test3/test4$ 
  • 相关阅读:
    django 关于render的返回数据
    关于 eval 的报错 Uncaught ReferenceError: False is not defined
    Unexpected token o in JSON at position 1 at JSON.parse (<anonymous>) SyntaxError: Unexpected token R in JSON at position 0 at JSON.parse (<anonymous>)
    ajax 异步请求返回只刷新一次页面
    线程
    IO
    IO初步,字节输入流和字节输出流
    File、FileFilter、递归初步
    Map、可变参数、静态导入、Collections、Arrays、集合嵌套
    Collection单列集合中的常用实现类
  • 原文地址:https://www.cnblogs.com/felixwang2/p/9907443.html
Copyright © 2011-2022 走看看