For most, changing the permissions of files and folders on Mac Terminal is not an everyday task, but as a command line user, you will find the need to do so at one time or another. The command itself is relatively simple. The hard part is learning the notation used to set them.
To do this, you will be using the chmod command. There are, of course, a few variations of how to use it, but for the most part, the command will have a format as shown below.
chmod <permissions> <file or folder name>
My name is Eric, and as a software engineer who uses command line interfaces such as Mac Terminal every day, I have had a great deal of experience in changing file and folder permissions. I will be glad to show you some of the basics below.
Keep reading to learn the notation used for file permissions and how to change them. I will also provide some tips you can use to make this easier.
Contents
Understanding Permissions Notation
The LINUX/UNIX-based command line used in Mac Terminal offers powerful control over file permissions. The notation used for displaying, setting, and changing those permissions is a bit complex, but we can do a few things to make it a little easier to learn and use.
Once you get the hang of it, you probably won’t have any problems, but it can take a little time. We won’t get into too much complexity here, but for those who want to skip the details and get right to the task at hand, you should be able to do so with the information provided below.
Before we can change file permissions, we first need to understand a little about the notation used, so let’s start by looking at the existing permissions of a file. For most of this article, we will work with a file’s permissions, but the same idea and methods apply to folders or directories.
How to View Current Permissions
If you want to view the current permissions of a file, you will first need to open Terminal and navigate to the directory of the file whose permissions you wish to view. Once there, you can use the ls -la command to see the file and its attributes.
ls -la <filename>
In the example above, you will see the file permissions in the first column on the left side of the screen. Each column will show a group of characters. The first character defines if the item is a directory or a file. If it is a directory, you will see a d there.
The following nine characters define the permissions for the file or directory and are grouped in sets of three. Each set of three represents the permission bits for a specific set of users. We will discuss the sets of users in the next section.
Permissions for Who?
The sets of users represented by each of the three sets of bits allow us to define permissions separately for each one. The three sets, in order from left to right, define permissions for the user who created or owns the file (u), the system group that owns the file (g), and all others (o).
The letters used for each set will be used in some commands later when we want to add or remove permissions for a specific set but for now, just know that each of these sets can have different permissions and are independent of each other.
Four Types of access
Each placeholder or bit of the three-bit set represents an additional permission attribute. When the bit is turned off, you will see a – character. When the bit is turned on, you will see an r in the leftmost placeholder, a w in the middle, and an x in the rightmost placeholder.
There are four types of access that each of the bit sets above can have. Take a look at each of these below
No access
With all bits turned off, you will see a — meaning no access is available to that file or folder.
Read access
If a file or folder has read access, it means that set of users can open and read the file and even copy it. You will see an r in the leftmost bit for that set of users. With only the read bit set it will have the format of r–.
Write access
Write access allows you to edit and delete files. If only the write access bit is set you would see the set as -w-. It would be very uncommon to have only the write bit set because you need to be able to read the file to edit it, but it is possible, as shown below.
Execute access
Execute access allows you to run a file or script or even start an application. If a file only had to execute permission (which is also very uncommon but possible), the bit set would look like –x.
The read, write and execute bits can be set in any combination. If you look through your directories, you will notice that the read bit is almost always set (at least for the user) since you need it to be set to do nearly anything with the file, such as opening it or copying it.
Numerical Representation
Each of the bit sets that represent the permissions for one of the three sets of users can also be read as a three-digit binary number where the – represents a 0 and the r/w/x character represents a 1. This will make sense if you are familiar with binary numbers, but no worries if you are not.
When converted to a decimal number, the binary number will be used with the chmod command, as seen in the next section. The chart below may clarify this and help you determine the numbers you need to use for changing the permissions on a file or folder.
Decimal Number | Binary Number | Permissions Bit Set | Permissions |
0 | 000 | — | None |
1 | 001 | –x | Execute |
2 | 010 | -w- | Write |
3 | 011 | -wx | Write and Execute |
4 | 100 | r– | Read |
5 | 101 | r-x | Read and Execute |
6 | 110 | rw- | Read and Write |
7 | 111 | rwx | Read, Write and Execute |
Two ways to Change the Permissions
The chmod command provides multiple ways to change and manipulate permissions on files and folders. Below are two of the most common ways that it is used, but you can use the man chmod command to find out more information and ways to use the command.
Setting Permissions with the Decimal Number Representation
The most common way to use the chmod command is to specify the decimal number for the permissions for each set of users and then specify the file name, as shown below.
chmod <UserDecimal#><GroupDecimal#><OtherDecimal#> <Filename>
You can refer to the table above if needed to determine what numbers to use for your permissions, but it may help to see an example so let’s set the permissions for a file called test.zip.
I would like this file to have read and write permissions for the user (which is me) and read permissions for group members and no permissions for others. Looking at the table above, this would give the following values.
User = read and write = rw- = 110 = 6
Group = read = r– = 100 = 4
Other = no permissions = — = 000 = 0
So my chmod command would be as shown below.
chmod 640 test.zip
Now I have decided to give all sets of users read and write permissions, so I would use 666 as shown below.
chmod 666 test.zip
Finally if I wanted to give everyone all permissions (read/write /execute) I would use 777.
chmod 777 test.zip
As you can see, there are many combinations, and using the chmod command with the decimal values for the permissions gives you the ability to set them any way that you would like. Don’t be afraid to play around with different combinations to see how it works.
Adding or Removing Permissions
Another common way to change file or folder permissions is to use the chmod command and specify the user set and the permission you would like to add or remove. This can be done in the following format.
chmod <user sets><+or-><permissions> <filename>
Where
- User sets = u, g, o or any combination of the three.
u=user, g=group, and o=other
- Use + to add the permission
Use – to remove the permission
- Permissions can be r, w, x, or any combination of the three.
r=read, w=write, and x=execute
For example, I have a file called test.zip which has all read/write/execute permissions (rwxrwxrwx). I would like to remove the write permissions from group and other so I would use the following command.
chmod go-w test.zip
Now I have decided that no one needs to have execute (x) permissions, so I will remove those with the command below.
chmod ugo-x test.zip
One more change is that I have now decided that the group should have write permissions, so I will add that back with the following command.
chmod g+w test.zip
Above are just a few examples, but you can use many combinations to change permissions. Don’t be afraid to create a test file yourself and try them out to see how it works.
FAQs
Below are some questions often asked when discussing how to change file or folder permissions on Mac Terminal.
Are there other ways to use the chmod command?
Yes. As with most commands in Mac Terminal, there are multiple ways to use it and many different parameters that let you do different things involving permissions. Take a look at the man page (type man chmod) of the chmod command to find out more.
Can I use the chmod command with multiple files and folders?
Yes, you can specify multiple files and folders in the command where I have shown <filename>. The format would be as shown below.
chmod ### file1 file2 file3 dir1 dir2
Can I use wildcards to specify multiple files with the chmod command?
Yes, you definitely can, and this is commonly used to change large numbers of files or all the files in a directory with a command such as chmod 644 *. You can also add the -R parameter so that the command will recurse any subdirectories in the path.
Just be careful to know what your wildcard statement will do and where you are running the command from. You probably don’t want to do something like this from the root directory.
Conclusion
You can use the chmod command to change the permissions of files and folders in Mac Terminal. There are multiple ways to do this, and I have shown two of the most common. I hope the information provided can help you to change any permissions that you need to change.
As usual, let me know if you have any questions or comments. I would love to hear from you!
Alex Amets
Good afternoon!
Erich Winkler how much useful you are doing! Wonderful stuff you offer! But I didn’t find the answer to the question I needed.
I have a problem with Final Cut Pro. This program takes a long time to read the Audio folder. How do I prevent Final Cut Pro from accessing the Audio folder?
Can you help me?
Thanks!
Eric
Hi Alex,
Thank you for the kind words. I enjoy solving problems and love to be able to help. I’m sorry to hear you are having this problem. I don’t have Final Cut Pro so I am not able to take a look at what is happening. I am wondering if there is a setting somewhere that you can use to prevent it from reading the folder. Changing permission will probably not do the trick because I would assume that the application has admin permissions on your computer and should be able to read the folder no matter what permissions are set on it. The only thing I can think of (without really knowing much about the application and what it is trying to do) would be to try renaming the Audio folder with another name and see if that prevents it from reading it. Not sure if that will work but just a thought. Good luck and I hope you are able to get things working.