3

I'm using the following command to perform permissions fixes:

sudo find . -type f -exec chmod 470 {} \;

There are many thousands of files to update the permissions on. It also spikes the CPU usage during the run.

A subsequent call that further modifies file permissions using a pure chmod recursive update doesn't spike the CPU

sudo chmod 770 -R /path/to/directory

What I am looking for:

  • A way to reduce CPU usage during this call
  • Potentially filtering to files that need the updated permissions

2 Answers2

5

Use nice to set a lower scheduling priority when running the command, or use renice to change the priority of an already running process.

sudo nice -n 19 find . -type f -exec chmod 470 {} \;

You can change find to not return files already matching the mode you're setting as well:

sudo nice -n 19 find \! -perm 0470 -and -type f -exec chmod 470 {} \;
Cakemox
  • 25,209
  • 6
  • 44
  • 67
  • well... didn't know about the -perm setting (I really should read the man page more on these common commands). I'm going to play a bit. For the purposes of this answer I'm going to avoid the nice command (although good to know about) because I do need it to be done in a timely fashion. But avoiding redoing perms will be "nice". – Rebecca Dessonville Nov 21 '17 at 19:00
1

The spike in CPU is due to disk activity so the only way to reduce CPU is faster disk.

Mike
  • 22,310
  • 7
  • 56
  • 79