LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-02-2006, 10:03 AM   #1
ryanzietlow
LQ Newbie
 
Registered: Oct 2003
Posts: 26

Rep: Reputation: 15
Change File permissions on numerous files


Hopefully a simple question!

I run a small network at a school consisting of a linux red hat 9 box running squid, samaba, dansguardian, etc.

We have a office management program that we use for attendance, grades, family info, etc. Updates for this program come out from time to time and must be installed. So... When I run the update it changes the permissions on all the files in the directory, say /123

What I want to know is how can i change all the files, directories, etc underneath /123 to read/write at the same time without having to go to each file/directory manually and change them?

Any help would be appreciated!
 
Old 11-02-2006, 10:06 AM   #2
uselpa
Senior Member
 
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507

Rep: Reputation: 47
Code:
find /123 -print0 | xargs -0 chmod u+rw
That will include /123 itself.
 
Old 11-02-2006, 10:10 AM   #3
ryanzietlow
LQ Newbie
 
Registered: Oct 2003
Posts: 26

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by uselpa
Code:
find /123 -print0 | xargs -0 chmod u+rw
That will include /123 itself.

So i better understand what I am doing here:

I assume "find /123" will find the directory /123 and the "chmod u+rw" means to change it to read and write for everyone?
what does -print0 | xargs -0 chmod u+rw actaully mean?

Thanks again for the quick reply and the time saver!
 
Old 11-02-2006, 10:12 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

If you want to change all (!) the normal files:

find /123 -type f -exec chmod 644 {} \;

All the directories and subdirs:

find /123 -type d -exec chmod 755 {} \;

The -type f (or d) only selects normal files (f) or directories (d). /123 is the starting point, all subdirs are checked too.
The -exec ... {} \; part makes it possible to execute a 'normal' command, chmod in this case.

Hope this is what you want, try it first on a non essential directory
 
Old 11-02-2006, 10:23 AM   #5
uselpa
Senior Member
 
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507

Rep: Reputation: 47
find /123 will find the directory /123 and all subdirectories and files below
-print0 will print the files with a trailing [00] byte, that's important if you have spaces or strange characters in your filenames
| xargs -0 will pipe the file and directory names found, one at a time, to the command specified thereafter
chmod u+rw will add read and write the users permissions

so it boils down to
chmod u+rw /123
chmod u+rw /123/file 1
chmod u+rw /123/file 2
chmod u+rw /123/dir1
chmod u+rw /123/dir1/file 3

and so on
 
Old 11-02-2006, 04:44 PM   #6
ryanzietlow
LQ Newbie
 
Registered: Oct 2003
Posts: 26

Original Poster
Rep: Reputation: 15
Thank you to both responders, the future just got easier for me! I did print off obth ways of doing it and will experiement with the one i didnt use at a later time.

Thanks again! With help like this I love Linux
 
Old 11-03-2006, 11:55 AM   #7
soggycornflake
Member
 
Registered: May 2006
Location: England
Distribution: Slackware 10.2, Slamd64
Posts: 249

Rep: Reputation: 31
You could also just use the -R (recursive) flag to chmod (though if you want to limit it to just regular files (or directories), then obviously 'find ... -type ...' is the way to go).
 
Old 11-03-2006, 04:10 PM   #8
ryanzietlow
LQ Newbie
 
Registered: Oct 2003
Posts: 26

Original Poster
Rep: Reputation: 15
I want it to apply to all the files and directories including and under /123 so it would be find /123 -R -exec chmod 755 {} \;
Is that correct?
 
Old 11-03-2006, 04:27 PM   #9
soggycornflake
Member
 
Registered: May 2006
Location: England
Distribution: Slackware 10.2, Slamd64
Posts: 249

Rep: Reputation: 31
You don't need to use find. 'chmod -R 755 /123' suffices, with the advantage that only one instance of chmod is spawned, instead of one for each file.
 
Old 11-03-2006, 04:43 PM   #10
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

I totally agree with soggycornflake: If you want everything changed use chmod not find.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Change permissions 4 many files at 1ce? TruthSeeker Linux - Newbie 3 10-31-2005 08:23 AM
How do you change a files permissions Charlie Chan Linux - Security 8 10-20-2004 10:19 PM
recursive file permissions does not change new files in same directory PAB Linux - Newbie 2 03-08-2004 12:27 PM
How do I change permissions of files/directories? Okashira Linux - Newbie 5 01-12-2004 05:11 PM
File Systems and Numerous files per directory dman65 Linux - General 1 10-06-2003 04:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:23 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