I have an external hard drive that has the content of a Recovered Drive. All the folders have 'recup_dir.XX' names and there are over a thousand.
我有一个外置硬盘驱动器,其中包含恢复驱动器的内容。所有文件夹都有'recup_dir.XX'名称,有超过一千个。
I have copied over all content I can think of, of specific file types using:
我使用以下方法复制了我能想到的所有特定文件类型的内容:
find . -type f -name \*.jpg -exec cp \{\} /Volumes/somedrive/somefolder/ \;
I went through all file types I can think of - but I want to see what file types are on the drive and in the sub folders.
我浏览了所有我能想到的文件类型 - 但我想查看驱动器和子文件夹中的文件类型。
What command can I use that will go through all folders and sub folders and display 'total's for each file type?
我可以使用哪个命令将遍历所有文件夹和子文件夹并显示每种文件类型的总数?
du -hcs
Gives a total of the Drive- but I am after a Total per File Type.
给出了驱动器的总数 - 但我是在每个文件类型的总数之后。
Can anyone help point me in the right direction. I have thousands of folders and I want to make sure I haven't forgotten any file types - so want to get a list of them.
任何人都可以帮我指出正确的方向。我有成千上万的文件夹,我想确保我没有忘记任何文件类型 - 所以想要得到它们的列表。
Thanks for your help in advance.
感谢您的帮助。
1 个解决方案
#1
You can do this with awk (as well as other scripting languages). Here is a script in awk
:
您可以使用awk(以及其他脚本语言)执行此操作。这是awk中的一个脚本:
#!/bin/sh
find . -type f -ls | awk '
{
type = $11;
if ( type ~ /\./ ) {
sub(/^.*\./, "", type);
} else {
type = ".";
}
sizes[type] += $7;
}
END {
for ( type in sizes ) {
printf "%10d %s\n", sizes[type], type;
}
}' | sort -r -n
It uses an array sizes
with the file-suffix as an index. awk
does not have built-in sorting, but you can do that by piping the result through sort
.
它使用数组大小,文件后缀作为索引。 awk没有内置排序,但你可以通过排序管道结果来做到这一点。
For example, here is output from MacOS running in a copy of the Debian scripts for the xterm package:
例如,这里是MacOS的输出,运行在xterm包的Debian脚本的副本中:
341580 html 72830 /changelog 8458 /copyright 5846 /control 5754 diff 2401 /rules 1817 Debian 1328 asc 1284 postinst 964 1 723 prerm 631 /NEWS 442 faq 419 /local/lxterm 279 ctlseqs 162 conf 127 install 125 /tests/control 102 /watch 101 docs 58 /patches/series 23 /clean 12 /source/format 3 /compat
What you see when running the script depends on what file-suffixes exist. In this example, there are a couple of large ".html" files.
您在运行脚本时看到的内容取决于存在的文件后缀。在这个例子中,有几个大的“.html”文件。
#1
You can do this with awk (as well as other scripting languages). Here is a script in awk
:
您可以使用awk(以及其他脚本语言)执行此操作。这是awk中的一个脚本:
#!/bin/sh
find . -type f -ls | awk '
{
type = $11;
if ( type ~ /\./ ) {
sub(/^.*\./, "", type);
} else {
type = ".";
}
sizes[type] += $7;
}
END {
for ( type in sizes ) {
printf "%10d %s\n", sizes[type], type;
}
}' | sort -r -n
It uses an array sizes
with the file-suffix as an index. awk
does not have built-in sorting, but you can do that by piping the result through sort
.
它使用数组大小,文件后缀作为索引。 awk没有内置排序,但你可以通过排序管道结果来做到这一点。
For example, here is output from MacOS running in a copy of the Debian scripts for the xterm package:
例如,这里是MacOS的输出,运行在xterm包的Debian脚本的副本中:
341580 html 72830 /changelog 8458 /copyright 5846 /control 5754 diff 2401 /rules 1817 Debian 1328 asc 1284 postinst 964 1 723 prerm 631 /NEWS 442 faq 419 /local/lxterm 279 ctlseqs 162 conf 127 install 125 /tests/control 102 /watch 101 docs 58 /patches/series 23 /clean 12 /source/format 3 /compat
What you see when running the script depends on what file-suffixes exist. In this example, there are a couple of large ".html" files.
您在运行脚本时看到的内容取决于存在的文件后缀。在这个例子中,有几个大的“.html”文件。