LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 08-17-2002, 04:05 PM   #1
eNTi
LQ Newbie
 
Registered: Jul 2002
Location: Austria - Salzburg
Distribution: gentoo
Posts: 20

Rep: Reputation: 0
change file permissions recursivly without changing permission of directories


i'm not sure wether this does work or if it's even supposed to but i've got the following problem. i have lot's of files in many directories and in a quite deep directory tree. so now i tried to do the following: chmod 644 * -R. the outcome is that chmod changes the privileges of the first directories first and that it takes itself the permission to write into those directories any changes and therefore can't change the file's permissions. any ideas how to do this? i'm lost.
 
Old 08-18-2002, 02:11 AM   #2
alaa
LQ Newbie
 
Registered: Aug 2002
Location: Egypt
Distribution: Mandrake
Posts: 2

Rep: Reputation: 0
complex solutions

checking the chmod man page looks like there is no straight forward way to do this.

I came up with a couple of solutions.

you can use the find tool to list all regular files (assuming you are trying to chmod regular files, you can use it to find device files if thats what you want), and use the output as the argument list of chmod like this

chmod 664 `find foo/ -type f `

yopu know about using ` foo` to insert the standard output in the argument list right??

the only problem is if you try to do this for very large directories /usr/local or something chmod will complain about too many arguments.

another solution is to use gawk to produce a the commands on the fly like this:
find foo/ -type f | awk '{print "chmod 664 " $0}' | sh

this will add the string 'chmod 664 ' to every entry of the find output and then pass it to the shell to execute.

I don't think there is a limit to how big this can be, but in case it is too big then redirect the output to a file and use it as a shell script instead this way

find foo/ -type f | awk '{print "chmod 664" $0}' > temp.sh

and then run temp.sh like this

sh temp.sh

hope this helps,
Alaa
 
Old 08-18-2002, 06:16 AM   #3
eNTi
LQ Newbie
 
Registered: Jul 2002
Location: Austria - Salzburg
Distribution: gentoo
Posts: 20

Original Poster
Rep: Reputation: 0
hehe. i checked the man page before i posted here , i always do.

to be honest, no i don't know about the "foo/"-thingy but i'm eager to learn it.

i've tried out your 2nd solution and i get the following error message:
find: foo/: No such file or directory

the problem might be that i don't really understand the foo/ parameter.
 
Old 08-18-2002, 07:09 AM   #4
sarin
Member
 
Registered: May 2001
Location: India, Kerala, Thrissur
Distribution: FC 7-10
Posts: 354
Blog Entries: 2

Rep: Reputation: 34
I think foo/ was just an example. Replace it with the name of directory on which you want to run chmod. So if you want to change the perms of all files in /usr/share, you will try something like chmod a+r `find /usr/share -type -f `. Again, replace a+r with whatever permissions you want to give.
--Sarin
( Also, don't try it on system directories. It might cause some problems. /usr is again an example, though it will really work )
 
Old 08-18-2002, 08:35 AM   #5
eNTi
LQ Newbie
 
Registered: Jul 2002
Location: Austria - Salzburg
Distribution: gentoo
Posts: 20

Original Poster
Rep: Reputation: 0
yeah. i know i just didn't get it in the first place.

thx so far.
 
Old 08-18-2002, 06:19 PM   #6
alaa
LQ Newbie
 
Registered: Aug 2002
Location: Egypt
Distribution: Mandrake
Posts: 2

Rep: Reputation: 0
oooops sorry about the foo confusion.

anyway you should learn you foos and fubars since they are very widly used in the GNU/Linux and Unix world.

any hypothetical file/command/user/etc. is called foo, any hypothetical file/command/user/etc in an error sitiuation (in an example of what you shouldn't do for instance) is called fubar or foobar

for an interesting discussion of their origin check the jargin file enteries for
foo @ http://www.tuxedo.org/~esr/jargon/html/entry/foo.html
and fubar @ http://www.tuxedo.org/~esr/jargon/html/entry/FUBAR.html

cheers,
Alaa
 
Old 08-18-2002, 09:25 PM   #7
Matt00SS
LQ Newbie
 
Registered: Jul 2002
Posts: 10

Rep: Reputation: 0
Thumbs up

You can do it all with just the 'find' command.

cd to the directory where you wish to start the permission change.... then:

find . -type f -exec chmod 644 {} \;

Enjoy,

Matt
 
Old 08-19-2002, 02:11 PM   #8
eNTi
LQ Newbie
 
Registered: Jul 2002
Location: Austria - Salzburg
Distribution: gentoo
Posts: 20

Original Poster
Rep: Reputation: 0
wow... that's a hole lot of splendit solutions. thx
 
Old 10-15-2004, 03:37 PM   #9
Zerosurf
LQ Newbie
 
Registered: Oct 2004
Posts: 2

Rep: Reputation: 0
and how can I do that only with directories?

find . -type f -exec chmod 644 {} \;

is a very good solution for files!!

Zerosurf
 
  


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
FC3 : how to change permission of directories where filesystems are mounted ? minnie Fedora 1 07-08-2005 11:23 AM
Persistent File Permission s on Shared Directories jackiemcghee Linux - General 3 07-15-2004 02:47 AM
Changing Permissions on Directories... bob4432 Linux - Newbie 6 06-25-2004 02:50 PM
file permissions windows directories lfent Linux - General 5 02-17-2004 04:43 PM
How do I change permissions of files/directories? Okashira Linux - Newbie 5 01-12-2004 05:11 PM


All times are GMT -5. The time now is 06:22 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration