Linux find command with multiple command -exec using chown and chmod

2

The following command runs but the two -exec commands don't run - so the file gets moved but the permissions and file owner doesn't change.

find ~/Downloads/ -name "2014-12-24*" -exec sudo mv {} ~/docs/ \; -exec sudo chown {} apache:apache \; -exec sudo chmod {} 400 \;

skibumdreamer

Posted 2014-12-25T03:55:28.950

Reputation: 23

Answers

1

Your problem is that you are moving, say, Downloads/2014-12-24-first to ~/docs/2014-12-24-first, and THEN trying to change the owner and permissions on Downloads/2014-12-24-first; which will not work, because you have already moved the file to ~/docs.

Try re-ordering your -execs so the chmod/chown are first, and the mv last.

BenjiWiebe

Posted 2014-12-25T03:55:28.950

Reputation: 7 672