Skip to content

Instantly share code, notes, and snippets.

@mudassaralichouhan
Created August 29, 2023 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mudassaralichouhan/882d9af4461660f2559a844e4092a14b to your computer and use it in GitHub Desktop.
Save mudassaralichouhan/882d9af4461660f2559a844e4092a14b to your computer and use it in GitHub Desktop.
# Set default permissions for directories
find /home/me -type d -exec chmod 755 {} \;
# Set default permissions for files
find /home/me -type f -exec chmod 644 {} \;
@mudassaralichouhan
Copy link
Author

Explanation:

The first command (find /home/me -type d -exec chmod 755 {} ;) searches for all directories within /home/me and sets their permissions to 755, which gives the owner read, write, and execute permissions, while giving read and execute permissions to the group and others. This is a common and secure setting for directories.
The second command (find /home/me -type f -exec chmod 644 {} ;) searches for all files within /home/me and sets their permissions to 644, which gives the owner read and write permissions, and read-only permissions to the group and others. This is also a common and secure setting for files.
Please note the following:

The find command is used with the -type d flag to select directories and the -type f flag to select files.

The chmod command is used to change permissions. 755 and 644 are the numeric representations of the permissions as explained in the previous response.

This approach will set the permissions for all directories and files under /home/me, but not for subdirectories and files within those subdirectories. If you want to apply these permissions recursively, you should use the -exec option with find to process subdirectories as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment