Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I added a file in /etc/init.d but noticed that the file isn't a green color like the other files when I do a ls -l What should I do to make it "green" or add the necessary file permissions?

Why are the files green in the first place?

share|improve this question
    
What other differences do you see with ls -l? –  Ignacio Vazquez-Abrams May 10 '11 at 1:44
    
The green ones have a lot more permissions than the non green one.. XP but the permissions aren't always the same. –  O_O May 10 '11 at 1:48
    
If you don't know the significance of the colour then should you really be putting files in this directory? –  symcbean May 10 '11 at 12:45

3 Answers 3

up vote 2 down vote accepted

To answer your question

All you need to do is run the following command as root.

chmod 755 /etc/init.d/yourscript

Now, if you want to actually know why this works, continue reading.

Background

Permission are very easy to understand once someone explains them to you. All files and directories have 3 types of permissions and 3 different groups of people that can have different permissions.

All users can have the following permissions on files and directories:

  • Read
    • Folder: You may see the files in the folder
    • File: You can read the file
  • Write
    • Folder: You can make files, move files, etc.
    • File: You can change the data in a file.
  • Execute
    • Folder: You can cd into the folder
    • File: You can run the file as a program.

These rights are given to 3 groups of people:

  • Owner
  • Group
  • Other (everybody else)

On a Linux system, when you do an ls -l on /etc/init.d, you get results like:

$ ls -l /etc/init.d/
-rwxr-xr-x 1 root root 2787 2009-11-05 08:03 umountfs
-rwxr-xr-x 1 root root 2075 2009-10-14 00:16 umountnfs.sh

The first part (-rwxr-xr-x) lists the permissions, the third shows the owner (root), and the forth shows the group (root).

The permissions list is split into four parts. The first letter is the file type. If it is a file, it is a dash. If it is a directory it is a d. If it is a link it is an l. The next three letters represent the rights of the owner. rwx means the user can read, write, and execute. The next three letters represent the permissions of the group. The group in this case can only read an execute (r-x). W is replaced with a dash meaning it is not allowed. Finally, everyone not belonging to the group is given read and execute permissions (r-x).

Modifying permissions and ownership

Now that we have gone over identifying permissions, we can modify them.

chmod

chmod is the tool for changing permissions. A good example of its use is the one I gave you at the beginning of this answer.

chmod 755 /etc/init.d/yourscript

The first argument (755) gives the permissions and the next arguments are this list of files to modify.

The permission list 755 is a short way of saying -rwxr-xr-x. The first number is the permission for the owner, the second is the permission for the group. and the third is the permission for others. Each number represents rwx.

Permission numbers:

  • Execute 1
  • Write 2
  • Read 4

The sum of the permission numbers is use in the chmod command. So, 7 is all rights (4+2+1) and 5 is read and execute (4+1).

So, putting it all together 755 is

  • All permissions for owner
  • Read and execute for group
  • Read and execute of everybody else

chown

chown is the tool for changing ownership and groups. It is much more simple then chmod.

chown root.root /etc/init.d/yourscript

First argument is the user.group. The next arguments are the files to change. It is that simple.

share|improve this answer

The green color you are referring is subjective to the person who put your Linux distribution together, and has no fixed meaning in the Linux world. However buy normal usage conventions it is normally associated with executable files. In the comment above Ignacio was asking you to look deeper. Example:

# ls -l
-rwxr-xr-x. 1 root root  1729 Dec  8 06:10 acpid

What do you see? If you look on the left side there are three sets of permissions. In this case the user root can execute, read and write, members of the group root can read and execute and everyone else can read and execute. The first dash on the far left is for special permissions, directories and symbolic links.

So how do you change this? There are two basic ways, both involving the command chmod (change mode). You could chmod u+x file to allow the owner execute permissions to the file, or you could do chmod a+x to allow everyone including the owner and group execute permissions or you could do chmod 550 to give the owner and group read and execute permissions.

Wikipedia has a great article discussing chmod in general along with basic file permissions.

share|improve this answer
chown root.root /etc/init.d/file    
chmod 755 /etc/init.d/file
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.