大家好,欢迎来到IT知识分享网。
Linux命令集(Linux文件管理命令–mv指令篇)
Linux文件管理命令集(mv指令篇)
如下为笔者总结出在linux
中最常用的mv
指令集
🌟希望能够帮助正在Linux路上奋斗的你🌟
2. mv(move)
移动或重命名文件或目录
mv filename.py /workspace/test/ #实现将文件filename.py移动至/workspace/test/路径文件夹中
mv oldfname.txt newfname.txt #实现将oldfname旧文件名替换成newfname新文件名
短选项 | 长选项 | 描述 |
---|---|---|
-b |
-- |
在执行覆盖前,为目标文件创建一个备份 |
-f |
--force |
不提示用户直接强制覆盖目标文件而进行操作 |
-i |
--interactive |
如果目标文件已经存在,则要求用户确认是否进行覆盖操作 |
-n |
--no-clobber |
不覆盖任何已存在的文件,即使源文件比目标文件新 |
-S |
-- |
为目标文件设置备份名称的拓展名 |
-u |
--update |
只有在源文件比目标文件新或者目标文件不存在时才进行操作 |
-v |
--verbose |
显示操作的详细信息 |
-- |
--help |
显示帮助信息 |
-- |
--version |
显示版本信息 |
下述为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] 源文件 目标文件 或 mv [选项]... 源文件... 目标目录 或 mv [选项]... -t 目标目录 源文件... 将源文件重命名为目标文件,或者将源文件移动到目标目录。 必要选项对于短选项也是必要的。 --backup[=CONTROL] 对每个现有的目标文件都进行备份 -b 和--backup一样,但不带参数 -f, --force 在覆盖前不提示 -i, --interactive 覆盖前提示 -n, --no-clobber 不覆盖已存在的文件 如果指定多个 -i,-f,-n,则只有最后一个起作用。 --strip-trailing-slashes 从每个源文件中去除任何尾随斜杠 -S,--suffix=SUFFIX 覆盖默认备份后缀 -t,--target-directory=DIRECTORY 将所有源文件移动到目标目录 -T,--no-target-directory 把DEST视为普通文件 -u, --update 只有当源文件较新或目标文件不存在时才移动 -v, --verbose 解释正在进行的操作 -Z,--context 将目标文件的 SELinux 安全上下文设置为默认类型 --help 显示此帮助信息并退出 --version 输出版本信息并退出 默认情况下备份后缀为'~',除非使用 --suffix 或 SIMPLE_BACKUP_SUFFIX 设置。 可以通过 --backup 选项或 VERSION_CONTROL 环境变量来选择版本控制方法。以下是选项: none, off 不进行备份(即使给出了--backup) numbered, t 进行编号的备份 existing, nil 如果存在编号备份则进行编号备份,否则进行简单备份 simple, never 总是进行简单备份 GNU 核心实用程序在线帮助:http://www.gnu.org/software/coreutils/ 完整的文档见:http://www.gnu.org/software/coreutils/mv 或使用 info '(coreutils) mv invocation' 在本地查看。
1. 文件移动
移动单个文件或多个文件到指定目录
mv filename_0.py filename_1.py /workspace/test/
2. 递归移动目录
包括子目录中的文件或目录全部移动到新目录
mv -r src_directory/ target_directory/
3. 文件目录重命名
更改文件或目录的名称
mv old_name.py new_name.py
4. 强制移动
文件名重合会覆盖目标文件而不提示
mv -f src_file.txt target_directory/
5. 备份覆盖的目标文件
mv -b src_file.txt target_directory/
6. 试探性移动
当文件名重合时不覆盖目标文件
mv -n src_file.txt target_directory/
7. 显示移动进度
mv -v src_file.txt target_directory/
8. 补集操作
把所有在 source 目录(src)中但不在 target 目录中的文件移动到 target 目录中
for file in `ls src`; do mv $file target/; done
9. 修改文件的权限、属主和时间戳等属性
mv --preserve=mode,ownership,timestamps src_file.txt target_directory/
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/128938.html