To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here

http://justlinux.com/   Thu, 09-Sep-2010 07:03:03 GMT
         internet.com

Go Back   JustLinux Forums > Community Help: Check the Help Files, then come here to ask! > Technical

Technical Other Linux related questions that do not quite fit into the other forums.

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 01-09-2002, 07:00 PM
Nexist Nexist is offline
Minor Poobah
 
Join Date: Nov 2000
Location: Eugene, OR USA
Posts: 67
chmod -r -x * & exclude directories.

Can this be done? I copied a bunch of files from a Windows Partition which were all mearked as executable. I then did a recursive chmod to set the execution bit off. After hitting return I realized the horrible mistake, as all directories became unlistable.

Is there a way to specify for Chmod to recurse into any & all sub directories and modify the files within those directories without applying to the directories themselves?

I don't know grep that well yet, & I have a sinking suspicion that grep is the tool I will need...
__________________
Thee Nexist (nexist@comcast.net)
Reply With Quote
  #2  
Old 01-10-2002, 01:47 PM
7 7 is offline
Registered User
 
Join Date: Jun 2000
Location: Newcastle UK
Posts: 388
Taking the exectable flag off a directory (what the hell is that for anyway?!) shouldn't make it unlistable..

And unless I'm confused, couldn't you just cd into the directory then to the chmod-R xxx, cd out, cd in another and repeat?
__________________
There's nothing less controlled than a controlled substance.
Like Trance? Weird Titan Radio
Reply With Quote
  #3  
Old 01-10-2002, 02:25 PM
slapNUT's Avatar
slapNUT slapNUT is offline
Banned
 
Join Date: Jul 2000
Location: Recycle Bin
Posts: 2,923
Here's one right out of Linux Shells by Example. Save it in your path, make it executable. Go into the directory you want to chmod the files in. Run program with * parameter i.e. <program> *.

Code:
#!/bin/bash
for FILE
do
  if [ -f $FILE -a ! -x $FILE ] # another way if [[ -f $FILE && ! -x $FILE ]]
  then
      chmod +x $FILE
      echo "Changing file $FILE..."
  fi
done
Note this is checking to see if the file is NOT executable then if it isn't chmod to make it executable. To modify it to do the opposite just remove the "!" in the test and change the chmod to -x. I don't think it recurses into directories but thats a project for the *****ious. It could be modified to chmod the directories... HINT: the -f stands for file a -d would test to see if $FILE was a directory.

HTH
Reply With Quote
  #4  
Old 01-10-2002, 06:27 PM
2thumbs 2thumbs is offline
Registered User
 
Join Date: May 2000
Location: Edmonton, Alberta, Canada
Posts: 701
Quote:
Originally posted by 7:
<STRONG>Taking the exectable flag off a directory (what the hell is that for anyway?!) shouldn't make it unlistable..

And unless I'm confused, couldn't you just cd into the directory then to the chmod-R xxx, cd out, cd in another and repeat?</STRONG>
The executable flag on a directory means as much as "access". If you dont have x, then you can't list the contents of the directory.

Doing it seperatedly for each dir would be a waste of time if you have like 50 directories and subfolders within them
__________________
myaddiction.ca
Reply With Quote
  #5  
Old 01-10-2002, 06:49 PM
7 7 is offline
Registered User
 
Join Date: Jun 2000
Location: Newcastle UK
Posts: 388
Thanks 2thumbs, strange that I've been using Linux for 2 years+ and I never knew that!

Stupid post..
__________________
There's nothing less controlled than a controlled substance.
Like Trance? Weird Titan Radio
Reply With Quote
  #6  
Old 01-10-2002, 06:53 PM
2thumbs 2thumbs is offline
Registered User
 
Join Date: May 2000
Location: Edmonton, Alberta, Canada
Posts: 701
It's ok.. I step on my own toes quite frequently also... and I do it for a living
__________________
myaddiction.ca
Reply With Quote
  #7  
Old 01-10-2002, 08:50 PM
AdaHacker AdaHacker is offline
Senior Grasshopper
 
Join Date: Oct 2001
Posts: 503
No grep needed. Just use find. This command
Code:
find $DIRNAME -type f -exec chmod 640 {} \;
will recurse int $DIRNAME, find everything that's just a regular file, and do a chmod 640 on it. The '-type f' tells find to return regular files, while the -exec performs the command after it. The {} in the chmod command stands for the file currently being processed. You must end the exec option with a semi-colon, which you'll probably have to escape.
You could modify this to change permissions on just the directories by changing the '-type f' to '-type d', for directory.
You can read more in the man page, but I find the reference and examples in Linux in a Nutshell much better.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 03:03 AM.

Help File Library
Compiling Kernels
Hardware
Soundcards
Booting Your OS
Command Reference
More



internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers
Free Newsletter
Server Daily


More Free Newsletters




internet.commerce
Be a Commerce Partner












Linux is a trademark of Linus Torvalds.

Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.7.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.