LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-27-2004, 06:37 PM   #1
rshooper
LQ Newbie
 
Registered: Aug 2004
Distribution: Fedora Core 2
Posts: 24

Rep: Reputation: 15
Basic Operation Question


Is there a way to process a command on all subdirectores of the current directory, liek chown, chgrp, or chmod. I want to be able to make a change on all the files, subdirectories and thier files in a particular directory.
 
Old 08-27-2004, 06:41 PM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 373Reputation: 373Reputation: 373Reputation: 373
Check the man page for the command. All of the commands you listed provide a -R option, which means to recursively go through the directory structure (in other words, exactly what you're looking for). For example:
Code:
chown -R rshooper *
That will change every file and directory's owner to rshooper (including all files in all subdirectories). Actually, that's sort of a lie, because I don't think hidden files will get changed (files that start with a dot). You get the idea though.
 
Old 08-27-2004, 06:45 PM   #3
rshooper
LQ Newbie
 
Registered: Aug 2004
Distribution: Fedora Core 2
Posts: 24

Original Poster
Rep: Reputation: 15
Thats exactly what I was looking for, I didn't realize it was a command specific option or I would have looked at the man pages. I figured it was a standard OS option like /s in DOS. Thanks for you assistance.
 
Old 08-27-2004, 06:51 PM   #4
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 373Reputation: 373Reputation: 373Reputation: 373
No problem. As a side note, if the command you want to run doesn't offer a recursive option, then you can use the find command. Here's an example equivalent to the command above:
Code:
find . -exec chown rshooper {} \;
Find searches through the given directory (in this case . - the current directory) and all subdirectories. When it finds a file/directory, the -exec option tells find to run the specified command on what it found (one at a time). The {} is replaced with the name of the file or directory. The \; signifies the end of the command.

Find is really useful and has lots of options. You can restrict matches based on filename wildcards, modification dates, and all kinds of other goodies. Just an fyi...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Basic C++ question oulevon Programming 1 02-16-2005 06:55 PM
Basic Question insyte Linux - Wireless Networking 4 09-16-2004 12:57 PM
Basic C++ question ooagentbender Programming 10 12-10-2003 10:34 PM
Very basic question rajanr Linux - Newbie 2 07-23-2003 04:13 AM
PHP question (passing an operation via link) bkeating General 0 10-14-2002 12:18 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:55 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration