LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-30-2004, 04:51 AM   #1
salami
LQ Newbie
 
Registered: Aug 2003
Location: Basel, Switzerland
Distribution: Debian & Mandrake
Posts: 4

Rep: Reputation: 0
stupid question about chmod


hi there

i need to set the file permissions on a directory and all subdiretories and files. files should have 660 and directories 770. now here's the problem... how can i tell chmod to only apply it to directories/files recursively?

thanks a lot!
 
Old 08-30-2004, 04:57 AM   #2
Charalambos
Member
 
Registered: Aug 2004
Location: Switzerland
Distribution: debian
Posts: 149

Rep: Reputation: 15
Re: stupid question about chmod

Quote:
Originally posted by salami
how can i tell chmod to only apply it to directories/files recursively?
Only recursively?
Do you want it to apply recursively (to all subdirectories and files of a directory) or to only one specific directory?
Recursively:
chmod -R 660 directory (The -R option means recursively)
To apply it to only one directory (without the subdirectories affected) apply the above without the option -R.
 
Old 08-30-2004, 05:23 AM   #3
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
Another way to go about it...

Since you've got two types of permissions, you're probably better off doing it in two commands. It's possible to do it all in one, but unnecessarily difficult (in my opinion). Anyway, find is your friend:
Code:
find /path/to/top/directory -type f -exec chmod 660 {} \;
find /path/to/top/directory -type d -exec chmod 770 {} \;
First command locates only regular files (-type f) located in the top-level directory and subdirectories. For each file found, the chmod command gets executed. The curly braces ( {} ) get replaced with the matching filename when executed. The \; signals where the end of the command is (for the -exec option).

Similarly, the second command finds only directories. It will match the directory given on the commandline and all its subdirectories. It will also perform a similar chmod but with a different set of permissions (770 as opposed to the 660 for files).

Last edited by Dark_Helmet; 08-30-2004 at 05:36 AM.
 
Old 08-30-2004, 05:27 AM   #4
Charalambos
Member
 
Registered: Aug 2004
Location: Switzerland
Distribution: debian
Posts: 149

Rep: Reputation: 15
Quote:
Originally posted by salami
files should have 660 and directories 770.
Sorry, somehow missed that one.
Forget my post above, it won't get you the desired result.
Consider Dark_Helmet's solution (he's the guru here anyway...)
 
Old 08-30-2004, 06:25 AM   #5
salami
LQ Newbie
 
Registered: Aug 2003
Location: Basel, Switzerland
Distribution: Debian & Mandrake
Posts: 4

Original Poster
Rep: Reputation: 0
hi

thanks for your replies!

the way Dark_Helmet described worked perfectly - thanks for the detailed explanation (this will get handy in the future too).
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Stupid, stupid question; I lost Klaptop. :( Surfrider Slackware 2 08-31-2005 09:12 PM
chmod -R question spooge Linux - General 2 01-13-2005 02:58 PM
Stupid Dumb Stupid Question... drigz Linux - Software 3 09-23-2004 03:09 PM
chmod question odious1 Linux - General 1 11-28-2003 11:41 PM
Question regarding chmod Yohhan Linux - Software 3 01-26-2003 02:24 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration