[Linux-Lernen] Grundlegende Linux-Befehle (1) – Detaillierte Erklärung des mv-Befehls

[Linux-Lernen] Grundlegende Linux-Befehle (1) – Detaillierte Erklärung des mv-Befehls

1. Detaillierte Erläuterung der Befehle

Der Befehl mv wird hauptsächlich zum Umbenennen oder Verschieben von Dateien oder Verzeichnissen verwendet. Verwendung: mv old.txt new.txt. Häufig verwendete
Parameter werden im Folgenden ausführlich erläutert:

用法:	mv [选项] [-T] 源文件 目标文件;
	或:mv [选项] 源文件... 目录;
	或:mv [选项] -t 目录 源文件;
将源文件重命名为目标文件,或将源文件移动至指定目录。长选项必须使用的参数对于短选项时也是必需使用的。
	--backup				为每个已存在的目标文件创建备份;
-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 	将目标文件视作普通文件处理;
-u, --update 				只在源文件文件比目标文件新或目标文件不存在时才进行移动;
-v, --verbose 				详细显示进行的步骤;
	--help 					显示此帮助信息并退出;
	--version				显示版本信息并退出

2. Befehlsbeispiele

Dateien verschieben

Dateien in Verzeichnis verschieben oder umbenennen

[root@nie linux]# ls
1.txt  2.txt  a  linux.txt  word
[root@nie linux]# ls a/
[root@nie linux]# mv 1.txt a
[root@nie linux]# ls a/
1.txt
[root@nie linux]# ls
2.txt  a  linux.txt  word
或
[root@nie linux]# ls
a  linux.txt  word
[root@nie linux]# mv linux.txt linux1.txt 
[root@nie linux]# ls
a  linux1.txt  word

Die gleichnamige Datei wird nach Bestätigung überschrieben.

[root@nie linux]# ls
2.txt  a  linux.txt  word
[root@nie linux]# ls word/
1.txt  2.txt  linux.txt
[root@nie linux]# mv -i 2.txt word/
mv:是否覆盖'word/2.txt'? y
[root@nie linux]# ls
a  linux.txt  word
[root@nie linux]# ls word/
1.txt  2.txt  linux.txt

Das gleichnamige Verzeichnis kann ohne Bestätigung direkt überschrieben werden.

[root@nie linux]# ls word/
1.txt  2.txt  linux.txt
[root@nie linux]# ls 
a  linux.txt  word
[root@nie linux]# ls a/
1.txt
[root@nie linux]# mv -f a/1.txt word/
[root@nie linux]# ls a/
[root@nie linux]# ls word/
1.txt  2.txt  linux.txt

Sichern Sie die Datei unter demselben Namen, bevor Sie sie überschreiben

[root@nie linux]# ll
总用量 4
drwxr-xr-x. 2 root root  6 6月   1 12:23 a
-rw-r--r--. 1 root root 18 5月  31 19:57 linux.txt
drwxr-xr-x. 2 root root 49 6月   1 12:23 word
[root@nie linux]# ll word/
总用量 8
-rw-r--r--. 1 root root 4 5月  31 19:56 1.txt
-rw-r--r--. 1 root root 6 5月  31 19:56 2.txt
-rw-r--r--. 1 root root 0 5月  31 19:40 linux.txt
[root@nie linux]# mv -b linux.txt word/
mv:是否覆盖'word/linux.txt'? y
[root@nie linux]# ll
总用量 0
drwxr-xr-x. 2 root root  6 6月   1 12:23 a
drwxr-xr-x. 2 root root 67 6月   1 12:27 word
[root@nie linux]# ll word/
总用量 12
-rw-r--r--. 1 root root  4 5月  31 19:56 1.txt
-rw-r--r--. 1 root root  6 5月  31 19:56 2.txt
-rw-r--r--. 1 root root 18 5月  31 19:57 linux.txt
-rw-r--r--. 1 root root  0 5月  31 19:40 linux.txt~

Nur verschieben, wenn die Quelldatei neuer als die Zieldatei ist oder die Zieldatei nicht existiert

[root@nie linux]# ll
总用量 4
drwxr-xr-x. 2 root root 23 6月   1 12:58 a
-rw-r--r--. 1  777 root 22 6月   1 13:00 linux.txt
drwxr-xr-x. 2 root root 49 6月   1 12:55 word
[root@nie linux]# ll a/
总用量 0
-rw-r--r--. 1 root root 0 6月   1 12:58 linux.txt
[root@nie linux]# ll word/
总用量 12
-rw-r--r--. 1 root root  4 5月  31 19:56 1.txt
-rw-r--r--. 1 root root  6 5月  31 19:56 2.txt
-rw-r--r--. 1 root root 18 5月  31 19:57 linux.txt
[root@nie linux]# mv -u linux.txt a/
mv:是否覆盖'a/linux.txt'? y
[root@nie linux]# ll
总用量 0
drwxr-xr-x. 2 root root 23 6月   1 13:03 a
drwxr-xr-x. 2 root root 49 6月   1 12:55 word
[root@nie linux]# ll a/
总用量 4
-rw-r--r--. 1 777 root 22 6月   1 13:00 linux.txt
或
[root@nie linux]# mv -u word/linux.txt ./
[root@nie linux]# ll
总用量 4
drwxr-xr-x. 2 root root 23 6月   1 13:03 a
-rw-r--r--. 1 root root 18 5月  31 19:57 linux.txt
drwxr-xr-x. 2 root root 32 6月   1 13:04 word
[root@nie linux]# ll word/
总用量 8
-rw-r--r--. 1 root root 4 5月  31 19:56 1.txt
-rw-r--r--. 1 root root 6 5月  31 19:56 2.txt

Verzeichnis verschieben

Verschieben Sie das Verzeichnis. Wenn das Zielverzeichnis nicht existiert, benennen Sie es um.

[root@nie linux]# ls
a  linux1.txt  word
[root@nie linux]# mv a word1/
[root@nie linux]# ls
linux1.txt  word  word1

[root@nie linux]# mv word1/ word/
[root@nie linux]# ls
linux1.txt  word
[root@nie linux]# ls word/
1.txt  2.txt  word1

Verschieben Sie Dateien im Verzeichnis in das aktuelle Verzeichnis

[root@nie linux]# ls 
linux1.txt  word
[root@nie linux]# ls word/
1.txt  2.txt  word1
[root@nie linux]# ls word/word1/
linux.txt
[root@nie linux]# mv word/* ./
[root@nie linux]# ls
1.txt  2.txt  linux1.txt  word  word1
[root@nie linux]# ls word/
[root@nie linux]# ls word1/
linux.txt

Ich denke du magst

Origin blog.csdn.net/weixin_43757336/article/details/130985082
Empfohlen
Rangfolge