The following will encrypt/decrypt an extremely large number of files in the directory $mydir.
It asks for the password just once for decryption or twice for encryption.
It is recursive i.e. it operates on all the subdirectories of $mydir too.
It does not work with filenames which contain spaces.
Such files are ignored, but without stopping the rest being processed.
Unusual filename characters might also cause problems.
Hidden files (e.g. .directory) are excluded by the option -name '[!.]*'
I've found that bcrypt on its own can cope with well over 2000 files at once; xargs greatly extends this by its ability to break up a much larger number of files into manageable chunks:-
Code:
bcrypt $(find $mydir -type f -name '[!.]*' | xargs)
The yes command can be used to pipe the password in as many times as bcrypt needs it, in this case once or twice:-
Code:
yes $pw | bcrypt $(find $mydir -type f -name '[!.]*' | xargs)
If this was running in a terminal the "Encryption key:" prompt would be displayed but there is no need to type anything as the password (held in the variable $pw) will be entered silently by the yes command.
This makes it easier to use a long password but is less secure and so should be used with caution.
e.g. the password might leak to the swap space by memory paging, or if $pw was set by typing into a terminal it could be recorded in the terminal history file.