Why you can trust ZDNET : ZDNET independently tests and researches products to bring you our best recommendations and advice. When you buy through our links, we may earn a commission. Our process

'ZDNET Recommends': What exactly does it mean?

ZDNET's recommendations are based on many hours of testing, research, and comparison shopping. We gather data from the best available sources, including vendor and retailer listings as well as other relevant and independent reviews sites. And we pore over customer reviews to find out what matters to real people who already own and use the products and services we’re assessing.

When you click through from our site to a retailer and buy a product or service, we may earn affiliate commissions. This helps support our work, but does not affect what we cover or how, and it does not affect the price you pay. Neither ZDNET nor the author are compensated for these independent reviews. Indeed, we follow strict guidelines that ensure our editorial content is never influenced by advertisers.

ZDNET's editorial team writes on behalf of you, our reader. Our goal is to deliver the most accurate information and the most knowledgeable advice possible in order to help you make smarter buying decisions on tech gear and a wide array of products and services. Our editors thoroughly review and fact-check every article to ensure that our content meets the highest standards. If we have made an error or published misleading information, we will correct or clarify the article. If you see inaccuracies in our content, please report the mistake via this form.


How to easily change folder and file permissions on Linux

File permissions make it possible for you to allow or prevent other users from viewing files on your Linux-powered computer. Here's a simpler way of setting up file permissions from the command line.
Written by Jack Wallen, Contributing Writer
Rockhopper penguins
Frizi/Getty Images

File permissions are an important aspect of the Linux operating system for security and privacy. You see, Linux is a multi-user operating system, which means more than one person can be logged on to the system at one time. 

Say, for example, you have a file called private.txt in the Documents directory of your home (so ~/Documents). By default on most modern Linux distributions, only the owner can view and/or edit the file. So, if user olivia logs in, she cannot see the contents of your home directory. 

Also: Thinking about switching to Linux? 9 things you need to know

But what about if you create a directory, outside of home, that you want to allow others to use? Let's say the directory is /user/share/data, which you could create with the command:

sudo mkdir /usr/share/data

Once you've created the directory, the only way to add anything to it is by using sudo for admin privileges -- and that includes allowing anyone on the system to be able to read and write to that directory, so they can view and edit files. Now, that's not exactly the most secure approach.

Also: Want to save your aging computer? Try these 5 Linux distributions

So, what I'm going to do is show you how to alter the file permissions in such a way that any valid user can read/write to the directory /user/share/data. Then I'll show you how to set the permissions in such a way that a file can be run like an app, which comes in handy when creating scripts.

Ready? Let's do this.

Changing file and folder permissions

What you'll need: For this feature, you'll need a running instance of Linux, which can be any distribution and either a desktop or server. You'll also need a user with sudo privileges. That's it. 

1. Set the permissions for the new directory

With the mkdir command we used earlier, we've created the directory /usr/share/data. We can set this directory such that any folder or file created within it enjoys the read/write permissions with the command:

sudo chmod -R ugo+rw /usr/share/da

Let me explain the above command:

  • chmod -- This is the command used to modify the permissions.
  • -R -- Informs chmod that we're working recursively, so every file and/or folder will inherit the same permissions.
  • ugo -- Means users, groups, and others (so, everyone).
  • rw -- Means read/write permissions.

A couple of things to keep in mind. First, you don't have to give permissions to all three types. You could give permissions to just u (user), g (group), or o (other). You can also give just r (read), w (write), or x (executable) permissions. For instance, you could give all users write permissions with:

sudo chmod -R u+w /usr/share/data

Also, if you're working with a file and not a folder, simply remove the -R option from the command.

2. Verify that the command worked

Once you've issued the command, you can verify it worked by issuing another command:

touch /usr/share/data/test

The above command will create an empty file, called test, in /usr/share/data. If the command worked, congratulations, you've successfully changed the permissions of the folder.

3. Give a file executable permissions

Say you've created a script that will back up the contents of your ~/Documents directory. To run that script, it must have executable permissions, which can be done with the chmod command. If your script is called backup, the command to give it executable permissions would be:

chmod u+x backup

Make sure to run the above command in the directory housing the script. To run the script, you could issue the command:


4. Removing permissions

You can also remove permissions with the chmod command. Let's stick with our earlier example. You now want to remove read/write permissions for the /usr/share/data directory. To do that, you would substitute - for +, so the new command would be:

sudo chmod -R ugo-rw /usr/share/data

At this point, no one would be able to read or write data to the directory.

Also: How to choose the right Linux desktop distribution for you

Now, this isn't the best method of adding or removing permissions on Linux because you wouldn't want to give every single user on a system access to modify a directory. A better way of handling this task is using groups. I'll explain that feature in an upcoming tutorial. Until then, keep practicing with this simple method of changing permissions on files and folders in Linux.

Editorial standards