0

I can use:

for f in .* ; do [ -f $f ] && openssl aes-256-cbc -in $f -out $f -k PASSWORD ; done

to encrypt all hidden files in a folder and use:

for f in * ; do [ -f $f ] && openssl aes-256-cbc -in $f -out $f -k PASSWORD ; done

to encrypt all visible files in a folder. Is it possible to combine these two commands? And are there other potential types of files that are not matched by * and .*?

kbulgrien
  • 780
  • 6
  • 21
Aero Wang
  • 151
  • 1
  • 8
  • 2
    Does this answer your question? [Best way run a command on each file in a directory tree](https://unix.stackexchange.com/questions/99/best-way-run-a-command-on-each-file-in-a-directory-tree) – muru Mar 25 '20 at 03:12
  • 1
    `*` isn't recursive. You'd need something like bash's `globstar` (`**`). Or just use `find`. – muru Mar 25 '20 at 03:14
  • @muru can you write an answer using `find`? I also realized it isn't recursive but I am not sure how to use find with openssl particularly I don't know how to get `$f` from the original command. – Aero Wang Mar 25 '20 at 07:33
  • `find . -type f -exec openssl aes-256-cbc -in {} -out {} -k PASSWORD \;` I'd expect. Though I am not certain writing to the same file works well with `openssl`. I think it truncates the output file immediately, so it will read from an empty file. – muru Mar 25 '20 at 08:49
  • @muru you are right, it does read from an empty file... – Aero Wang Mar 25 '20 at 09:09
  • 1
    Double-quote those variables when you use them (`"$f"` instead of `$f`) – roaima Mar 26 '20 at 17:55

1 Answers1

0

I use the && thing:

for f in .* ; do [ -f $f ] && openssl aes-256-cbc -in $f -out $f -k PASSWORD ; done && for f in * ; do [ -f $f ] && openssl aes-256-cbc -in $f -out $f -k PASSWORD ; done

Ex. echo 1 && echo 2 returns

1

2