Changing permissions only on files or only on directories

The following two commands will change the permissions only on the files in a directory even if there are also other directories, and the same for directories only:

This only chmods files to 644:
[root@box ~]# find -type f | xargs -i chmod 644 {}

This only chmods directories to 755:
[root@box ~]# find -name ‘*’ -type d | xargs -i chmod 755 {}

Also, as an addition here the most common permissions on server are 644 for files and 755 for directories, you may want to make sure that the files/directories are not having 777 permissions as this is a big security risk. Most of the time some scripts will need 777 permissions and if this is the case would be a good idea to find a way around this or just find another script that does not need 777 permissions set.

Was this answer helpful?

 Print this Article

Also Read

How to change the root password

How to change the root password Change root password: There are two kind of things we need to...

Debian asking to insert cdrom to update?

open a terminalsunano /etc/apt/sources.listput a # in front of the line talking bout cd's (or...

Easy ruTorrent installer + Web server, FTP, Webmin (Ubuntu/Debian/Fedora/More)

All credit goes to Author brock from  original post here for reference also...

Install Rar/Unrar centos 6

for 64 bit install unrar centos x64#wget...

KVM Install Guide

Table of Contents KVM Basic Install Individual Install Guides...