3

I was trying to add execute permissions to sh files in a folder. For that I mistakenly used:

find . -print0 -iname '*.sh' | xargs -0 chmod -v 744

and the output was :

mode of `.' changed from 0755 (rwxr-xr-x) to 0744 (rwxr--r--)
mode of `./codis.sh' changed from 0644 (rw-r--r--) to 0744 (rwxr--r--)
mode of `./ne fil.sw' changed from 0644 (rw-r--r--) to 0744 (rwxr--r--)
mode of `./.whois1.sh.swo' changed from 0644 (rw-r--r--) to 0744 (rwxr--r--)
mode of `./new file' changed from 0644 (rw-r--r--) to 0744 (rwxr--r--)
mode of `./ezik.sh' changed from 0644 (rw-r--r--) to 0744 (rwxr--r--)
mode of `./.whois1.sh.swp' changed from 0600 (rw-------) to 0744 (rwxr--r--)
mode of `./whois1.sh' retained as 0744 (rwxr--r--)

I now know that the correct usage for the find part was

find . -iname '*.sh' -print0

So I created another find like so:

find . \! -iname '*.sh' -print0 | xargs -0 chmod 600

so that I may set back the permissions for non-sh files (yes, I see that some files have 644 perms, not 600 but it does not matter now). The output for this command is :

chmod: cannot access `./ne fil.sw': Permission denied
chmod: cannot access `./.whois1.sh.swo': Permission denied
chmod: cannot access `./new file': Permission denied
chmod: cannot access `./.whois1.sh.swp': Permission denied

I used sudo too but still nothing...

I see I do not understand permissons properly... If I understand correctly I need x permisions for directory direc too in order to execute commands in said directory.

  • Are you owner of current directory? – cuonglm Jun 24 '14 at 2:45
  • in between the command that changed permissions and the command that outputs permissions denied i have not run any permission-altering commands. for the directory in which i am working the permissions are: drw------- 2 joee joee 4096 Jun 24 02:06 scripts ; i opened the terminal as joee and tried sudo too – user293496 Jun 24 '14 at 2:51
2

Your find cmd also finds the current directory ".". The rights of this directory will then be set to 600 and therefore you'll lose the rights to touch the files within this directory.

So cd .., chmod 700 said directory and then run your reverting find, which now excludes the current directory, like this:

find . \! -path . \! -iname '*.sh' -print0 | xargs -0 chmod 600
  • 1
    well, that makes sense ... i just noticed, like you said, that find . \! -iname '*.sh' includes "." in the results too... – user293496 Jun 24 '14 at 2:55
  • Don't forget to close your questions so they don't show up in the section unanswered :). – polym Jun 24 '14 at 3:02
  • 1
    At least in the GNU world this can be done with -mindepth 1, too. – Hauke Laging Jun 24 '14 at 3:07
  • 1
    forgot to add an \!, try it now :) – polym Jun 24 '14 at 3:13
  • 1
    yep, works now. the mindepth 1 argument also works. thanks folks – user293496 Jun 24 '14 at 3:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.