<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://qingliezhiquan.com/mediawiki/index.php?action=history&amp;feed=atom&amp;title=%E7%94%A8_bash_%E8%84%9A%E6%9C%AC%E8%AE%A1%E7%AE%97%E5%BD%93%E5%89%8D%E6%96%87%E4%BB%B6%E5%A4%B9%E5%86%85%E6%89%80%E6%9C%89_.docx_%E6%96%87%E4%BB%B6%E7%9A%84_sha1_%E5%80%BC</id>
	<title>用 bash 脚本计算当前文件夹内所有 .docx 文件的 sha1 值 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://qingliezhiquan.com/mediawiki/index.php?action=history&amp;feed=atom&amp;title=%E7%94%A8_bash_%E8%84%9A%E6%9C%AC%E8%AE%A1%E7%AE%97%E5%BD%93%E5%89%8D%E6%96%87%E4%BB%B6%E5%A4%B9%E5%86%85%E6%89%80%E6%9C%89_.docx_%E6%96%87%E4%BB%B6%E7%9A%84_sha1_%E5%80%BC"/>
	<link rel="alternate" type="text/html" href="https://qingliezhiquan.com/mediawiki/index.php?title=%E7%94%A8_bash_%E8%84%9A%E6%9C%AC%E8%AE%A1%E7%AE%97%E5%BD%93%E5%89%8D%E6%96%87%E4%BB%B6%E5%A4%B9%E5%86%85%E6%89%80%E6%9C%89_.docx_%E6%96%87%E4%BB%B6%E7%9A%84_sha1_%E5%80%BC&amp;action=history"/>
	<updated>2026-08-11T07:47:32Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.46.0</generator>
	<entry>
		<id>https://qingliezhiquan.com/mediawiki/index.php?title=%E7%94%A8_bash_%E8%84%9A%E6%9C%AC%E8%AE%A1%E7%AE%97%E5%BD%93%E5%89%8D%E6%96%87%E4%BB%B6%E5%A4%B9%E5%86%85%E6%89%80%E6%9C%89_.docx_%E6%96%87%E4%BB%B6%E7%9A%84_sha1_%E5%80%BC&amp;diff=8035&amp;oldid=prev</id>
		<title>Mwroot: Created page with &quot;保存这段代码为 calc_sha1_input.sh，再&lt;code&gt;./calc_sha1_input.sh 23333&lt;/code&gt;运行，就会计算出 calc_sha1_input.sh 所在文件夹内所有 .docx 文件的 sha1 值，并输出结果为 23333.txt。calc_sha1_input.sh 中的 input 是提示你，这段脚本需要输入一个参数，用以指定结果的文件名前缀。这对于当别人给你发了两个重复文件看着大差不差，但又不确定是否重复时很有用，只需要分别计算 sha1...&quot;</title>
		<link rel="alternate" type="text/html" href="https://qingliezhiquan.com/mediawiki/index.php?title=%E7%94%A8_bash_%E8%84%9A%E6%9C%AC%E8%AE%A1%E7%AE%97%E5%BD%93%E5%89%8D%E6%96%87%E4%BB%B6%E5%A4%B9%E5%86%85%E6%89%80%E6%9C%89_.docx_%E6%96%87%E4%BB%B6%E7%9A%84_sha1_%E5%80%BC&amp;diff=8035&amp;oldid=prev"/>
		<updated>2025-09-29T02:42:00Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;保存这段代码为 calc_sha1_input.sh，再&amp;lt;code&amp;gt;./calc_sha1_input.sh 23333&amp;lt;/code&amp;gt;运行，就会计算出 calc_sha1_input.sh 所在文件夹内所有 .docx 文件的 sha1 值，并输出结果为 23333.txt。calc_sha1_input.sh 中的 input 是提示你，这段脚本需要输入一个参数，用以指定结果的文件名前缀。这对于当别人给你发了两个重复文件看着大差不差，但又不确定是否重复时很有用，只需要分别计算 sha1...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;保存这段代码为 calc_sha1_input.sh，再&amp;lt;code&amp;gt;./calc_sha1_input.sh 23333&amp;lt;/code&amp;gt;运行，就会计算出 calc_sha1_input.sh 所在文件夹内所有 .docx 文件的 sha1 值，并输出结果为 23333.txt。calc_sha1_input.sh 中的 input 是提示你，这段脚本需要输入一个参数，用以指定结果的文件名前缀。这对于当别人给你发了两个重复文件看着大差不差，但又不确定是否重复时很有用，只需要分别计算 sha1 值，再进 excel 表格中用 if 函数一比较就能清楚知道哪两个文件是一模一样的了。代码来自 Kimi.ai。&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; line&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
# 检查参数数量&lt;br /&gt;
if [ $# -ne 1 ]; then&lt;br /&gt;
    echo &amp;quot;Usage: $0 &amp;lt;prefix_for_result_file&amp;gt;&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# 提取结果文件前缀&lt;br /&gt;
result_prefix=&amp;quot;$1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# 确保结果文件名以.txt结尾&lt;br /&gt;
if [[ &amp;quot;$result_prefix&amp;quot; != *.txt ]]; then&lt;br /&gt;
    result_file=&amp;quot;${result_prefix}.txt&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
    echo &amp;quot;Error: Result filename should not include the .txt extension.&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# 创建或清空指定的结果文件&lt;br /&gt;
&amp;gt; &amp;quot;$result_file&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# 遍历当前目录下的所有.docx文件&lt;br /&gt;
for file in *.docx; do&lt;br /&gt;
    # 检查文件是否存在&lt;br /&gt;
    if [ -f &amp;quot;$file&amp;quot; ]; then&lt;br /&gt;
        # 计算文件的SHA1哈希值&lt;br /&gt;
        sha1=$(sha1sum &amp;quot;$file&amp;quot; | awk &amp;#039;{print $1}&amp;#039;)&lt;br /&gt;
        # 将哈希值和文件名写入指定的结果文件&lt;br /&gt;
        echo &amp;quot;$sha1 $file&amp;quot; &amp;gt;&amp;gt; &amp;quot;$result_file&amp;quot;&lt;br /&gt;
    fi&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# 输出完成信息&lt;br /&gt;
echo &amp;quot;SHA1 hashes have been written to $result_file&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mwroot</name></author>
	</entry>
</feed>