您的位置:首页 > 运维架构 > Linux

Linux命令---- mv移动或重命名文件/目录

2017-05-28 15:34 645 查看
Linux 下查看帮助说明,可以用mv –help或man mv, 永远是最快捷的方式

@ubuntu:~$ mv --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 file
If 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
4000
file is missing
-v, --verbose                explain what is being done
-Z, --context                set SELinux security context of destination
file to default type
--help     display this help and exit
--version  output version information and exit

The 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

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
Full documentation at: <http://www.gnu.org/software/coreutils/mv>
or available locally via: info '(coreutils) mv invocation'


mv 的最后一个目标文件一定是目录,除非用 -t 参数先指定了目录。

1、移动一文件夹(目录及目录下的所有文件)到另一目录

下面案例是为了保存已下载代码的.repo文件夹并移到另一个目录中, 已后下载基于现有的来下载。

@ubuntu:~$ mv MSM8953/.repo/  work/MSM8909/

@ubuntu:~$ ls -a MSM8953/
.         build        device      libcore          platform_testing  tools
..        build.sh     docs        libnativehelper  prebuilts         vendor
abi       cts          external    Makefile         sdk
art       dalvik       frameworks  ndk              shortcut-fe
bionic    developers   hardware    packages         system
bootable  development  kernel      pdk              toolchain

@ubuntu:~/work$ cd MSM8909/
@ubuntu:~/work/MSM8909$ ls -a
.  ..  .repo


再看一案例,移动已下载的MSM8953文件到work工作目录

@ubuntu:~$ ls
bin      Documents  examples.desktop  Music     Public  Templates  work
Desktop  Downloads  MSM8953           Pictures  repo    Videos
@ubuntu:~$ mv MSM8953/ work/
@ubuntu:~$ ls
bin      Documents  examples.desktop  Pictures  repo       Videos
Desktop  Downloads  Music             Public    Templates  work
@ubuntu:~$ cd work
@ubuntu:~/work$ ls
MSM8909  MSM8953


2、移动一文件或多个文件到目录

@ubuntu:~/work$ ls
directory  MSM8909  MSM8953  test
@ubuntu:~/work$ mv test directory/
@ubuntu:~/work$ ls
directory  MSM8909  MSM8953
@ubuntu:~/work$ ls directory/
test


@ubuntu:~/work$ ls
directory  MSM8909  MSM8953  test1  test2
@ubuntu:~/work$ mv test1 test2 directory/
@ubuntu:~/work$ ls directory/
test  test1  test2


3、重命名文件

@ubuntu:~/work/directory$ ls
test  test1  test2
@ubuntu:~/work/directory$ mv test test3
@ubuntu:~/work/directory$ ls
test1  test2  test3


目录也可以重命名跟重命名文件一样。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  LINUX命令