Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How do I set all *.java files in the current directory and all its sub directories to have read permission to all users?

I also want to set all files of at least 1 kilobyte in size in the current directory and all sub directories to have a group of admin.

share|improve this question

migrated from stackoverflow.com Nov 2 '10 at 13:01

This question came from our site for professional and enthusiast programmers.

2  
Voting to move to Super User, this is not a programming question. –  unwind Nov 2 '10 at 12:59
add comment

4 Answers

Alternative: To set read permission for all .java files in the current directory, use this command:

chmod -R 444 *.java

To set all files of at least 1 kilobyte in size in the current directory and all sub directories to have a group of admin.

find /yourdirectorypath -size +1k -exec chgrp admin {} \;

Note: the "-R" indicates recursive which will cover your sub directories as well

share|improve this answer
    
I don't think you want -R on the chgrp command since find is doing the recursion for you. –  Dennis Williamson Nov 2 '10 at 14:32
    
Dennis--if you notice, he only uses -R on the chmod, not on the chgrp. He isn't using find on the chmod, because it has built-in recursion. –  CarlF Nov 2 '10 at 16:42
    
@CarlF: Reading the revision history, it would appear that the answer was edited. When Dennis commented, the chgrp had a -R on it. –  Thanatos Nov 2 '10 at 17:57
    
I should have stated that change here in the comments but I got busy. –  ricbax Nov 3 '10 at 0:35
add comment

How do I set all *.java files in the current directory and all its sub directories to have read permission to all users?

In bash ≥4.0 and zsh:

chmod a+r ./**/*.java

On any POSIX-compliant system (i.e. any non-antique unix variant and more):

find . -name '*.java' -exec chmod a+r {} +

Set all files of at least 1 kilobyte in size in the current directory and all sub directories to have a group of admin.

In zsh:

chgrp admin ./**/*(.L+1023)

On any POSIX-compliant system:

find . -type f -size +1023c -exec chgrp admin {} +
share|improve this answer
add comment

Use find and xargs

find . -name \*.java | xargs chmod o+r

or

find . -name \*.java -print0 | xargs -0 chmod o+r

The second version handles spaces in file or directory names.

You may need to fix directory permissions as well.

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

You can avoid updating permissions which are already correct. Check the man page for find and review the section on permissions.

share|improve this answer
    
Rather than use xargs, use the simpler, robust and POSIX-compliant find . -type d -exec chmod o+r {} +. –  Gilles Nov 2 '10 at 23:30
add comment

To set read permission for all .java files in the current directory, use this command

chmod +r *.java
share|improve this answer
    
The question asked about subdirectories, which this answer does not cover. –  CarlF Nov 2 '10 at 16:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.