Changing file permission recursively


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Changing file permission recursively
# 1  
Old 12-22-2009
Changing file permission recursively

I have a directory named DIR. The contents of the directory is something like:

Code:
a.sh
b.sh
cghsk.sh
assjsjkd
gdshddll
DFG/
...
...

Where only DFG/ is a folder.

I want to grant execute permission to all(a+x), for all the files directly under the DIR directory except the files that doesn't have a file name extension.

Code:
chmod -R +x /DIR

wont solve my problem.

Last edited by proactiveaditya; 12-22-2009 at 07:17 AM..
# 2  
Old 12-22-2009
Code:
for fname in $(find /DIR | grep -v '\.' )
do
    chmod +x $fname
done

# 3  
Old 12-22-2009
Worked it out.
Code:
for fname in $(find /DIR -maxdepth 1 -name "*.sh")
do
chmod +x $fname
done


Did the trick.

Last edited by proactiveaditya; 12-22-2009 at 08:02 AM..
# 4  
Old 12-22-2009
Quote:
Originally Posted by proactiveaditya
Worked it out.
Code:
for fname in $(find /DIR -maxdepth 1 -name "*.sh")
do
chmod +x $fname
done


Did the trick.
You dont require a loop there, a simple find command can do the trick.

Code:
find /DIR -maxdepth 1 -name *.sh -exec chmod +x {} \;

# 5  
Old 12-22-2009
Oh Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Change permission on a file recursively

Hi, this is the structure of the directory /local/home/app/cases under cases directory, below are the sub directories and each directory has files. /local/home/app/cases/1 /local/home/app/cases/2 /local/home/app/cases/3 /local/home/app/cases/4 File types are .txt .sh and so... (5 Replies)
Discussion started by: lookinginfo
5 Replies

2. Solaris

"Permission denied" when changing IP netmask

hello everyone, I am new on unix systems. I am working with a Solaris 10 OS. When i try to change netmask on certain interface: I get: How can i enable permission for changing that ? I have administrator privileges. Your help is much appreciated. thanks, (13 Replies)
Discussion started by: pablod76
13 Replies

3. UNIX for Dummies Questions & Answers

Permission denied when changing root password after reset

I have a Solaris 10 machine that I didn't know the root password to so I went into single user mode and removed the password from the shadow file and rebooted and I am able to login with no password now. But my problem is that when I try to change the root password from no password to something... (0 Replies)
Discussion started by: darkone_d1_2000
0 Replies

4. UNIX for Dummies Questions & Answers

changing password with sudo user " permission denied"

HI All, I am using solaris i created a user adam and updated his permissions in vi sudoers file as follows adam ALL=(ALL) NOPASSWORD: ALL ........... when i create user by logging as sudo user . $ sudo useradd -d /home/kalyan -m -s /bin/sh kalyan sudo: not found ... (6 Replies)
Discussion started by: kalyankalyan
6 Replies

5. Shell Programming and Scripting

Changing file permission upon creation in a directory

I want to change the permission of a file when it gets created in a particular directory. For instance, I have directory MyDir. Everytime a file gets created in that directory, I would like to change the permission to 777. The context is that I have a 3rd party appication running as root. Only... (2 Replies)
Discussion started by: laiko
2 Replies

6. Shell Programming and Scripting

how to exclude file when changing permission

I have files as below: erf100.sh erf101.sh erf102.sh erf103.sh erf104.sh erf105.sh I can easily change permission of all files to 755 by issuing command below: chmod 755 erf*.sh; how do i change permission of all files but excluding file erf102.sh? thanks best regards (2 Replies)
Discussion started by: khchong
2 Replies

7. UNIX for Dummies Questions & Answers

Recursively changing permissions on files

Please excuse for double posting, but since this seems like a " yep, me dummy question", I feel I should post here.:o Just joined after using the site as a guest.. (Very Good Stuff in here.. thanks folks.) I am in the process of hardening a Solaris 10 server using JASS. I also must use DISA... (1 Reply)
Discussion started by: altamaha
1 Replies

8. Shell Programming and Scripting

changing permission using FTP

Dear all, i want to change file permision of remote dir using FTP. is that possible? what i'm doing is i'm simply doing chmod 777 filename after establishing the connection with remote server using ftp... but the result showing is 550 SITE CHMOD command failed. can any body plz help?... (3 Replies)
Discussion started by: panknil
3 Replies

9. Red Hat

changing wtmp ownership and permission

Hi, I am using redhat AS 3. Recently, I was asked to implement a security control on the OS: to change ownership of /var/log/wtmp to root:sys and permission to 600. However, when I made the change and reboot the machine, everything was reverted. How come? Please help. The following is the... (1 Reply)
Discussion started by: voa2mp3
1 Replies

10. UNIX for Dummies Questions & Answers

changing permission using scripts

I have been trying to create a script that changes the user rights to read in the 'other' group across directories. The problem I'm having is that when i execute the script, the permissions of the directories remains the same. HELP (8 Replies)
Discussion started by: BigTool4u2
8 Replies
Login or Register to Ask a Question