加密 Bash 中文件夹内的每个项目

Encrypt every item inside a folder in Bash

我有一个代码应该加密文件夹中的每个文件,但是当我把它(加密代码)放在无限循环中时它不起作用。

touch Out_file.txt
ls > Out_file.txt
i = 0
while:
i = i + 1
line=$(head -n $i Out_file.txt)
openssl cbc -aes-256-cbc -pass pass:Hello123  -p -in $line -out $line.enc
done

It might be able to encrypt all your files within the folder you are running the program in so please proceed with caution

怎么样:

(只是简化了我们如何生成文件列表并通过它们运行)


touch Out_file.txt
#write only filename to Out_file.txt
ls -l | awk 'NF>1{print $NF}' > Out_file.txt
while read filename; do
  openssl cbc -aes-256-cbc -pass pass:Hello123  -p -in $filename -out $filename.enc
done <Out_file.txt

祝你好运。