I've just written a simple bash file to copy a full directory to my home directory to avoid permission problems when tracking it with git.

The script looks as follows:



cp -R $working_directory $target_directory

The script is owned by my local username "peter".

-rwxrwx--- 1 peter peter 123 Sep 11 11:02 update.sh

During the copy process I get an error that files of the folder "/opt/lampp/htdocs/vocab/files" cannot be copied due to permission restrictions.

ls -l /opt/lampp/htdocs/vocab/ returns

drwxr-xr-x 2 root     root     4096 Sep 10 22:59 css
drwxrwxrw- 2 www-data www-data 4096 Sep 11 11:06 files
drwxr-xr-x 2 root     root     4096 Aug 17 21:33 html
-rw-r--r-- 1 root     root      918 Sep  3 08:28 index.html

As you can see the problem causing directory "files" is neither possessed by peter nor its group contains peter. I checked this running the command groups peter.

Why can I copy all directories and files except "files"? On the one hand peter does not have the permission to do any stuff with "files", because he is not the owner and does not belong to the group, but on the other hand all other directories are owned by root - this actually the same case. peter does not belong to root, but he somehow has no problem to copy those files and dirs. Why?


You have no rights to read the content of the folder /opt/lampp/htdocs/vocab/files.

If you start your script as user peter and the group and owner of the folder is www-data, than you have to set x (execution rights, which are necessary to see the contents of directories--you "execute" them when you access their contents) to the rights for others.

sudo chmod o+x /opt/lampp/htdocs/vocab/files

And you should add the p switch to preserve mode, ownership, timestamps.

cp -pR $working_directory $target_directory

(Alternatively you can start your script with sudo rights )

From man chmod

The letters rwxXst select file mode bits for the affected users: read (r),
write (w), execute (or search for directories) (x), execute/search
only if the file is a directory or already has execute permission for some
user (X), set user or  group  ID on execution (s), restricted deletion flag
or sticky bit (t).  Instead of one or more of these letters, you can specify
exactly one of the letters ugo: the permissions granted to the user who owns
the file (u), the permissions granted to other users who are members of the
file's group (g), and the permissions granted to users that are in neither of
the two preceding categories (o).
  • And why do I have to right to copy all other directories when starting the script as user peter? For example 'index.html' neither has the x permission, and nobody is complaining when copying it. – null Sep 11 '15 at 9:55
  • x isn't necessary for files in your case and in your question isn't described, what the permissions for /opt/lampp/htdocs/vocab is. – A.B. Sep 11 '15 at 9:57
  • It's drwxrwxrwx 9 www-data www-data 4096 Sep 11 10:16 vocab. Ok, I did not know that there are differences between directories and files. I thought everything was a file.... – null Sep 11 '15 at 10:00
  • 1
    @kos ok, without sudo, understand =) – A.B. Sep 11 '15 at 10:04
  • 2
    @null Since I see that you didn't cast any vote ever, in general consider also upvoting answers which you deem as helpful. In this case to thank the user who posted it :) – kos Sep 11 '15 at 10:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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