Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What permission should i apply to a folder so that everyone can see the hierarchy and all the files inside but they should not be able to read and write them. The folder can have multiple other folders with files inside.

share|improve this question

Listing directories uses the executable bit, I don't think read actually affects directories at all. You will have to set permissions on each individual file to prevent them from being read or written to. The following commands will do all this for you, execute them from the folder you want this to start at:

find . -type d | xargs chmod o=rx 
find . -type f | xargs chmod o=

find will recursively find files (-type f) and directories (-type d) and print their names (lacking another specified action), and this gets piped to xargs, which executes its arguments with the files it reads from the pipe. chmod changes the permissions for others (o, meaning neither you nor others in the group owning the file) to exactly (=) read/list (rx) for folders and nothing for plain files.

As grumbel pointed out in a comment, this will only work on well-behaved names. To get them all, either use his solution:

find . -type d -print0 | xargs -0 chmod o=rx 
find . -type f -print0 | xargs -0 chmod o=

or find's builtin -exec:

find . -type d -exec chmod o=rx '{}' ';'
find . -type f -exec chmod o= \{\} \;

Note that you can either quote the braces and semicolon like the first line, or escape them like the second, they just have to be there in separate arguments. Also, -exec will execute chmod once for each file, while xargs will do it in as few commands as possible (based on the max command line length). That's why I generally prefer xargs.

share|improve this answer
Use "find . -type f -print0 | xargs -0 chmod o=" to avoid issues with filenames containing unusual characters (i.e. newlines). – Grumbel Nov 5 '11 at 21:24
Yes, thanks, added it in. – Kevin Nov 5 '11 at 21:37
Braces do not need to be escaped – enzotib Nov 5 '11 at 21:43
You can use + instead of ; to have find using as few commands as possible. – enzotib Nov 5 '11 at 21:44
Without the r bit on a directory, you can cd to it, but cannot list its content. – enzotib Nov 5 '11 at 21:47
sudo chown -R username:root "/directory you want"

-R represent Recursion for all it's sub directory's and files.

username- current user

It helpful for read/write/execute permission

share|improve this answer

Your Answer


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.