• Skip to primary navigation
  • Skip to main content

Magda Sicknick

  • About me
  • Articles
  • Portfolio

Useful Linux commands

Copy contents of a directory to a new path

  • sudo cp -a /path/to/dir/. /path/to/new_dir

Remove directory and all its contents

  • sudo rm -R /path/to/dir

Apache commands

  • sudo service apache2 restart
  • sudo service apache2 reload
  • sudo service apache2 stop
  • sudo service apache2 start

Assign ownership and change permissions

  • sudo chown -R user_name:group_name /path/tp/dir
  • sudo chmod -R 775 /path/to/dir

Permissions are set by three numbers using the chmod command. The three numbers correspond to: Owner, Group, and Others.

Every file and folder contain a 8-bit data that control the permissions. At its basic binary form, it will be “000”, which means no permissions of any form is granted. When you set a “Read” permission, it will add 4-bit to the data, making it “100” (in binary format) or a “4” in the usual decimal format. Setting a “Write” permission will add 2-bit to the data, making it “010” and “2” in decimal form. Lastly, setting an “Execute” permission adds 1-bit to the data, which will result in “001”, or “1” in decimal form. In short:

  • Read is equivalent to 4
  • Write is equivalent to 2
  • Execute is equivalent to 1

When we want to set permissions, we just add up the number. For example, to set the permissions to read and write, we will use 6 (4 + 2) for the permission. For read, write and execute, we will use 7 (4 + 2 + 1) for the permission. Here’s the different permutation:

  • 0 – no permission
  • 1 – execute
  • 2 – write
  • 3 – write and execute
  • 4 – read
  • 5 – read and execute
  • 6 – read and write
  • 7 – read, write, and execute

Assign permissions to all files or folders in a directory

To assign permissions to all folders in a directory:

  • sudo find path/to/directory -type d -exec chmod 755 {} \;

To assign permissions to all files in a directory:

  • sudo find path/to/directory -type f -exec chmod 644 {} \;

Published on February 18, 2019

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Let’s Talk

Looking to get your business a website or update your current online presence?

Please send me information about you project so that I can determine how to best fulfill your needs.

    Service Required *

    Copyright© 2023 · Magda Sicknick · All Rights Reserved · Powered by Wordpress and the Genesis Framework.