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

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 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

目录也可以重命名跟重命名文件一样。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值