Extract file and folders with specified permissions

If you're running tar(1) as a regular user, it will apply your umask by default. If you're running tar(1) as root, then you can give --no-same-permissions command line option to ask tar(1) to respect the umask.

So: either run this as a regular user:

umask 022
tar zxvf file.tar.gz

or run this as root:

umask 022
tar zxvf file.tar.gz --no-same-permissions

You might want to stick umask 022 into your ~/.bashrc, ~/.bash_profile, or ~/.profile. (See bash(1) manpage for full details on the start up files. It's complicated.)

Details on umask can be found in your shell's manpage, the umask(2) system-call manpage, or the umask(1posix) POSIX-provided utility manpage (if you have the manpages-posix installed).


Run the following commands in the root of the directory to set the desired permissions for your directories and files:

find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;

Be aware of the space between the closing curly bracket and the back slash


If you use capital X in chmod you can use it to set the execute permissions only on directories. i.e.

chmod -R ugo+X .

I found this solution that worked for me. For folders and subfolders:

chmod -R 777 */

And for all files (also in folders and subfolders):

find . -type f -name "*" | xargs chmod 644

All comments welcome if this is not a good way of doing it. I just started learning Linux.

Following comments, a more robust solution that handles special characters nicely would be:

find . -type f -print0 | xargs -0 chmod 644  # For files
find . -type d -print0 | xargs -0 chmod 755  # For directories