1

I went from Windows 7 to Debian 9, copying most of the files I'm using for my projects from an NTFS drive.

I see that :

  • all the folders I have copied are now with rights drwxrwxrwx instead of drwxr-xr-x.
  • all the files have those rights too, instead of -rw-r--r--.

Is there an easy way to correct this, recursively ?
a chmod I think, but I'm not used with its parameters.

Files and folders shall have differents rights.

  • @Christopher : no, Files and folders shall have differents rights. – Marc Apr 30 at 18:01
2

you can use find like

find . -type d -print0 | xargs -r -0 chmod 0755
find . -type f -print0 | xargs -r -0 chmod 0644

The first one to chmod directories and the 2nd one for files

  • Thanks ! I succeded with your response. Can you explain more what the part -print0 | -xargs -r -0 of the command did ? It seems to be useful. – Marc Apr 30 at 17:59
  • find will choke when it hits a high number (determined by your system); xargs prevents that. – K7AAY Apr 30 at 18:04
  • @Marc, -print0 will add a "NULL" character between each object returned by find. Then -0 will tell xargs he will receive stuffs delimited by "NULL" chars.As this NULL can't exists in a filename, you are then sure to have the full filename to do you stuffs. -r will tell xargs to no do anything if nothing received. Since I had weird side effects with bad filenames and find -exec, I'm always using this -print0 trick. Have a look in the find and xargs man pages :-) – darxmurf Apr 30 at 20:45
  • Here's a useful primer on chmod: help.unc.edu/help/how-to-use-unix-and-linux-file-permissions – K7AAY May 1 at 16:06
  • @K7AAY It's not find that's the issue, it's the OS itself, which puts a limit on how long any one command line can be. You could just as easily sidestep this issue by just having find invoke the command once for each file, xargs is only the preferred option because it reduces the number of fork() calls and therefore speeds things up significantly. – Austin Hemmelgarn May 1 at 19:09
3

Instead of using find and octal mode. It can be done in one command (If using a modern chmod).

chmod -R u=rw,og=r,+X «directory to be fixed»

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.