Linux Command to Fix Permissions for Files and Directories

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

If you migrate your WordPress blog or another CMS driven website to another location, you might have to face issues with file permissions. For WordPress, the default directory permissions are 755 and the default file permissions are 644. This post focuses on setting these permission using command line (given that you have ssh access to your webserver). If your  CMS or webserver want you to have different permissions, then you can change the numbers in the commands below to suit your needs.

Beware of 777 permissions though, as it can be a big security threat! If you are told to use 777, first try it with 755 and 644, if that doesn’t work, then carefully add 777 permissions only as a last resort. Here are the terminal commands to fix your permissions recursively for a directory and its content:

find /var/www -type d -exec chmod 755 {} \;
find /var/www -type f -exec chmod 644 {} \;

The command above  finds, or looks for files and folders in the directory specified above by /var/www (If you want to look in a different directory, you can specify a different path like this. e.g. ~/public_html/myblog) and then it looks for the document type, be it directory (d) or file (f), and executes the chmod (change mode) command to change the permissions on all results.

Be very careful with these commands, specially if you are not sure what you are doing, it might break things for you!

You might also like

WordPress Blog Post by Post Redirection! You recently...
Must Have Free Windows 7 Software Open source/free...
Replace URL in WordPress Posts, Images and Links If you migrate...
How to Convert a WordPress Blog to Blogspot (Blogger) If you have...

About the Author

has written 346 posts on this blog.

Meditating towards his "nerdvana", lifehacker is a teacher by the day and a nerdy blogger by the night. He lives to learn and yearns to learn living.

Write a Comment

Gravatars are small images that can show your personality. You can get your gravatar for free today!


Copyright © 2017 Hack Your Life!. All rights reserved.
Proudly powered by WordPress. Developed by Deluxe Themes