Problem with changing directory and subdirectories to read only


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with changing directory and subdirectories to read only
# 1  
Old 08-22-2007
Problem with changing directory and subdirectories to read only

I have a directory with its subdirectories and files. I want to change them all to read only. Say it is ~/test

chmod -R 444 ~/test
chmod: `/home/myname/test': permission denied

I do not understand. Do I have to have executable mode for a diirectory to access.

How can I change ~/test to read only recursively?

Last edited by lalelle; 08-22-2007 at 09:21 AM.. Reason: missing words
# 2  
Old 08-22-2007
It seems that it changes to 444 but where the permission denied comes from.
Please help
# 3  
Old 08-22-2007
chmod -R -w ~/test

at a guess.
# 4  
Old 08-22-2007
Porter your way is only to get rid of the write permissions, isn't it.
It does not remove execute permission.

You can try create a directory with its subdirectories then try to

chmod -R 444 directory
the error will show
chmod: `directory': permission denied

directory is changed to 444 but its subdirectories are not changed.

It is because chmod -R cannot access into the directory once the directory is changed to 444 already.

Therefore, I am asking how can I change everything to 444.

Or when somebody says change a directory and all directories and files inside to read only, we do not have to care about executable permission.

Moreover, once you change a directory to 444, you cannot (cd directory).
Why??

Last but not least
What is \rm or \chmod different to rm or chmod

Please please I am going nuts.
# 5  
Old 08-22-2007
try this:
Code:
find ~/test -type d | grep -v "^.$" | xargs chmod 444

find command selects all directories and subdirectories (recursively) in the ~/test directory
grep command weeds out . which represents current directory (this may not be necessary in your case)
# 6  
Old 08-22-2007
Quote:
Originally Posted by lalelle
Moreover, once you change a directory to 444, you cannot (cd directory).
"execute" for a directory means allowing somebody to navigate through it, hence cd failing, or paths that include that directory will fail.

The reason I didn't suggest removing the execute bit is for precisely that reason. You may want all your directories set to 444, I don't find that particularly useful.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

recursive copy into a directory and all its subdirectories...

I want to copy a file from the top directory into all the sub-folders and all of the sub-folders of those sub-folder etc. Does anyone have any idea how to do this? Thanks in advance of any help you can give. (3 Replies)
Discussion started by: EinsteinMcfly
3 Replies

2. UNIX for Dummies Questions & Answers

changing mode of files in subdirectories

Hi I actually need to change the mode to 777 in the current directory as well as subdirectories how to achieve that. I have /usr/sol/home/workfold as the main directory there are many directies and files in the workfold directory . I need to chmod 777 to all the directories and files under... (2 Replies)
Discussion started by: ssuresh1999
2 Replies

3. Shell Programming and Scripting

Copying subdirectories of a directory to some other directory and renaming them

Hi, I am a newbie in shell scripting. I have to copy a particular sub-directory (data) from a large no. of directories (all in the same folder) and paste them to another directory ( /home/hubble/data ) and then rename all the subdirectories (data) as the name of its parent directory. please... (8 Replies)
Discussion started by: sholay
8 Replies

4. Shell Programming and Scripting

Find directory name while traversing subdirectories

Hi, I have a parent directory in which I have sub directories of different depth /usr/usr1/user2/671 /usr/usr1/672 /usr/user2/user1/673 /usr/user2/user3/user4/674 And I need the names of all the directories that which starts only with 6 in a file. Thanks, (12 Replies)
Discussion started by: arun_maffy
12 Replies

5. UNIX for Dummies Questions & Answers

How to remove directory with subdirectories and files?

I'm trying to remove several directories which contains sun-dirs and files inside. I used the command rm -r <dirname> But, it always ask "examine file in directory <dirname> yes/no?" line by line. So, i need to write "y" for every line. How can i skip this step and remove all directories with... (9 Replies)
Discussion started by: ppa108
9 Replies

6. UNIX for Dummies Questions & Answers

read files from subdirectories

hello there the problem i got: i need to list .rrd files in each sub-directory from the parent directory, then create .xml files for each rrd files, the xml file should be in the same subdirectoryas rrd file. i have tried ls |awk '{print... (3 Replies)
Discussion started by: binbintriangel
3 Replies

7. Shell Programming and Scripting

problem with changing default home directory

Hi I want to change the default home directory of a user by modifying the /etc/passwd. I have a user named John cat /etc/passwd | grep John john:x:503:506::/home/john/:/bin Here is my script: echo "Enter username"; read username; echo "Enter new home directory"; read new_path; ... (3 Replies)
Discussion started by: tjay83
3 Replies

8. Shell Programming and Scripting

search files in a directory and its subdirectories

Hello my friends, I need to write a simple shell bad file :D that search and delete a file it's name 'Microsoft.txt' in the current directory and its subdirectories? So can you help to guide me how i can write this shell, Just give me the beginning :o thank you. (1 Reply)
Discussion started by: Net-Man
1 Replies

9. Shell Programming and Scripting

How Can I Make Subdirectories In A Directory?

I cant remember how, i use to know but its been like 2 years since ive used shell can anyone help me? (7 Replies)
Discussion started by: kprescod4158
7 Replies

10. UNIX for Dummies Questions & Answers

makefiles in a directory and subdirectories

I need to develop a makefile that spans across directories. For example, let's say i have an upper level directory (main) and about 2 subdirectories. I want my .cpp files and .o files to be in one subdirectory. I want my .a files to be in the other subdirectory. The .a files are made up of the... (0 Replies)
Discussion started by: benjie_asu
0 Replies
Login or Register to Ask a Question