我使用该mv命令丢失了一些文件。我不知道他们在哪里。它们不在我打算将其复制到的目录中。
以下是我所做的记录:
samuelcayo@CAYS07019906:~/Downloads/221-tp2-public-main$ cd
samuelcayo@CAYS07019906:~$ ls
Desktop Documents Downloads GameShell Music Pictures pratice Public Templates Videos
samuelcayo@CAYS07019906:~$ mkdir tp2
samuelcayo@CAYS07019906:~$ ls
Desktop Documents Downloads GameShell Music Pictures pratice Public Templates tp2 Videos
samuelcayo@CAYS07019906:~$ cd Downloads/221-tp2-public-main/
samuelcayo@CAYS07019906:~/Downloads/221-tp2-public-main$ ls
backup copybash Dockerfile ntfy-1.16.0 packets.txt README.md restore secret
cloud data Dockerfile_CAYS07019906 ntfy.zip rapport-tp2.md remplacer.sed sauvegarde.sh tail
samuelcayo@CAYS07019906:~/Downloads/221-tp2-public-main$ mv rapport-tp2.md tp2
samuelcayo@CAYS07019906:~/Downloads/221-tp2-public-main$ mv Dockerfile_CAYS07019906 tp2
samuelcayo@CAYS07019906:~/Downloads/221-tp2-public-main$ mv packets.txt tp2
samuelcayo@CAYS07019906:~/Downloads/221-tp2-public-main$ mv sauvegarde.sh tp2
samuelcayo@CAYS07019906:~/Downloads/221-tp2-public-main$ cd
samuelcayo@CAYS07019906:~$ cd tp2/
samuelcayo@CAYS07019906:~/tp2$ ls
samuelcayo@CAYS07019906:~/tp2$ ls -l
total 0
samuelcayo@CAYS07019906:~/tp2$ cd ..
Run Code Online (Sandbox Code Playgroud)
Kus*_*nda 82
您创建了一个名为 in 您的主目录的目录tp2,即您创建了目录~/tp2。然后您更改为~/Downloads/221-tp2-public-main并开始使用mv.
mv由于您将每个操作的目标指定为tp2,并且tp2不是当前目录中的目录,因此您移动的每个文件都被重命名为 tp2。tp2您随后每次运行时都会覆盖之前调用的文件mv。最后,tp2您留下的就是之前称为sauvegarde.sh.
~/tp2/通过使用作为每个操作的目标,您可以避免数据丢失mv。
指~的是您的主目录,您在其中创建了tp2目录。目标路径末尾/的 并不是绝对必要的,但如果不是目录,它会mv正常失败。~/tp2
至于您现在可以做什么来恢复丢失的文件;如果您在其他地方没有它们的其他副本,请考虑从最近的备份中恢复它们。
Pau*_*ant 28
该mv命令的 GNU 实现(在 Ubuntu 上找到的)有一个显式mv -t myDir选项,用于检查该myDir目录是否是一个现有目录。mv Source Dest这避免了( move to ) 和mv Source Directory( move into )之间的歧义。
它还修复了诸如 之类的构造中的 args 顺序find ... -print0 | xargs -r0 mv -t Dir --,其中 xargs 默认情况下附加 args (因此不可能将目标目录放在最后)。这两种情况都会避免你的问题。
该mv -i选项还提供防止意外覆盖文件的保护。