Page 1 of 1

Linux: Recursive ownership/permission change

Posted: Wed Oct 26, 2016 3:49 am
by ^rooker
[PROBLEM]
Sometimes I have the situation where the access rights look like this:

Code: Select all

drwx------ 280 pi   pi   16384 Oct 25 11:29 Data
Now that's no problem for one folder, but "Data" has a thousands of subfolders and files... :?

[SOLUTION]
Thanks to StackExchange answer by user "WombleGoneBad", here's a great 2-liner:

Code: Select all

$ find /path/to/folder -type d -exec chmod 755 {} \;
$ find /path/to/folder -type f -exec chmod 644 {} \;
The first line changes all folder to "drwxr-xr-x" (=755) and all files to "rw-r--r--" (=644).

NOTE: This removes executable rights from files.
This is usually not a problem with data-storage only folders, but definitely a no-go when applied to operating system folders and such.

Needed this 2-lines so often that I found it worth writing it down ;)


It's all in a day's work for "recursive find permission change"! :D