Linux: Set Permission Only to Directories

Linux: Set permission only to directories

Use find's -type option to limit actions to files and directories. Use the -o option to specify alternate actions for different types, so you only have to run find once, rather than separately for each type.

find htdocs -type f -exec chmod 664 {} + -o -type d -exec chmod 775 {} +

How do I change permissions for a folder and its subfolders/files?

The other answers are correct, in that chmod -R 755 will set these permissions to all files and subfolders in the tree. But why on earth would you want to? It might make sense for the directories, but why set the execute bit on all the files?

I suspect what you really want to do is set the directories to 755 and either leave the files alone or set them to 644. For this, you can use the find command. For example:

To change all the directories to 755 (drwxr-xr-x):

find /opt/lampp/htdocs -type d -exec chmod 755 {} \;

To change all the files to 644 (-rw-r--r--):

find /opt/lampp/htdocs -type f -exec chmod 644 {} \;

Some splainin': (thanks @tobbez)

  • chmod 755 {} specifies the command that will be executed by find for each directory
  • chmod 644 {} specifies the command that will be executed by find for each file
  • {} is replaced by the path
  • ; the semicolon tells find that this is the end of the command it's supposed to execute
  • \; the semicolon is escaped, otherwise it would be interpreted by the shell instead of find

How to change the permission for a specific directory without affecting the permission of everything inside that directory?

chmod 777 /path/to/specific/dir

Add read permissions to all the directories of a path

You can say:

chmod -R o+r /home/mDB/admin/KNUCKLES/dbs/

This would give read permission recursively to others, i.e. not owner/group.

EDIT: As per your comment, it seems that permissions for directories is the issue and not that of files. You could say:

chmod o+rx /home/mDB/{admin,admin/KNUCKLES,admin/KNUCKLES/dbs}

Note that since these are directories, you need to set the execute x bit on. Without that, r would serve no purpose!

How to create a directory and give permission in single command

According to mkdir's man page...

mkdir -m 777 dirname

In Linux how do I set permissions for a directory that prevent a user from listing, deleting or creating files within?

If your username is alex and the folder name is homework,

  1. try

    chmod -R 700 homework

from your login


  1. ensure the owner is alex. Else change ownership using the command

chown alex:alex homework

Now login using another username and execute

ls homework

you should get permission denied error

Change all files and folders permissions of a directory to 644/755

One approach could be using find:

for directories

find /desired_location -type d -print0 | xargs -0 chmod 0755

for files

find /desired_location -type f -print0 | xargs -0 chmod 0644

how to change chmod of directories in path

Use:

(umask 022; mkdir -p /a/b/c/d)

Setting the umask ensures that the write bits are reset for group and other on any directories the command creates (but has no effect on pre-existing directories, of course). The directories are then created with 755 permissions as desired. The parentheses use a sub-shell so that only the mkdir command is affected by the umask setting. (I use umask 022 by default; I usually don't mind people reading files, but I don't like them changing them without my permission.)



Related Topics



Leave a reply



Submit