How to change all of the contents inside of directory to what the default file ownership and permissions are

chmod

I have moved contents of another drive into my home directory, but the permissions are not what they should be. First, I changed ownership by entering:

  ~$ sudo chown -R USERME /home/USERHOME/

Which I think works now.

But now, I wanted to simply change all of the files and sub-directories into the default permissions, with files being read+write, and directories being r+w+x. I have not found a recursive way of handling this. I have run:

  ~$ sudo chmod 755 -R /home/USERHOME/

To make everything available to me. However, files appear as executables, and this is not what I want. There are plenty more sub-directories and files so I am looking for a simple recursive solution.

Basically, I think I am looking for a recursive way to reapply the default umask parameter to a whole folder with (I think) chmod.


Update:

I have posted a solution thanks to @SkyDan and "changing chmod for files but not directories"

Best Answer

chmod can do it, you don't need find.

Use symbolic mode and capital X.

chmod -R u=rwX,og=rX directory

alternately to avoid repetition, and make easier to edit. We can made it action orientated, instead of role orientated.

chmod -R a=rX,u+w directory

The capital X tells chmod to apply x to directories, (and if it already has it, if you do for example go+X).

Manual extract:

The format of a symbolic mode is [ugoa...][[+-=][perms...]...], where perms is either zero or more letters from the set rwxXst, or a single letter from the set ugo. Multiple symbolic modes can be given, separated by commas.

A combination of the letters ugoa controls which users' access to the file will be changed: the user who owns it (u), other users in the file's group (g), other users not in the file's group (o), or all users (a). If none of these are given, the effect is as if a were given, but bits that are set in the umask are not affected.

The operator + causes the selected file mode bits to be added to the existing file mode bits of each file; - causes them to be removed; and = causes them to be added and causes unmentioned bits to be removed except that a directory's unmentioned set user and group ID bits are not affected.

The letters rwxXst select file mode bits for the affected users: read (r), write (w), execute (or search for directories) (x), execute/search only if the file is a directory or already has execute permission for some user (X), set user or group ID on execution (s), restricted deletion flag or sticky bit (t). Instead of one or more of these letters, you can specify exactly one of the letters ugo: the permissions granted to the user who owns the file (u), the permissions granted to other users who are members of the file's group (g), and the permissions granted to users that are in neither of the two preceding categories (o).

Related Question