Modify permissions to -rwxr-xr-x [duplicate]
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO9GURib1T8z7lCwjOGLQaGtrueEthgQ8LO42ZX8cOfTqDK4jvDDpKkLFwf2J49kYCMNW7d4ABih_XCb_2UXdq5fPJDkoyg7-8g_YfRUot-XnaXkNYycsNp7lA5_TW9td0FFpLQ2APzKcZ/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQ0N5W1qAOxLP7t7iOM6O6AzbZnkXUy16s7P_CWfOb5UbTQY_aDsc727chyphenhyphen5W4IppVNernMMQeaUFTB_rFzAd95_CDt-tnwN-nBx6JyUp2duGjPaL5-VgNO41AVsA_vu30EJcipdDG409/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
up vote
0
down vote
favorite
This question already has an answer here:
How do file permissions work?
2 answers
I need some help with a homework problem to modify a file's permissions. It wants it to be -rwxr-xr-x
? Not sure how to make the user permissions. Thank you.
permissions chmod
marked as duplicate by Fabby, muru, Eric Carvalho, Thomas Ward⦠Apr 24 at 19:30
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
up vote
0
down vote
favorite
This question already has an answer here:
How do file permissions work?
2 answers
I need some help with a homework problem to modify a file's permissions. It wants it to be -rwxr-xr-x
? Not sure how to make the user permissions. Thank you.
permissions chmod
marked as duplicate by Fabby, muru, Eric Carvalho, Thomas Ward⦠Apr 24 at 19:30
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
This question already has an answer here:
How do file permissions work?
2 answers
I need some help with a homework problem to modify a file's permissions. It wants it to be -rwxr-xr-x
? Not sure how to make the user permissions. Thank you.
permissions chmod
This question already has an answer here:
How do file permissions work?
2 answers
I need some help with a homework problem to modify a file's permissions. It wants it to be -rwxr-xr-x
? Not sure how to make the user permissions. Thank you.
This question already has an answer here:
How do file permissions work?
2 answers
permissions chmod
edited Apr 21 at 19:13
![](https://i.stack.imgur.com/8CW8e.png?s=32&g=1)
![](https://i.stack.imgur.com/8CW8e.png?s=32&g=1)
Zanna
48k13119227
48k13119227
asked Apr 21 at 17:45
Rich
133
133
marked as duplicate by Fabby, muru, Eric Carvalho, Thomas Ward⦠Apr 24 at 19:30
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Fabby, muru, Eric Carvalho, Thomas Ward⦠Apr 24 at 19:30
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
add a comment |Â
5 Answers
5
active
oldest
votes
up vote
11
down vote
Lets analyze your homework: -rwxr-xr-x
, break them into three parts -rwx|r-x|r-x
:
rwx
: read, write and execute for user or ownerr-x
: read, no write, and execute for group membersr-x
: same as in2
but this time for every other person akaothers
.
No you will need to run the command using the change permission program chmod
like so:
chmod 755 filename
Explained:
change the permission to:
- user: 7 => r(4), w(2), x(1)
- group: 5 => r(4), -, x(1)
- others: r(4), -, x(1)
Now you have to own that file or folder to do this or be in the sudo group.
1
Also thesudo
is only needed for files you don't own, which is probably not the case as part of a homework.
â Byte Commander
Apr 21 at 18:00
Noted @Zanna and ByteCommander
â George Udosen
Apr 21 at 18:03
It worked, just got a little confused on the user's permission, but understand clearly now, Thanks everybody for your help.
â Rich
Apr 21 at 18:12
add a comment |Â
up vote
10
down vote
There's also a more "talkative" version to set permissions:
chmod u=rwx,g=rx,o=rx filename
This means:
- give the user (
u=
)rwx
permissions, and - give the group (
g=
)rx
permissions, and - give others (
o=
)rx
permissions.
You can leave out the parts that you do not want to change, e.g.:
chmod u=rwx filename
will set the user's permissions and leave the others as they are.
You can even "add" or "substract" permissions:
chmod g-x filename
will remove the group's x
permission, and
chmod o+w filename
will add write permission for others.
To set SUID, SGID, and sticky bit use the s
and t
permissions:
chmod u+s filename
-- sets SUIDchmod g+s filename
-- sets SGIDchmod a+t filename
-- sets sticky bit (a
means "all", i.e.u
andg
ando
)
So which method would this be, SGUID, SGID or sticky bit? How would I do the others using this method?
â Rich
Apr 21 at 18:33
@Rich I updated my answer.
â PerlDuck
Apr 21 at 18:46
But sticky bit is only for directories, can it be used for text files? Would these the same commands for fedora?
â Rich
Apr 21 at 18:53
Good catch. I forgot that. Linux ignores the sticky bit for files, but other OSes honor it. And yes, the commands work an any Unixy OS.
â PerlDuck
Apr 21 at 18:58
@Rich the horse has bolted, but if you're using fedora, you shouldn't be asking questions here on Ask Ubuntu...
â Zanna
Apr 21 at 18:59
 |Â
show 3 more comments
up vote
6
down vote
Obligatory Preamble
Modifying permissions of important files and directories in your system can break things badly. If you would find it inconvenient to have to reinstall your system or retrieve data from a live session, make sure you experiment with permissions and ownership safely. While you're learning your way around the filesystem and basic commands, you should avoid running chmod
and chown
with sudo
or in a root shell. That way, a permission error will let you know that you might be doing something risky and you should check the command again.
We change file permissions with chmod
. This command has a recursive flag -R
. This flag is often used unnecessarily, and it is rarely useful, because we don't usually want directories to have the same permissions as the files inside them. Directories need execute permission to be entered, so aren't useful without it, while files only need execute permission if they are programs. Without the -R
flag, chmod
can do only limited and repairable damage, but with -R
you can make a terrible mess of your system in a single command. If you are using -R
, consider whether you really need it, and check the file path for typos.
The mode you have been asked to give the file is a common one
-rwxr-xr-x
The leading dash indicates that this is a regular file. The x
bits in three places indicate that it needs to be executable by any user. So, this mode is appropriate for programs that anyone can execute. Most programs on your system have this mode, as you can see by examining the files in /usr/bin
, /bin
and so on (I explain how to examine permissions later in this answer). It's important for security that only the owner, root, can write to (modify) these files, so the programs you run can't be accidentally (or otherwise) changed by users without root privileges.
As pointed out in George Udosen's answer the permission bits are set separately for user (the owner of the file), group, and others. This is explained, for example, in our tag wiki for chmod
and in many other places on the internet, and even on your system; you can read about it by running man chmod
. You have been asked to make the file readable, writeable and executable by its owner, and readable and writeable for its group and others. You can see the owner and group of a file by running ls -ld file
(the -d
is only necessary if it's a directory; without that flag, ls
shows the content of the directory rather than the directory itself) or if you want less irrelevant information, use stat
:
stat -c '%U %G' file
-c
means control the output. %U
= file owner, %G
= group. file
should be replaced with the path to the file whose metadata you want to examine. If it's in the current directory, its name is sufficient, but you can give a path for files elsewhere:
$ stat -c '%U %G' /var/log/syslog
syslog adm
The stat
command can also show file permissions in octal and in "human readable" form:
stat -c '%n %a %A' *
(I used %n
to display the filenames, and *
to run stat
on every non-hidden file in the current directory.)
This provides a very useful reference if you ever forget what permission bits a particular octal number represents to chmod
, though vidarlo's answer provides a nice way to recall them.
I strongly recommend examining permissions of any file you care about before you change them, since you won't have any way to "reset" the original mode except setting it manually.
Other answers have explained how to set the file mode you need in octal notation. chmod
accepts file mode in symbolic notation as well as octal, and this is useful when you only want to modify one permission bit (one letter in that rwxr-xr-x
string). Perl Duck's answer explains how to do this to set the mode you want.
When I create a script and I want to make it executable, which is the main reason I use chmod
, I use symbolic notation to give myself execute permission and make no other changes, with this command:
chmod u+x file
If the script needs to be executable by all users, I would run that without u
:
chmod +x file
This would probably be sufficient in your current situation, since files are often created by default with permissions that allow reading and writing by the owner and only readable for group and others, but it's also likely that they are created with write permission for the group. This depends on the umask
setting a user has when they create the file. Let's create a file and take a look at it!
$ touch somefile
$ stat -c '%a %A' somefile
664 -rw-rw-r--
OK. So to get mode 755
I need to remove the w
bit from the g
section, and add the x
bit everywhere.
In symbolic notation, I can do that this way:
$ chmod +x,g-w somefile
$ stat -c '%a %A' somefile
755 -rwxr-xr-x
Another way to write +x
in chmod
is a+x
. a
stands for all, which is assumed if no letter is given. Important to note: u
stands for user, which means the owner, while o
stands for others (not owner).
You can also set all the bits for a
u
g
or o
with the =
sign. Here's me playing around with useless permission settings:
$ chmod =x somefile
$ stat -c '%a %A' somefile
111 ---x--x--x
$ chmod u=r,g=rwx,o= somefile
$ stat -c '%a %A' somefile
470 -r--rwx---
You can use both octal and symbolic notation to add special bits like setuid (this allows running a program as its owner, so is dangerous) and setgid (this causes files created in a directory with setgid subsequently to inherit the directory's group ownership, which is useful because it allows you to control permissions for a group of users in a certain filesystem location without having to constantly fiddle with it).
Some folks like octal notation, some like symbolic. The latter is a little more flexible and maybe a little more intuitive for some. I recommend testing and learning both (safely!) so you'll be able to figure out what any chmod
command will do when you see it, and solve any homework problem about it with flair :)
TL;DR
- Be careful with
chmod
. Don't usesudo chmod
unless you know what you're doing. Think carefully before using the-R
flag. - Look at the existing permissions first.
stat
is your friend - Learn both symbolic and octal notation.
add a comment |Â
up vote
4
down vote
The syntax for chmod
command is :
chmod [options] permissions file-name
Before setting the file/folder permissions you need to be in the Parent Directory
of the file/folder.
r(read) - 4
w(write) - 2
x(execute) - 1
Now, analyzing the set from your work: (-rwxr-xr-x)
Divide it into four parts as :
1. - File Type
2. rwx User
3. r-x Group
4. r-x Others
Thus, Finally to give permision to your file :
2. rwx : 4+2+1 = 7
3. r-x : 4+0+1 = 5
4. r-x : 4+0+1 = 5
Hence, The command is
chmod 755 *filename*
add a comment |Â
up vote
4
down vote
I find it easiest to think in octal permissions:
- 1 equals execute
- 2 equals write
- 4 equals read
This can easily be seen setting it up bitwise:
r w x
0 0 1 #Execute = 1
0 1 0 #Write = 2
1 0 0 #Read = 4
1 0 1 #Read + Execute = 5
1 1 0 #Read + Write = 6
1 1 1 #All permissions = 7
These can be added. Read and execute is 4+1=5. Read, execute and write is 7 (4+2+1), write only is 2, and so forth.
There's three digits to the permissions: User, Group and Other. rwx for user becomes 7 (full permissions) for first digit. r-x for group becomes 1+4=5, and r-x for other becomes 5. Thus this equals permissions 755.
add a comment |Â
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
11
down vote
Lets analyze your homework: -rwxr-xr-x
, break them into three parts -rwx|r-x|r-x
:
rwx
: read, write and execute for user or ownerr-x
: read, no write, and execute for group membersr-x
: same as in2
but this time for every other person akaothers
.
No you will need to run the command using the change permission program chmod
like so:
chmod 755 filename
Explained:
change the permission to:
- user: 7 => r(4), w(2), x(1)
- group: 5 => r(4), -, x(1)
- others: r(4), -, x(1)
Now you have to own that file or folder to do this or be in the sudo group.
1
Also thesudo
is only needed for files you don't own, which is probably not the case as part of a homework.
â Byte Commander
Apr 21 at 18:00
Noted @Zanna and ByteCommander
â George Udosen
Apr 21 at 18:03
It worked, just got a little confused on the user's permission, but understand clearly now, Thanks everybody for your help.
â Rich
Apr 21 at 18:12
add a comment |Â
up vote
11
down vote
Lets analyze your homework: -rwxr-xr-x
, break them into three parts -rwx|r-x|r-x
:
rwx
: read, write and execute for user or ownerr-x
: read, no write, and execute for group membersr-x
: same as in2
but this time for every other person akaothers
.
No you will need to run the command using the change permission program chmod
like so:
chmod 755 filename
Explained:
change the permission to:
- user: 7 => r(4), w(2), x(1)
- group: 5 => r(4), -, x(1)
- others: r(4), -, x(1)
Now you have to own that file or folder to do this or be in the sudo group.
1
Also thesudo
is only needed for files you don't own, which is probably not the case as part of a homework.
â Byte Commander
Apr 21 at 18:00
Noted @Zanna and ByteCommander
â George Udosen
Apr 21 at 18:03
It worked, just got a little confused on the user's permission, but understand clearly now, Thanks everybody for your help.
â Rich
Apr 21 at 18:12
add a comment |Â
up vote
11
down vote
up vote
11
down vote
Lets analyze your homework: -rwxr-xr-x
, break them into three parts -rwx|r-x|r-x
:
rwx
: read, write and execute for user or ownerr-x
: read, no write, and execute for group membersr-x
: same as in2
but this time for every other person akaothers
.
No you will need to run the command using the change permission program chmod
like so:
chmod 755 filename
Explained:
change the permission to:
- user: 7 => r(4), w(2), x(1)
- group: 5 => r(4), -, x(1)
- others: r(4), -, x(1)
Now you have to own that file or folder to do this or be in the sudo group.
Lets analyze your homework: -rwxr-xr-x
, break them into three parts -rwx|r-x|r-x
:
rwx
: read, write and execute for user or ownerr-x
: read, no write, and execute for group membersr-x
: same as in2
but this time for every other person akaothers
.
No you will need to run the command using the change permission program chmod
like so:
chmod 755 filename
Explained:
change the permission to:
- user: 7 => r(4), w(2), x(1)
- group: 5 => r(4), -, x(1)
- others: r(4), -, x(1)
Now you have to own that file or folder to do this or be in the sudo group.
edited Apr 21 at 18:01
answered Apr 21 at 17:58
![](https://i.stack.imgur.com/ElvwO.jpg?s=32&g=1)
![](https://i.stack.imgur.com/ElvwO.jpg?s=32&g=1)
George Udosen
17k93559
17k93559
1
Also thesudo
is only needed for files you don't own, which is probably not the case as part of a homework.
â Byte Commander
Apr 21 at 18:00
Noted @Zanna and ByteCommander
â George Udosen
Apr 21 at 18:03
It worked, just got a little confused on the user's permission, but understand clearly now, Thanks everybody for your help.
â Rich
Apr 21 at 18:12
add a comment |Â
1
Also thesudo
is only needed for files you don't own, which is probably not the case as part of a homework.
â Byte Commander
Apr 21 at 18:00
Noted @Zanna and ByteCommander
â George Udosen
Apr 21 at 18:03
It worked, just got a little confused on the user's permission, but understand clearly now, Thanks everybody for your help.
â Rich
Apr 21 at 18:12
1
1
Also the
sudo
is only needed for files you don't own, which is probably not the case as part of a homework.â Byte Commander
Apr 21 at 18:00
Also the
sudo
is only needed for files you don't own, which is probably not the case as part of a homework.â Byte Commander
Apr 21 at 18:00
Noted @Zanna and ByteCommander
â George Udosen
Apr 21 at 18:03
Noted @Zanna and ByteCommander
â George Udosen
Apr 21 at 18:03
It worked, just got a little confused on the user's permission, but understand clearly now, Thanks everybody for your help.
â Rich
Apr 21 at 18:12
It worked, just got a little confused on the user's permission, but understand clearly now, Thanks everybody for your help.
â Rich
Apr 21 at 18:12
add a comment |Â
up vote
10
down vote
There's also a more "talkative" version to set permissions:
chmod u=rwx,g=rx,o=rx filename
This means:
- give the user (
u=
)rwx
permissions, and - give the group (
g=
)rx
permissions, and - give others (
o=
)rx
permissions.
You can leave out the parts that you do not want to change, e.g.:
chmod u=rwx filename
will set the user's permissions and leave the others as they are.
You can even "add" or "substract" permissions:
chmod g-x filename
will remove the group's x
permission, and
chmod o+w filename
will add write permission for others.
To set SUID, SGID, and sticky bit use the s
and t
permissions:
chmod u+s filename
-- sets SUIDchmod g+s filename
-- sets SGIDchmod a+t filename
-- sets sticky bit (a
means "all", i.e.u
andg
ando
)
So which method would this be, SGUID, SGID or sticky bit? How would I do the others using this method?
â Rich
Apr 21 at 18:33
@Rich I updated my answer.
â PerlDuck
Apr 21 at 18:46
But sticky bit is only for directories, can it be used for text files? Would these the same commands for fedora?
â Rich
Apr 21 at 18:53
Good catch. I forgot that. Linux ignores the sticky bit for files, but other OSes honor it. And yes, the commands work an any Unixy OS.
â PerlDuck
Apr 21 at 18:58
@Rich the horse has bolted, but if you're using fedora, you shouldn't be asking questions here on Ask Ubuntu...
â Zanna
Apr 21 at 18:59
 |Â
show 3 more comments
up vote
10
down vote
There's also a more "talkative" version to set permissions:
chmod u=rwx,g=rx,o=rx filename
This means:
- give the user (
u=
)rwx
permissions, and - give the group (
g=
)rx
permissions, and - give others (
o=
)rx
permissions.
You can leave out the parts that you do not want to change, e.g.:
chmod u=rwx filename
will set the user's permissions and leave the others as they are.
You can even "add" or "substract" permissions:
chmod g-x filename
will remove the group's x
permission, and
chmod o+w filename
will add write permission for others.
To set SUID, SGID, and sticky bit use the s
and t
permissions:
chmod u+s filename
-- sets SUIDchmod g+s filename
-- sets SGIDchmod a+t filename
-- sets sticky bit (a
means "all", i.e.u
andg
ando
)
So which method would this be, SGUID, SGID or sticky bit? How would I do the others using this method?
â Rich
Apr 21 at 18:33
@Rich I updated my answer.
â PerlDuck
Apr 21 at 18:46
But sticky bit is only for directories, can it be used for text files? Would these the same commands for fedora?
â Rich
Apr 21 at 18:53
Good catch. I forgot that. Linux ignores the sticky bit for files, but other OSes honor it. And yes, the commands work an any Unixy OS.
â PerlDuck
Apr 21 at 18:58
@Rich the horse has bolted, but if you're using fedora, you shouldn't be asking questions here on Ask Ubuntu...
â Zanna
Apr 21 at 18:59
 |Â
show 3 more comments
up vote
10
down vote
up vote
10
down vote
There's also a more "talkative" version to set permissions:
chmod u=rwx,g=rx,o=rx filename
This means:
- give the user (
u=
)rwx
permissions, and - give the group (
g=
)rx
permissions, and - give others (
o=
)rx
permissions.
You can leave out the parts that you do not want to change, e.g.:
chmod u=rwx filename
will set the user's permissions and leave the others as they are.
You can even "add" or "substract" permissions:
chmod g-x filename
will remove the group's x
permission, and
chmod o+w filename
will add write permission for others.
To set SUID, SGID, and sticky bit use the s
and t
permissions:
chmod u+s filename
-- sets SUIDchmod g+s filename
-- sets SGIDchmod a+t filename
-- sets sticky bit (a
means "all", i.e.u
andg
ando
)
There's also a more "talkative" version to set permissions:
chmod u=rwx,g=rx,o=rx filename
This means:
- give the user (
u=
)rwx
permissions, and - give the group (
g=
)rx
permissions, and - give others (
o=
)rx
permissions.
You can leave out the parts that you do not want to change, e.g.:
chmod u=rwx filename
will set the user's permissions and leave the others as they are.
You can even "add" or "substract" permissions:
chmod g-x filename
will remove the group's x
permission, and
chmod o+w filename
will add write permission for others.
To set SUID, SGID, and sticky bit use the s
and t
permissions:
chmod u+s filename
-- sets SUIDchmod g+s filename
-- sets SGIDchmod a+t filename
-- sets sticky bit (a
means "all", i.e.u
andg
ando
)
edited Apr 21 at 18:45
answered Apr 21 at 18:24
![](https://i.stack.imgur.com/kCmqs.png?s=32&g=1)
![](https://i.stack.imgur.com/kCmqs.png?s=32&g=1)
PerlDuck
3,80311030
3,80311030
So which method would this be, SGUID, SGID or sticky bit? How would I do the others using this method?
â Rich
Apr 21 at 18:33
@Rich I updated my answer.
â PerlDuck
Apr 21 at 18:46
But sticky bit is only for directories, can it be used for text files? Would these the same commands for fedora?
â Rich
Apr 21 at 18:53
Good catch. I forgot that. Linux ignores the sticky bit for files, but other OSes honor it. And yes, the commands work an any Unixy OS.
â PerlDuck
Apr 21 at 18:58
@Rich the horse has bolted, but if you're using fedora, you shouldn't be asking questions here on Ask Ubuntu...
â Zanna
Apr 21 at 18:59
 |Â
show 3 more comments
So which method would this be, SGUID, SGID or sticky bit? How would I do the others using this method?
â Rich
Apr 21 at 18:33
@Rich I updated my answer.
â PerlDuck
Apr 21 at 18:46
But sticky bit is only for directories, can it be used for text files? Would these the same commands for fedora?
â Rich
Apr 21 at 18:53
Good catch. I forgot that. Linux ignores the sticky bit for files, but other OSes honor it. And yes, the commands work an any Unixy OS.
â PerlDuck
Apr 21 at 18:58
@Rich the horse has bolted, but if you're using fedora, you shouldn't be asking questions here on Ask Ubuntu...
â Zanna
Apr 21 at 18:59
So which method would this be, SGUID, SGID or sticky bit? How would I do the others using this method?
â Rich
Apr 21 at 18:33
So which method would this be, SGUID, SGID or sticky bit? How would I do the others using this method?
â Rich
Apr 21 at 18:33
@Rich I updated my answer.
â PerlDuck
Apr 21 at 18:46
@Rich I updated my answer.
â PerlDuck
Apr 21 at 18:46
But sticky bit is only for directories, can it be used for text files? Would these the same commands for fedora?
â Rich
Apr 21 at 18:53
But sticky bit is only for directories, can it be used for text files? Would these the same commands for fedora?
â Rich
Apr 21 at 18:53
Good catch. I forgot that. Linux ignores the sticky bit for files, but other OSes honor it. And yes, the commands work an any Unixy OS.
â PerlDuck
Apr 21 at 18:58
Good catch. I forgot that. Linux ignores the sticky bit for files, but other OSes honor it. And yes, the commands work an any Unixy OS.
â PerlDuck
Apr 21 at 18:58
@Rich the horse has bolted, but if you're using fedora, you shouldn't be asking questions here on Ask Ubuntu...
â Zanna
Apr 21 at 18:59
@Rich the horse has bolted, but if you're using fedora, you shouldn't be asking questions here on Ask Ubuntu...
â Zanna
Apr 21 at 18:59
 |Â
show 3 more comments
up vote
6
down vote
Obligatory Preamble
Modifying permissions of important files and directories in your system can break things badly. If you would find it inconvenient to have to reinstall your system or retrieve data from a live session, make sure you experiment with permissions and ownership safely. While you're learning your way around the filesystem and basic commands, you should avoid running chmod
and chown
with sudo
or in a root shell. That way, a permission error will let you know that you might be doing something risky and you should check the command again.
We change file permissions with chmod
. This command has a recursive flag -R
. This flag is often used unnecessarily, and it is rarely useful, because we don't usually want directories to have the same permissions as the files inside them. Directories need execute permission to be entered, so aren't useful without it, while files only need execute permission if they are programs. Without the -R
flag, chmod
can do only limited and repairable damage, but with -R
you can make a terrible mess of your system in a single command. If you are using -R
, consider whether you really need it, and check the file path for typos.
The mode you have been asked to give the file is a common one
-rwxr-xr-x
The leading dash indicates that this is a regular file. The x
bits in three places indicate that it needs to be executable by any user. So, this mode is appropriate for programs that anyone can execute. Most programs on your system have this mode, as you can see by examining the files in /usr/bin
, /bin
and so on (I explain how to examine permissions later in this answer). It's important for security that only the owner, root, can write to (modify) these files, so the programs you run can't be accidentally (or otherwise) changed by users without root privileges.
As pointed out in George Udosen's answer the permission bits are set separately for user (the owner of the file), group, and others. This is explained, for example, in our tag wiki for chmod
and in many other places on the internet, and even on your system; you can read about it by running man chmod
. You have been asked to make the file readable, writeable and executable by its owner, and readable and writeable for its group and others. You can see the owner and group of a file by running ls -ld file
(the -d
is only necessary if it's a directory; without that flag, ls
shows the content of the directory rather than the directory itself) or if you want less irrelevant information, use stat
:
stat -c '%U %G' file
-c
means control the output. %U
= file owner, %G
= group. file
should be replaced with the path to the file whose metadata you want to examine. If it's in the current directory, its name is sufficient, but you can give a path for files elsewhere:
$ stat -c '%U %G' /var/log/syslog
syslog adm
The stat
command can also show file permissions in octal and in "human readable" form:
stat -c '%n %a %A' *
(I used %n
to display the filenames, and *
to run stat
on every non-hidden file in the current directory.)
This provides a very useful reference if you ever forget what permission bits a particular octal number represents to chmod
, though vidarlo's answer provides a nice way to recall them.
I strongly recommend examining permissions of any file you care about before you change them, since you won't have any way to "reset" the original mode except setting it manually.
Other answers have explained how to set the file mode you need in octal notation. chmod
accepts file mode in symbolic notation as well as octal, and this is useful when you only want to modify one permission bit (one letter in that rwxr-xr-x
string). Perl Duck's answer explains how to do this to set the mode you want.
When I create a script and I want to make it executable, which is the main reason I use chmod
, I use symbolic notation to give myself execute permission and make no other changes, with this command:
chmod u+x file
If the script needs to be executable by all users, I would run that without u
:
chmod +x file
This would probably be sufficient in your current situation, since files are often created by default with permissions that allow reading and writing by the owner and only readable for group and others, but it's also likely that they are created with write permission for the group. This depends on the umask
setting a user has when they create the file. Let's create a file and take a look at it!
$ touch somefile
$ stat -c '%a %A' somefile
664 -rw-rw-r--
OK. So to get mode 755
I need to remove the w
bit from the g
section, and add the x
bit everywhere.
In symbolic notation, I can do that this way:
$ chmod +x,g-w somefile
$ stat -c '%a %A' somefile
755 -rwxr-xr-x
Another way to write +x
in chmod
is a+x
. a
stands for all, which is assumed if no letter is given. Important to note: u
stands for user, which means the owner, while o
stands for others (not owner).
You can also set all the bits for a
u
g
or o
with the =
sign. Here's me playing around with useless permission settings:
$ chmod =x somefile
$ stat -c '%a %A' somefile
111 ---x--x--x
$ chmod u=r,g=rwx,o= somefile
$ stat -c '%a %A' somefile
470 -r--rwx---
You can use both octal and symbolic notation to add special bits like setuid (this allows running a program as its owner, so is dangerous) and setgid (this causes files created in a directory with setgid subsequently to inherit the directory's group ownership, which is useful because it allows you to control permissions for a group of users in a certain filesystem location without having to constantly fiddle with it).
Some folks like octal notation, some like symbolic. The latter is a little more flexible and maybe a little more intuitive for some. I recommend testing and learning both (safely!) so you'll be able to figure out what any chmod
command will do when you see it, and solve any homework problem about it with flair :)
TL;DR
- Be careful with
chmod
. Don't usesudo chmod
unless you know what you're doing. Think carefully before using the-R
flag. - Look at the existing permissions first.
stat
is your friend - Learn both symbolic and octal notation.
add a comment |Â
up vote
6
down vote
Obligatory Preamble
Modifying permissions of important files and directories in your system can break things badly. If you would find it inconvenient to have to reinstall your system or retrieve data from a live session, make sure you experiment with permissions and ownership safely. While you're learning your way around the filesystem and basic commands, you should avoid running chmod
and chown
with sudo
or in a root shell. That way, a permission error will let you know that you might be doing something risky and you should check the command again.
We change file permissions with chmod
. This command has a recursive flag -R
. This flag is often used unnecessarily, and it is rarely useful, because we don't usually want directories to have the same permissions as the files inside them. Directories need execute permission to be entered, so aren't useful without it, while files only need execute permission if they are programs. Without the -R
flag, chmod
can do only limited and repairable damage, but with -R
you can make a terrible mess of your system in a single command. If you are using -R
, consider whether you really need it, and check the file path for typos.
The mode you have been asked to give the file is a common one
-rwxr-xr-x
The leading dash indicates that this is a regular file. The x
bits in three places indicate that it needs to be executable by any user. So, this mode is appropriate for programs that anyone can execute. Most programs on your system have this mode, as you can see by examining the files in /usr/bin
, /bin
and so on (I explain how to examine permissions later in this answer). It's important for security that only the owner, root, can write to (modify) these files, so the programs you run can't be accidentally (or otherwise) changed by users without root privileges.
As pointed out in George Udosen's answer the permission bits are set separately for user (the owner of the file), group, and others. This is explained, for example, in our tag wiki for chmod
and in many other places on the internet, and even on your system; you can read about it by running man chmod
. You have been asked to make the file readable, writeable and executable by its owner, and readable and writeable for its group and others. You can see the owner and group of a file by running ls -ld file
(the -d
is only necessary if it's a directory; without that flag, ls
shows the content of the directory rather than the directory itself) or if you want less irrelevant information, use stat
:
stat -c '%U %G' file
-c
means control the output. %U
= file owner, %G
= group. file
should be replaced with the path to the file whose metadata you want to examine. If it's in the current directory, its name is sufficient, but you can give a path for files elsewhere:
$ stat -c '%U %G' /var/log/syslog
syslog adm
The stat
command can also show file permissions in octal and in "human readable" form:
stat -c '%n %a %A' *
(I used %n
to display the filenames, and *
to run stat
on every non-hidden file in the current directory.)
This provides a very useful reference if you ever forget what permission bits a particular octal number represents to chmod
, though vidarlo's answer provides a nice way to recall them.
I strongly recommend examining permissions of any file you care about before you change them, since you won't have any way to "reset" the original mode except setting it manually.
Other answers have explained how to set the file mode you need in octal notation. chmod
accepts file mode in symbolic notation as well as octal, and this is useful when you only want to modify one permission bit (one letter in that rwxr-xr-x
string). Perl Duck's answer explains how to do this to set the mode you want.
When I create a script and I want to make it executable, which is the main reason I use chmod
, I use symbolic notation to give myself execute permission and make no other changes, with this command:
chmod u+x file
If the script needs to be executable by all users, I would run that without u
:
chmod +x file
This would probably be sufficient in your current situation, since files are often created by default with permissions that allow reading and writing by the owner and only readable for group and others, but it's also likely that they are created with write permission for the group. This depends on the umask
setting a user has when they create the file. Let's create a file and take a look at it!
$ touch somefile
$ stat -c '%a %A' somefile
664 -rw-rw-r--
OK. So to get mode 755
I need to remove the w
bit from the g
section, and add the x
bit everywhere.
In symbolic notation, I can do that this way:
$ chmod +x,g-w somefile
$ stat -c '%a %A' somefile
755 -rwxr-xr-x
Another way to write +x
in chmod
is a+x
. a
stands for all, which is assumed if no letter is given. Important to note: u
stands for user, which means the owner, while o
stands for others (not owner).
You can also set all the bits for a
u
g
or o
with the =
sign. Here's me playing around with useless permission settings:
$ chmod =x somefile
$ stat -c '%a %A' somefile
111 ---x--x--x
$ chmod u=r,g=rwx,o= somefile
$ stat -c '%a %A' somefile
470 -r--rwx---
You can use both octal and symbolic notation to add special bits like setuid (this allows running a program as its owner, so is dangerous) and setgid (this causes files created in a directory with setgid subsequently to inherit the directory's group ownership, which is useful because it allows you to control permissions for a group of users in a certain filesystem location without having to constantly fiddle with it).
Some folks like octal notation, some like symbolic. The latter is a little more flexible and maybe a little more intuitive for some. I recommend testing and learning both (safely!) so you'll be able to figure out what any chmod
command will do when you see it, and solve any homework problem about it with flair :)
TL;DR
- Be careful with
chmod
. Don't usesudo chmod
unless you know what you're doing. Think carefully before using the-R
flag. - Look at the existing permissions first.
stat
is your friend - Learn both symbolic and octal notation.
add a comment |Â
up vote
6
down vote
up vote
6
down vote
Obligatory Preamble
Modifying permissions of important files and directories in your system can break things badly. If you would find it inconvenient to have to reinstall your system or retrieve data from a live session, make sure you experiment with permissions and ownership safely. While you're learning your way around the filesystem and basic commands, you should avoid running chmod
and chown
with sudo
or in a root shell. That way, a permission error will let you know that you might be doing something risky and you should check the command again.
We change file permissions with chmod
. This command has a recursive flag -R
. This flag is often used unnecessarily, and it is rarely useful, because we don't usually want directories to have the same permissions as the files inside them. Directories need execute permission to be entered, so aren't useful without it, while files only need execute permission if they are programs. Without the -R
flag, chmod
can do only limited and repairable damage, but with -R
you can make a terrible mess of your system in a single command. If you are using -R
, consider whether you really need it, and check the file path for typos.
The mode you have been asked to give the file is a common one
-rwxr-xr-x
The leading dash indicates that this is a regular file. The x
bits in three places indicate that it needs to be executable by any user. So, this mode is appropriate for programs that anyone can execute. Most programs on your system have this mode, as you can see by examining the files in /usr/bin
, /bin
and so on (I explain how to examine permissions later in this answer). It's important for security that only the owner, root, can write to (modify) these files, so the programs you run can't be accidentally (or otherwise) changed by users without root privileges.
As pointed out in George Udosen's answer the permission bits are set separately for user (the owner of the file), group, and others. This is explained, for example, in our tag wiki for chmod
and in many other places on the internet, and even on your system; you can read about it by running man chmod
. You have been asked to make the file readable, writeable and executable by its owner, and readable and writeable for its group and others. You can see the owner and group of a file by running ls -ld file
(the -d
is only necessary if it's a directory; without that flag, ls
shows the content of the directory rather than the directory itself) or if you want less irrelevant information, use stat
:
stat -c '%U %G' file
-c
means control the output. %U
= file owner, %G
= group. file
should be replaced with the path to the file whose metadata you want to examine. If it's in the current directory, its name is sufficient, but you can give a path for files elsewhere:
$ stat -c '%U %G' /var/log/syslog
syslog adm
The stat
command can also show file permissions in octal and in "human readable" form:
stat -c '%n %a %A' *
(I used %n
to display the filenames, and *
to run stat
on every non-hidden file in the current directory.)
This provides a very useful reference if you ever forget what permission bits a particular octal number represents to chmod
, though vidarlo's answer provides a nice way to recall them.
I strongly recommend examining permissions of any file you care about before you change them, since you won't have any way to "reset" the original mode except setting it manually.
Other answers have explained how to set the file mode you need in octal notation. chmod
accepts file mode in symbolic notation as well as octal, and this is useful when you only want to modify one permission bit (one letter in that rwxr-xr-x
string). Perl Duck's answer explains how to do this to set the mode you want.
When I create a script and I want to make it executable, which is the main reason I use chmod
, I use symbolic notation to give myself execute permission and make no other changes, with this command:
chmod u+x file
If the script needs to be executable by all users, I would run that without u
:
chmod +x file
This would probably be sufficient in your current situation, since files are often created by default with permissions that allow reading and writing by the owner and only readable for group and others, but it's also likely that they are created with write permission for the group. This depends on the umask
setting a user has when they create the file. Let's create a file and take a look at it!
$ touch somefile
$ stat -c '%a %A' somefile
664 -rw-rw-r--
OK. So to get mode 755
I need to remove the w
bit from the g
section, and add the x
bit everywhere.
In symbolic notation, I can do that this way:
$ chmod +x,g-w somefile
$ stat -c '%a %A' somefile
755 -rwxr-xr-x
Another way to write +x
in chmod
is a+x
. a
stands for all, which is assumed if no letter is given. Important to note: u
stands for user, which means the owner, while o
stands for others (not owner).
You can also set all the bits for a
u
g
or o
with the =
sign. Here's me playing around with useless permission settings:
$ chmod =x somefile
$ stat -c '%a %A' somefile
111 ---x--x--x
$ chmod u=r,g=rwx,o= somefile
$ stat -c '%a %A' somefile
470 -r--rwx---
You can use both octal and symbolic notation to add special bits like setuid (this allows running a program as its owner, so is dangerous) and setgid (this causes files created in a directory with setgid subsequently to inherit the directory's group ownership, which is useful because it allows you to control permissions for a group of users in a certain filesystem location without having to constantly fiddle with it).
Some folks like octal notation, some like symbolic. The latter is a little more flexible and maybe a little more intuitive for some. I recommend testing and learning both (safely!) so you'll be able to figure out what any chmod
command will do when you see it, and solve any homework problem about it with flair :)
TL;DR
- Be careful with
chmod
. Don't usesudo chmod
unless you know what you're doing. Think carefully before using the-R
flag. - Look at the existing permissions first.
stat
is your friend - Learn both symbolic and octal notation.
Obligatory Preamble
Modifying permissions of important files and directories in your system can break things badly. If you would find it inconvenient to have to reinstall your system or retrieve data from a live session, make sure you experiment with permissions and ownership safely. While you're learning your way around the filesystem and basic commands, you should avoid running chmod
and chown
with sudo
or in a root shell. That way, a permission error will let you know that you might be doing something risky and you should check the command again.
We change file permissions with chmod
. This command has a recursive flag -R
. This flag is often used unnecessarily, and it is rarely useful, because we don't usually want directories to have the same permissions as the files inside them. Directories need execute permission to be entered, so aren't useful without it, while files only need execute permission if they are programs. Without the -R
flag, chmod
can do only limited and repairable damage, but with -R
you can make a terrible mess of your system in a single command. If you are using -R
, consider whether you really need it, and check the file path for typos.
The mode you have been asked to give the file is a common one
-rwxr-xr-x
The leading dash indicates that this is a regular file. The x
bits in three places indicate that it needs to be executable by any user. So, this mode is appropriate for programs that anyone can execute. Most programs on your system have this mode, as you can see by examining the files in /usr/bin
, /bin
and so on (I explain how to examine permissions later in this answer). It's important for security that only the owner, root, can write to (modify) these files, so the programs you run can't be accidentally (or otherwise) changed by users without root privileges.
As pointed out in George Udosen's answer the permission bits are set separately for user (the owner of the file), group, and others. This is explained, for example, in our tag wiki for chmod
and in many other places on the internet, and even on your system; you can read about it by running man chmod
. You have been asked to make the file readable, writeable and executable by its owner, and readable and writeable for its group and others. You can see the owner and group of a file by running ls -ld file
(the -d
is only necessary if it's a directory; without that flag, ls
shows the content of the directory rather than the directory itself) or if you want less irrelevant information, use stat
:
stat -c '%U %G' file
-c
means control the output. %U
= file owner, %G
= group. file
should be replaced with the path to the file whose metadata you want to examine. If it's in the current directory, its name is sufficient, but you can give a path for files elsewhere:
$ stat -c '%U %G' /var/log/syslog
syslog adm
The stat
command can also show file permissions in octal and in "human readable" form:
stat -c '%n %a %A' *
(I used %n
to display the filenames, and *
to run stat
on every non-hidden file in the current directory.)
This provides a very useful reference if you ever forget what permission bits a particular octal number represents to chmod
, though vidarlo's answer provides a nice way to recall them.
I strongly recommend examining permissions of any file you care about before you change them, since you won't have any way to "reset" the original mode except setting it manually.
Other answers have explained how to set the file mode you need in octal notation. chmod
accepts file mode in symbolic notation as well as octal, and this is useful when you only want to modify one permission bit (one letter in that rwxr-xr-x
string). Perl Duck's answer explains how to do this to set the mode you want.
When I create a script and I want to make it executable, which is the main reason I use chmod
, I use symbolic notation to give myself execute permission and make no other changes, with this command:
chmod u+x file
If the script needs to be executable by all users, I would run that without u
:
chmod +x file
This would probably be sufficient in your current situation, since files are often created by default with permissions that allow reading and writing by the owner and only readable for group and others, but it's also likely that they are created with write permission for the group. This depends on the umask
setting a user has when they create the file. Let's create a file and take a look at it!
$ touch somefile
$ stat -c '%a %A' somefile
664 -rw-rw-r--
OK. So to get mode 755
I need to remove the w
bit from the g
section, and add the x
bit everywhere.
In symbolic notation, I can do that this way:
$ chmod +x,g-w somefile
$ stat -c '%a %A' somefile
755 -rwxr-xr-x
Another way to write +x
in chmod
is a+x
. a
stands for all, which is assumed if no letter is given. Important to note: u
stands for user, which means the owner, while o
stands for others (not owner).
You can also set all the bits for a
u
g
or o
with the =
sign. Here's me playing around with useless permission settings:
$ chmod =x somefile
$ stat -c '%a %A' somefile
111 ---x--x--x
$ chmod u=r,g=rwx,o= somefile
$ stat -c '%a %A' somefile
470 -r--rwx---
You can use both octal and symbolic notation to add special bits like setuid (this allows running a program as its owner, so is dangerous) and setgid (this causes files created in a directory with setgid subsequently to inherit the directory's group ownership, which is useful because it allows you to control permissions for a group of users in a certain filesystem location without having to constantly fiddle with it).
Some folks like octal notation, some like symbolic. The latter is a little more flexible and maybe a little more intuitive for some. I recommend testing and learning both (safely!) so you'll be able to figure out what any chmod
command will do when you see it, and solve any homework problem about it with flair :)
TL;DR
- Be careful with
chmod
. Don't usesudo chmod
unless you know what you're doing. Think carefully before using the-R
flag. - Look at the existing permissions first.
stat
is your friend - Learn both symbolic and octal notation.
edited Apr 22 at 5:53
answered Apr 21 at 19:08
![](https://i.stack.imgur.com/8CW8e.png?s=32&g=1)
![](https://i.stack.imgur.com/8CW8e.png?s=32&g=1)
Zanna
48k13119227
48k13119227
add a comment |Â
add a comment |Â
up vote
4
down vote
The syntax for chmod
command is :
chmod [options] permissions file-name
Before setting the file/folder permissions you need to be in the Parent Directory
of the file/folder.
r(read) - 4
w(write) - 2
x(execute) - 1
Now, analyzing the set from your work: (-rwxr-xr-x)
Divide it into four parts as :
1. - File Type
2. rwx User
3. r-x Group
4. r-x Others
Thus, Finally to give permision to your file :
2. rwx : 4+2+1 = 7
3. r-x : 4+0+1 = 5
4. r-x : 4+0+1 = 5
Hence, The command is
chmod 755 *filename*
add a comment |Â
up vote
4
down vote
The syntax for chmod
command is :
chmod [options] permissions file-name
Before setting the file/folder permissions you need to be in the Parent Directory
of the file/folder.
r(read) - 4
w(write) - 2
x(execute) - 1
Now, analyzing the set from your work: (-rwxr-xr-x)
Divide it into four parts as :
1. - File Type
2. rwx User
3. r-x Group
4. r-x Others
Thus, Finally to give permision to your file :
2. rwx : 4+2+1 = 7
3. r-x : 4+0+1 = 5
4. r-x : 4+0+1 = 5
Hence, The command is
chmod 755 *filename*
add a comment |Â
up vote
4
down vote
up vote
4
down vote
The syntax for chmod
command is :
chmod [options] permissions file-name
Before setting the file/folder permissions you need to be in the Parent Directory
of the file/folder.
r(read) - 4
w(write) - 2
x(execute) - 1
Now, analyzing the set from your work: (-rwxr-xr-x)
Divide it into four parts as :
1. - File Type
2. rwx User
3. r-x Group
4. r-x Others
Thus, Finally to give permision to your file :
2. rwx : 4+2+1 = 7
3. r-x : 4+0+1 = 5
4. r-x : 4+0+1 = 5
Hence, The command is
chmod 755 *filename*
The syntax for chmod
command is :
chmod [options] permissions file-name
Before setting the file/folder permissions you need to be in the Parent Directory
of the file/folder.
r(read) - 4
w(write) - 2
x(execute) - 1
Now, analyzing the set from your work: (-rwxr-xr-x)
Divide it into four parts as :
1. - File Type
2. rwx User
3. r-x Group
4. r-x Others
Thus, Finally to give permision to your file :
2. rwx : 4+2+1 = 7
3. r-x : 4+0+1 = 5
4. r-x : 4+0+1 = 5
Hence, The command is
chmod 755 *filename*
answered Apr 21 at 18:14
BoRRis
1412
1412
add a comment |Â
add a comment |Â
up vote
4
down vote
I find it easiest to think in octal permissions:
- 1 equals execute
- 2 equals write
- 4 equals read
This can easily be seen setting it up bitwise:
r w x
0 0 1 #Execute = 1
0 1 0 #Write = 2
1 0 0 #Read = 4
1 0 1 #Read + Execute = 5
1 1 0 #Read + Write = 6
1 1 1 #All permissions = 7
These can be added. Read and execute is 4+1=5. Read, execute and write is 7 (4+2+1), write only is 2, and so forth.
There's three digits to the permissions: User, Group and Other. rwx for user becomes 7 (full permissions) for first digit. r-x for group becomes 1+4=5, and r-x for other becomes 5. Thus this equals permissions 755.
add a comment |Â
up vote
4
down vote
I find it easiest to think in octal permissions:
- 1 equals execute
- 2 equals write
- 4 equals read
This can easily be seen setting it up bitwise:
r w x
0 0 1 #Execute = 1
0 1 0 #Write = 2
1 0 0 #Read = 4
1 0 1 #Read + Execute = 5
1 1 0 #Read + Write = 6
1 1 1 #All permissions = 7
These can be added. Read and execute is 4+1=5. Read, execute and write is 7 (4+2+1), write only is 2, and so forth.
There's three digits to the permissions: User, Group and Other. rwx for user becomes 7 (full permissions) for first digit. r-x for group becomes 1+4=5, and r-x for other becomes 5. Thus this equals permissions 755.
add a comment |Â
up vote
4
down vote
up vote
4
down vote
I find it easiest to think in octal permissions:
- 1 equals execute
- 2 equals write
- 4 equals read
This can easily be seen setting it up bitwise:
r w x
0 0 1 #Execute = 1
0 1 0 #Write = 2
1 0 0 #Read = 4
1 0 1 #Read + Execute = 5
1 1 0 #Read + Write = 6
1 1 1 #All permissions = 7
These can be added. Read and execute is 4+1=5. Read, execute and write is 7 (4+2+1), write only is 2, and so forth.
There's three digits to the permissions: User, Group and Other. rwx for user becomes 7 (full permissions) for first digit. r-x for group becomes 1+4=5, and r-x for other becomes 5. Thus this equals permissions 755.
I find it easiest to think in octal permissions:
- 1 equals execute
- 2 equals write
- 4 equals read
This can easily be seen setting it up bitwise:
r w x
0 0 1 #Execute = 1
0 1 0 #Write = 2
1 0 0 #Read = 4
1 0 1 #Read + Execute = 5
1 1 0 #Read + Write = 6
1 1 1 #All permissions = 7
These can be added. Read and execute is 4+1=5. Read, execute and write is 7 (4+2+1), write only is 2, and so forth.
There's three digits to the permissions: User, Group and Other. rwx for user becomes 7 (full permissions) for first digit. r-x for group becomes 1+4=5, and r-x for other becomes 5. Thus this equals permissions 755.
edited Apr 24 at 12:41
answered Apr 21 at 17:53
![](https://i.stack.imgur.com/AKwUL.png?s=32&g=1)
![](https://i.stack.imgur.com/AKwUL.png?s=32&g=1)
vidarlo
7,12342140
7,12342140
add a comment |Â
add a comment |Â