擅长:python、mysql、java
<p>以下是csl的回复:</p>
<blockquote>
<p>You can use</p>
<pre><code>file -i filename
</code></pre>
<p>to get a MIME-type.
You could potentially lookup the type
in a list and then append an
extension. You can find list of
MIME-types and suggested file
extensions on the net.</p>
</blockquote>
<p>我建议您编写一个脚本,它接受<code>file -i filename</code>的输出,并用您选择的语言返回一个扩展名(在空格上拆分,找到“/”,在表文件中查找该术语)-最多几行。然后你可以做如下事情:</p>
<pre><code>ls | while read f; do mv "$f" "$f".`file -i "$f" | get_extension.py`; done
</code></pre>
<p>在bash中,或者在bash脚本中抛出它。或者使get_扩展脚本更大,但这样在下次需要相关扩展时就不那么有用了。</p>
<p>编辑:从<code>for f in *</code>更改为<code>ls | while read f</code>,因为后者处理的文件名中有空格(在Windows上是一个特殊的噩梦)。</p>