Linux: Recursive ownership/permission change

Step-by-Step descriptions of how to do things.
Post Reply
User avatar
^rooker
Site Admin
Posts: 1481
Joined: Fri Aug 29, 2003 8:39 pm

Linux: Recursive ownership/permission change

Post 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
Jumping out of an airplane is not a basic instinct. Neither is breathing underwater. But put the two together and you're traveling through space!
Post Reply