MrM*_*e01 5 shell-script files file-types
我已经恢复了大约 2.8TB(是的,太字节)的数据,这将被扫描以查找重复项,这些文件所在的机器相当旧,只有 2GB 内存(但是对于 LVM 来说工作正常),所以执行以下操作重复扫描它是在寻求痛苦。
我的问题是,如何让 Debian 将文件移动到具有该文件类型的文件夹中,在需要时自动重命名,而无需指定文件类型列表。
我有大约 800GB 的可用空间,所以我可以在让它在我的数据上运行之前做一些测试。
目录看起来像
$ ls
another.doc file.txt file1.mp3 myfile.txt
Run Code Online (Sandbox Code Playgroud)
我们可以使用以下命令构建文件扩展名列表:
$ exts=$(ls | sed 's/^.*\.//' | sort -u)
Run Code Online (Sandbox Code Playgroud)
然后我们可以循环遍历这些扩展名,将文件移动到子目录中:
$ for ext in $exts
> do
> echo Processing $ext
> mkdir $ext
> mv -v *.$ext $ext/
> done
Run Code Online (Sandbox Code Playgroud)
运行时我们得到以下输出:
Processing doc
'another.doc' -> 'doc/another.doc'
Processing mp3
'file1.mp3' -> 'mp3/file1.mp3'
Processing txt
'file.txt' -> 'txt/file.txt'
'myfile.txt' -> 'txt/myfile.txt'
Run Code Online (Sandbox Code Playgroud)
结果:
$ ls
doc/ mp3/ txt/
$ ls *
doc:
another.doc
mp3:
file1.mp3
txt:
file.txt myfile.txt
Run Code Online (Sandbox Code Playgroud)