我有一個檔案 file.txt,檔案名以 *.sha256 結尾,包括每個檔案的完整路徑。這是一個玩具示例:
file.txt:
/path/a/9b/x3.sha256
/path/7c/7j/y2.vcf.gz.sha256
/path/e/g/7z.sha256
每行都有不同的路徑/檔案。*.sha256 檔案有校驗和。
我想在每個 *.sha256 檔案上運行命令“sha256sum -c”并將輸出寫入 output_file.txt。但是,此命令僅接受 .sha256 檔案的名稱,而不是包含其完整路徑的名稱。我嘗試了以下方法:
while read in; do
sha256sum -c "$in" >> output_file.txt
done < file.txt
但我得到:
"sha256sum: WARNING: 1 listed file could not be read"
這是由于命令中包含的路徑。
歡迎任何建議
uj5u.com熱心網友回復:
#!/bin/bash
while read in
do
thedir=$(dirname "$in")
thefile=$(basename "$in")
cd "$thedir"
sha256sum -c "$thefile" >>output_file.txt
done < file.txt
修改您的代碼以提取in變數的目錄和檔案部分。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/517841.html
標籤:解析Unix子目录校验和
上一篇:了解crontab條目
