2

I actually started learning Unix and while doing so I stuck here. Though It may seem silly question I'm actually unclear with it so please help me.

I've a file as somefile.txt and a symbolic link which refers to somefile.txt, and I found default permissions for both are rw-r--r--.

When I change permissions of somefile.txt (chmod ugo=rwx somefile.txt), I found a change in both files as rwxrwxrwx. But again when I try to change permissions by giving chmod u-rx somefile.txt, I found change only in somefile.txt but not in symbolic link. I wonder why? I'm using RedHat cygwin.

0

1 Answer 1

5

You have mistaken the output of at least one command. The permissions of a symbolic link are always rwxrwxrwx, or rather they don't have permissions at all:

$ touch file
$ ls -l 
total 0
-rw-rw-r-- 1 muru muru 0 Dec  5 20:53 file
$ ln -s file link
$ ls -l 
total 0
-rw-rw-r-- 1 muru muru 0 Dec  5 20:53 file
lrwxrwxrwx 1 muru muru 4 Dec  5 20:53 link -> file
$ chmod a+x file
$ ls -l
total 0
-rwxrwxr-x 1 muru muru 0 Dec  5 20:53 file
lrwxrwxrwx 1 muru muru 4 Dec  5 20:53 link -> file

See this FreeBSD FAQ for more information.

And since you're on Linux, man chmod says:

   chmod never changes the permissions of symbolic links; the chmod system
   call cannot change their permissions.  This is not a problem since  the
   permissions  of  symbolic  links  are  never  used.   However, for each
   symbolic link listed on the command line, chmod changes the permissions
   of  the  pointed-to  file.   In  contrast, chmod ignores symbolic links
   encountered during recursive directory traversals.
1
  • My bad. I've make a mistake without my proper attention. Thank you so much for this help. Commented Dec 6, 2014 at 5:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .