How To Set Permission For Folders and Subfolders in Linux – POFTUT

How To Set Permission For Folders and Subfolders in Linux


During daily Linux administration we generally work generally with file and directory permissions. In this tutorial we will look different examples about how to change and revert Linux file and directory permissions. There is different ways to set folder and sub folder permission in Linux but here we will describe most convenient way.

Read Only Owner

Say we have folder /opt/lamp and we want to change all sub folders permission to change 600. Using <a href="https://www.poftut.com/linux-chmod-command-tutorial-examples-change-permission-files-folders/" target="_blank" rel="noopener noreferrer">chmod</a> with recursive options is the simplest one.

$ chmod -R 600 /opt/lamp

Read By Group But Not Edited

We may want to read by the owner group but not changed. We will set binary permission 660 for this.

$ chmod -R 600 /opt/lamp

Read By Others But Can Not Edit

Another useful permission is given other users read permission but denying from editing the file. We will use 664binary permission.

$ chmod -R 664 /opt/lamp

Change Directory Permission with Find

If we only want to change permission of directory we need to specify the type as directory .

$ find /opt/lamp -type d -exec chmod 660 {} \;

Change File Permission with Find

We can specify the type as file and change only files permissions. In this example we will change files located at /opt/lamp to 660 .

$ find /opt/lamp -type f -exec chmod 660 {} \;

Change File Permission According Extension with Find

We can specify the file extension we want to change the permission to the find command. In this example we will look directory /opt/lamp and change permission of .c extension files to the 660 .

$ find /opt/lamp -type d -name *.c -exec chmod 660 {} \;

 

How To Set Permission For Folders and Subfolders in Linux Infografic

How To Set Permission For Folders and Subfolders in Linux Infografic
How To Set Permission For Folders and Subfolders in Linux Infografic

LEARN MORE  Linux xargs Command Tutorial With Examples

1 thought on “How To Set Permission For Folders and Subfolders in Linux”

Leave a Comment