Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am trying to change permissions of a folder temporarily whose initial permissions are

user@ubuntu:/var/log$ ls -l squid*
squid3:
total 4
-rw-r----- 1 proxy proxy    0 Jan 16 14:43 access.log
-rw-r----- 1 proxy proxy 1359 Jan 16 14:43 cache.log
ls: cannot open directory squid-deb-proxy: Permission denied

to some thing following

user@ubuntu:/var/log$ sudo chmod -R 644 squid*
user@ubuntu:/var/log$ ls -l squid*
squid3:
ls: cannot access squid3/cache.log: Permission denied
ls: cannot access squid3/access.log: Permission denied
total 0
-????????? ? ? ? ?            ? access.log
-????????? ? ? ? ?            ? cache.log

squid-deb-proxy:
ls: cannot access squid-deb-proxy/store.log: Permission denied
ls: cannot access squid-deb-proxy/cache.log: Permission denied
ls: cannot access squid-deb-proxy/access.log: Permission denied
total 0
-????????? ? ? ? ?            ? access.log
-????????? ? ? ? ?            ? cache.log
-????????? ? ? ? ?            ? store.log

You will notice after the change of permissions there are question marks everywhere. Why is this happening? I basically want to read the access log to see if squid-deb-proxy server is getting requests from client or not.

share|improve this question

2 Answers 2

up vote 9 down vote accepted

To view the permissions of a directory, you need to pass the -d flag to ls, like this:

ls -ld squid3

To read a file, its read permission needs to be set. However, to read a directory and the listing of its files, both the read and the execute permissions need to be set. If they aren't, you get weird errors like the ones you're experiencing.

To set the read permission on files and the read and execute permissions on directories recursively, use this command:

chmod -R a+rX directoryname

Here's an explanation of that command:

  • chmod is the name of the command, use for changing the permissions of files.
  • -R is the recursive flag. It means apply this command to the directory, and all of its children, and of its children's children, and so on.
  • a stands for all: apply these permissions the owner of the file, the group owner of the file, and all other users.
  • + means add the following permissions if they aren't set already.
  • r means the read permission.
  • X means the execute permission, but only on directories. Lower-case x would mean the execute permission on both files and directories.

More information is found in the manpage for the chmod command Manpage icon.

share|improve this answer
    
is there any thing wrong with using chmod -R 644 squid* –  Registered User Jan 16 '13 at 20:38
3  
@RegisteredUser: yes. 644 is rw-r--r--, which is suitable for files, but not for directories. Directories need to have the execute permission set too, like this: rwxr-xr-x or 755. The command you mentioned unsets the execute permission on all files and directories recursively, which causes these errors. –  Flimm Jan 16 '13 at 20:56

As you stated that your goal is to read /var/log/squid/access.log, your best solution is to type sudo less /var/log/squid/access.log, which spares the trouble of repeatedly chmodding.

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.