0

I have a USB flash drive and would like to base-64 (or similar) encode all the files/folders (recursively) under a certain parent directory on it; let's call it "toEncode".

It would be preferable to be able to encode and decode these files whenever I want: decode the toEncode directory, modify any part of its child folders/files, and then re-encode it. I'm on Ubuntu 12.04 desktop. Ideas?

  • 1
    Encoding is not the same as encrypting. The former translates data from one representation to a smaller code set (for example Unicode to ASCII) and the latter translates (generally) into a binary form unreadable without some secret code. – l0b0 Jan 20 '14 at 21:54
  • Thanks but I know the difference and do mean encode! – user3178622 Jan 20 '14 at 22:19
  • 1
    If so, what is the use case? I can't think of any reason why you'd want to do this, but maybe you have one? – l0b0 Jan 20 '14 at 22:21
  • The use case is irrelevant backstory that shouldn't be used to clutter up the SU databases. I'm simply wondering if this is possible and if so how – user3178622 Jan 20 '14 at 22:36
  • You'll have it much easier if you break your problem into its constituents: You want to do one operation recursively on several files; the operation happens to be base64 encoding/decoding. Both parts taken by themselves are trivial, without knowing what you are trying to accomplish it's difficult to give any meaningful advice. – Vucar Timnärakrul Jan 20 '14 at 22:55
1

To encode:

base64 file.xyz > encoded.b64

To decode:

base64 -d encoded.b64 > file.xyz

For more information:

man base64

To find such commands, it's useful to search using commands like these:

apropos -r 'base.*64'
apt-cache search 'base.*64'
  • Awesome thanks @I0b0 (+1) do you know if base64 is recursive and works on directories? – user3178622 Jan 20 '14 at 22:45
  • 1
    Nope, it's definitely one file at a time. I don't think your use case is really all that common, so it might help avoiding an X-Y problem if you post more details. – l0b0 Jan 20 '14 at 22:48
  • Of course not: As a filter, by design it works on single files only. You'll have to build the recursion yourself, maybe by a combination of find and a little scripting. – Vucar Timnärakrul Jan 20 '14 at 22:51
1

If you're just looking to encrypt data on a flash drive, there are far better tools than trying to do it manually.

http://www.truecrypt.org/

  • Thanks @codenoire (+1) but I do want base 64 encoding here... Ideas? – user3178622 Jan 20 '14 at 22:20
  • You might be thinking of what happens if you need to stop this sort of operation during the middle of processing a whole bunch of files. Some will be encoded, and some will not. If any of the original set of files were actually already base64-encoded data, you're going to have a heck of a time trying to recover. – Xavier J Jan 20 '14 at 23:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.