[wellylug] permissions munted

Cliff Pratt enkidu at cliffp.com
Fri Jul 31 08:47:37 NZST 2009


Phillip Hutchings wrote:
> 
> On 30/07/2009, at 8:43 PM, Rimu Atkinson wrote:
> 
>> Hi all
>> 
>> I copied several tens of gigabytes of files off a NTFS disk and
>> every single file has the most permissive permissions imaginable.
>> Execute and write for everyone (see
>> http://rimu.geek.nz/Screenshot.png )
>> 
>> If I do chmod -x * then all the directories can't be opened any
>> more, which isn't cool.
>> 
>> How can I set everything to something sane, like
>> 
>> -rw-r--r--  1 rimu rimu       357 2009-07-17 20:56 examples.desktop
>>  drwxr-xr-x  2 rimu rimu      4096 2009-07-18 09:02 Templates
> 
> You want the amazing find command. If you want to do stuff to a bunch
> of files then find probably has the option you want.
> 
> find /path/to/base -type d -exec 'chmod' '755' '{}' ';' find
> /path/to/base -type f -exec 'chmod' '600' '{}' ';'
> 
> This searches all subdirectories and files starting at 
> /path/to/base/. -type specifies directory in the first case, then 
> regular file in the second. Then we use the -exec command to call
> chmod. It's a bit strange as I single quote every argument so I don't
> forget to double escape. Also {} and ; need to be escaped from the
> main shell, otherwise bad things happen.
> 
> If you want to double check replace the -exec... bit with -print,
> it'll just print the files to console.
> 
Why all the "'"?

I'd use something like:

find /path/to/base -type d -exec chmod 755 '{}' \;

The only necessary "'" are the ones around the parameter in case there
are spaces in the name.

Cheers,

Cliff



More information about the wellylug mailing list