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 byfind
for each directorychmod 644 {}
specifies the command that will be executed byfind
for each file{}
is replaced by the path;
the semicolon tellsfind
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 offind
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,
- try
chmod -R 700 homework
from your login
- 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
Fast Way to Get Image Dimensions (Not Filesize)
How to Install Crontab on Centos
How to Change File Permissions in Ubuntu
Difference Between Netstat and Ss in Linux
How to Open Sublime Text 2 Files from the Command Line in Linux to a Tab, Not a New Window
Mongo: Couldn't Connect to Server 127.0.0.1:27017 at Src/Mongo/Shell/Mongo.Js:145
/Lib64/Ld-Linux-X86-64.So.2: No Such File or Directory Error
Maximum Number of Inodes in a Directory
In Sshd Configuration What Does "Maxstartups 10:30:60" Mean
End of Line (New Line) Escapes in Bash
Linux Cmd to Search for a Class File Among Jars Irrespective of Jar Path
JSON Command Line Formatter Tool for Linux
Keep Remote Directory Up-To-Date
How to View Log Files in Linux and Apply Custom Filters While Viewing
Install Zsh Without Root Access
How to Write a Linux Daemon with .Net Core