【Linux命令】每天一个Linux命令(6):mv命令

admin 2023年6月3日19:12:44评论11 views字数 2383阅读7分56秒阅读模式

每天一个Linux命令(6):mv命令

命令:
mv
描述:mv(move)用于移动文件或目录,也可以用于重命名文件或目录。
语法:
mv [选项] 源文件 目标文件
常用选项:
  • -i:在移动文件之前进行交互式确认。
  • -v:显示每个移动操作的详细信息。
示例:

1.

移动文件到目标位置:
mv file1.txt file2.txt

这将将 file1.txt 移动到 file2.txt,相当于对文件进行重命名。

【Linux命令】每天一个Linux命令(6):mv命令

2.

移动文件到目标目录:
mv file.txt directory/
这将将 file.txt 移动到 directory/ 目录。

【Linux命令】每天一个Linux命令(6):mv命令

3.

重命名文件:
mv oldname.txt newname.txt
这将将 oldname.txt 重命名为 newname.txt。
【Linux命令】每天一个Linux命令(6):mv命令
4.
移动目录到目标位置:
mv sourcedir/ destination/
这将将 sourcedir/ 目录移动到 destination/ 目录。

【Linux命令】每天一个Linux命令(6):mv命令

5.
在移动文件之前进行交互式确认:
mv -i file.txt destination/
这将在移动 file.txt 文件到 destination/ 目录之前进行交互式确认。

【Linux命令】每天一个Linux命令(6):mv命令

6.
显示每个移动操作的详细信息:
mv -v file.txt destination/
这将显示每个移动操作的详细信息,包括移动的文件名和目标位置。

【Linux命令】每天一个Linux命令(6):mv命令

说明: 
mv 命令可用于移动文件或目录,也可用于对文件或目录进行重命名。当移动文件或目录时,您可以指定源文件或目录的路径,并提供目标位置的路径。如果您希望重命名文件或目录,只需在目标位置中指定新的名称即可。请注意,目标位置可以是一个新的路径,也可以是已存在的路径。
使用 mv 命令时,请确保提供正确的源文件或目录路径以及目标位置。根据需要,您可以使用选项来进行交互式确认或显示详细信息。请注意,mv 命令会移动文件或目录,因此在执行操作之前请确保您具有足够的权限来读取源文件或目录,并在目标位置中进行写入。
[root@iZb5dlyg1ebe6oZ /]# mv --helpUsage: 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 -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 throughthe 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: <https://www.gnu.org/software/coreutils/>Full documentation <https://www.gnu.org/software/coreutils/mv>or available locally via: info '(coreutils) mv invocation'

【Linux命令】每天一个Linux命令(6):mv命令

原文始发于微信公众号(利刃信安攻防实验室):【Linux命令】每天一个Linux命令(6):mv命令

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2023年6月3日19:12:44
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   【Linux命令】每天一个Linux命令(6):mv命令https://cn-sec.com/archives/1782311.html

发表评论

匿名网友 填写信息