LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-22-2005, 03:55 AM   #1
[GOD]Anck
Member
 
Registered: Dec 2003
Location: The Netherlands
Distribution: Slackware
Posts: 171

Rep: Reputation: 35
Using chmod to recursively change directories / files


Forgive my questions, this is probably something simple but man chmod did not help me out. I've got a directory with many subdirectories and files in it. I would like to recursively change the permissions on all the subdirectories to 755, but leave the permissions on files as 644. Issuing chmod 755 * will change the permissions on files as well as directories. Is there a way to tell chmod to change only directories, or only files, recursively?

Thanks!
 
Old 02-22-2005, 04:12 AM   #2
heema
Senior Member
 
Registered: Sep 2003
Location: Egypt
Distribution: Arch
Posts: 1,528

Rep: Reputation: 47
you could make a script to do that
 
Old 02-22-2005, 06:49 AM   #3
linuxxed
Member
 
Registered: Feb 2004
Posts: 273

Rep: Reputation: 30
Re: Using chmod to recursively change directories / files

Quote:
Originally posted by [GOD]Anck
Forgive my questions, this is probably something simple but man chmod did not help me out. I've got a directory with many subdirectories and files in it. I would like to recursively change the permissions on all the subdirectories to 755, but leave the permissions on files as 644. Issuing chmod 755 * will change the permissions on files as well as directories. Is there a way to tell chmod to change only directories, or only files, recursively?

Thanks!


find [YOURDIR] -type d -exec chmod 755 {} \;

find [YOURDIR] -type f -exec chmod 644 {} \;
 
Old 02-24-2005, 11:59 AM   #4
zovres
Member
 
Registered: Sep 2002
Posts: 184

Rep: Reputation: 30
AWE freaking SOME

just what I have been looking for


thx
 
Old 11-10-2008, 10:38 AM   #5
bucovaina78
Member
 
Registered: Oct 2004
Location: Belgium / Antwerp
Distribution: Debian
Posts: 287

Rep: Reputation: 33
indeed nice one :-)
 
Old 11-10-2008, 12:50 PM   #6
bucovaina78
Member
 
Registered: Oct 2004
Location: Belgium / Antwerp
Distribution: Debian
Posts: 287

Rep: Reputation: 33
I used this command for my directory structure to change the permissions and it worked fine (as I mentioned before). But still I have a few questions about it. Sounds stupid but I don't fully understand every single piece of the command I'm typing.

Code:
find [YOURDIR] -type d -exec chmod 755 {} \;
If I understand it well, you tell to search for directories, and when a match is found it changes the permissions to 755.

But, for example, I want to look up all the files in a directory with mp3-files that contain "John Denver"

I tried

Code:
find /.../music -type f -exec grep -i john denver
That resulted in ... errr nothing

so I tried

Code:
find /.../music -type f | grep -i john denver
and that one worked!!

So my question is, what is the -exec thing? It tells to run chmod, but what's the difference with the | (pipe)? I'm propably wrong but for me it does exactly the same, the output generated from find is "piped" to grep. Grep itself is only going to show the matches "john denver" (case insensitive -i )

And question nr 2 is why "{} \;" at the end?


as an exercise for myself I tried to list all the mp3-files that had an ID3tag: 1990 in the "year-field"

So I tried:

Code:
user@ubuntu:/.../music$ find -type f -exec id3ed -y 1990 {} \;

File ./e/Emir Kusturica & The No Smoking Orchestra/Life is a Miracle/02-Evergreen.mp3: (tag v1.1)
songname[max:30]: Evergreen
I learned at school a long time ago: "An experiment never fails, it's possible that you don't get the expected result, but again, it never fails"

So the question now is: what am I doing wrong if I want to list all the files in my music directory with an ID3-tag: 1990 in the "year-field"
 
Old 11-10-2008, 06:16 PM   #7
salter
Member
 
Registered: Oct 2008
Posts: 100

Rep: Reputation: 15
The manual for find ($ man find) has an explanation for -exec (listed under ACTIONS).
-exec launches an application (chmod in this case)
'{}' is replaced with the current filename
'\' is used for proper escaping of the input sequence

Linux Archive

Last edited by salter; 12-20-2008 at 11:49 AM.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
CHMOD directories.sub-directories.files zerojosh Linux - Software 2 11-19-2005 03:22 PM
chmod to only change directories lluciano Linux - General 2 08-17-2005 02:14 PM
List all files and recursively open directories. unreal128 Linux - General 2 07-16-2005 02:06 PM
Why doesn't a wildcard chmod change "dot" files/directories? jht2k Linux - General 1 08-09-2004 02:31 PM
chmod directories and files seperately robeb Linux - General 2 05-23-2003 08:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:02 AM.

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