如何使用unix shell重命名目录中的文件,以便它们的名称是crc32哈希+原始扩展名?
示例:
1-s2.0-105687199400063A-main.pdf
=> e3492cf3.pdf
答案 0 :(得分:2)
for file in `ls`; do mv "${file}" `cksum "${file}" | cut -d' ' -f1`."${file##*.}"; done
可能awk
是比cut
答案 1 :(得分:1)
这样的事情可行:
for file in /your/dir/*
do
extension="${file##*.}" #gets the block after the last dot, that is, the extension
new_name=$(crc32 $file) #calculates the crc32 value of the file
mv $file ${new_name}.${extension} #renames by moving the original file to the new name
done