View previous topic :: View next topic |
Author |
Message |
wilburpan l33t
![l33t l33t](/images/ranks/rank_rect_4.gif)
![](images/avatars/gallery/Southpark/South_Park_-_Chinese.jpg)
Joined: 21 Jan 2003 Posts: 977
|
Posted: Mon Jul 06, 2009 9:37 pm Post subject: Need help with a script to set permissions |
|
|
I have a directory that holds a lot of document/media files, called FileCabinet. There are a lot of subdirectories and they are nested pretty deeply.
Here's my issue: I'd like to make sure that all of these files have 0644 permissions. No problem, right? I entered this command:
Code: | chmod 0644 -R FileCabinet |
Which should convert everything in this folder to 0644, permission-wise.
Problem is, that command also converted the folder permissions to 644, which played havoc with the subdirectories. I would get this issue:
Code: | ls -l FileCabinet
ls: cannot access FileCabinet/Pictures: Permission denied
ls: cannot access FileCabinet/Movies: Permission denied
ls: cannot access FileCabinet/Documents: Permission denied
total 0
?????????? ? ? ? ? ? Documents
?????????? ? ? ? ? ? Movies
?????????? ? ? ? ? ? Pictures |
Obviously, what happened is that with the last command, I changed the directories to 0644 as well, which my system doesn't like. This is fixable -- I just change everything to 0755.
But is there a way to write a script that traverses the directory and changes everything to 0644 except for the directories themselves? _________________ I'm only hanging out in OTW until I get rid of this stupid l33t ranking.....Crap. That didn't work. |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
Nerevar l33t
![l33t l33t](/images/ranks/rank_rect_4.gif)
![](images/avatars/11350998804996c6d5494c6.jpg)
Joined: 31 May 2008 Posts: 720
|
Posted: Mon Jul 06, 2009 9:56 pm Post subject: |
|
|
Code: | find . -type d -print0 | xargs -0 chmod 0755 && find . -type f -print0 | xargs -0 chmod 0644 |
|
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
wilburpan l33t
![l33t l33t](/images/ranks/rank_rect_4.gif)
![](images/avatars/gallery/Southpark/South_Park_-_Chinese.jpg)
Joined: 21 Jan 2003 Posts: 977
|
Posted: Tue Jul 07, 2009 2:16 pm Post subject: |
|
|
Thanks -- that did the trick!
I need to spend more time with the 'find' and 'xargs' commands. _________________ I'm only hanging out in OTW until I get rid of this stupid l33t ranking.....Crap. That didn't work. |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
alex.blackbit Advocate
![Advocate Advocate](/images/ranks/rank-G-1-advocate.gif)
Joined: 26 Jul 2005 Posts: 2397
|
Posted: Tue Jul 07, 2009 2:29 pm Post subject: |
|
|
Nerevar wrote: | Code: | find . -type d -print0 | xargs -0 chmod 0755 && find . -type f -print0 | xargs -0 chmod 0644 |
|
Code: | $ find <path> -type d -exec chmod 0755 {} \; && find <path> -type f -exec chmod 0644 {} \; | is possible too, IMHO a little bit more elegant. |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
Nerevar l33t
![l33t l33t](/images/ranks/rank_rect_4.gif)
![](images/avatars/11350998804996c6d5494c6.jpg)
Joined: 31 May 2008 Posts: 720
|
Posted: Tue Jul 07, 2009 3:33 pm Post subject: |
|
|
alex.blackbit wrote: | Nerevar wrote: | Code: | find . -type d -print0 | xargs -0 chmod 0755 && find . -type f -print0 | xargs -0 chmod 0644 |
|
Code: | $ find <path> -type d -exec chmod 0755 {} \; && find <path> -type f -exec chmod 0644 {} \; | is possible too, IMHO a little bit more elegant. |
I don't like the exec switch, but if you insist on using it you should look at the "-exec command {} +" variant in the manpage. It will speed up the operation on directories with many files. |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
timeBandit Bodhisattva
![Bodhisattva Bodhisattva](/images/ranks/rank-bodhisattva.gif)
![](images/avatars/7370479114aa9a876e87b5.png)
Joined: 31 Dec 2004 Posts: 2719 Location: here, there or in transit
|
Posted: Tue Jul 07, 2009 3:36 pm Post subject: |
|
|
alex.blackbit wrote: | Code: | $ find <path> -type d -exec chmod 0755 {} \; && find <path> -type f -exec chmod 0644 {} \; | is possible too, IMHO a little bit more elegant. | In addition, use + instead of \; to get behavior more like an xargs pipeline (fewer spawned processes).
Edit: Bah. Too slow. What he (Nerevar) said. ![Wink :wink:](images/smiles/icon_wink.gif) _________________ Plants are pithy, brooks tend to babble--I'm content to lie between them.
Super-short f.g.o checklist: Search first, strip comments, mark solved, help others. |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
alex.blackbit Advocate
![Advocate Advocate](/images/ranks/rank-G-1-advocate.gif)
Joined: 26 Jul 2005 Posts: 2397
|
Posted: Tue Jul 07, 2009 6:51 pm Post subject: |
|
|
k, thx. |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
|