LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Using chmod to recursively change directories / files (https://www.linuxquestions.org/questions/linux-software-2/using-chmod-to-recursively-change-directories-files-293310/)

[GOD]Anck 02-22-2005 03:55 AM

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!

heema 02-22-2005 04:12 AM

you could make a script to do that

linuxxed 02-22-2005 06:49 AM

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 {} \;

zovres 02-24-2005 11:59 AM

AWE freaking SOME

just what I have been looking for :)


thx :)

bucovaina78 11-10-2008 10:38 AM

indeed nice one :-)

bucovaina78 11-10-2008 12:50 PM

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"

salter 11-10-2008 06:16 PM

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


All times are GMT -5. The time now is 11:36 PM.