On my EC2 Linux server, I blindly ran chmod 777 at directory that it turns out I should not have. There are hundreds of files in there, and I'm not sure which ones need to go back to their original permissions. I have server with the exact same configurations. So I'm trying to run a shell script that outputs a chmod command for each file in the directory. The plan is that I'd then take the results and execute them in a shell script on the other machine.

I want my output to look like this:

sudo chmod ### /somefilepath/
sudo chmod ### /somefilepath/

My shell script right now looks like:

for file in /opt/bitnami/**
  perm = "$(stat --format '%a' "$file")"
  echo 'sudo chmod $perm "$file"'

It errors on each file with perm not found. What am I doing wrong?

I was able to fix this after the response below, final script is:


FILES=$(find /opt/bitnami/ -name '*')
for file in $FILES
  perm=$(stat --format '%a' "$file")
  echo "sudo chmod $perm $file"

1 Answer 1


The whitespace is significant:

spacing = "matters"  # runs spacing. or tries to, anyways
spacing="matters"    # probably more what you want

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .