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 .*?

6
  • 2
    Does this answer your question? Best way run a command on each file in a directory tree Commented Mar 25, 2020 at 3:12
  • 1
    * isn't recursive. You'd need something like bash's globstar (**). Or just use find. Commented Mar 25, 2020 at 3: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. Commented Mar 25, 2020 at 7: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. Commented Mar 25, 2020 at 8:49
  • 1
    Double-quote those variables when you use them ("$f" instead of $f) Commented Mar 26, 2020 at 17:55

1 Answer 1

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

2
  • 1
    This doesn’t do anything that couldn’t be done more simply by for f in .* * ; do …. More importantly, this doesn’t work recursively. Commented Sep 24, 2020 at 23:49
  • Also -- if there is an error in one command, the next ones won't be executed. Commented Sep 25, 2020 at 5:18

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.