LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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
 
LinkBack Search this Thread
Old 03-30-2007, 11:46 PM   #1
cope
LQ Newbie
 
Registered: Apr 2005
Distribution: rhel, centos, ubuntu
Posts: 18

Rep: Reputation: 0
chmod all files 644 and files 755


Hi,

I've got a mass of files sitting in a directory I copied from my windows eons ago.

It has about 150gig of 4mb files the directory tree can go up to 10 levels deep.

Because they were copied off a XP machine, the permissions aren't set correctly.
What i'm after is an EASY way (or a utility) that will chmod all files 644 and all folders 755.. if I have to run two commands to do this, eh, I'll live!

Otherwise, I'll have to elarn how to shell or even worse I'll do it in PHP with exec or system calls, both I don't really want to do due to time constraints.


If anyone can lend a hand I would appreciate it.
 
Old 03-31-2007, 12:22 AM   #2
Simon Bridge
Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu 10.04
Posts: 9,195
Blog Entries: 4

Rep: Reputation: 190Reputation: 190
Of course: chmod -R 755 /top/directory will set everything to 755 throughout the tree. This means your problem is reduced to setting the x bit to 0 for all files that are not directories... chmod -R -x [file] but you need scripting skills to single out only non-directories from this.

Have fun.

Last edited by Simon Bridge; 03-31-2007 at 12:31 AM.
 
Old 03-31-2007, 12:32 AM   #3
jschiwal
Moderator
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 14,971

Rep: Reputation: 527Reputation: 527Reputation: 527Reputation: 527Reputation: 527Reputation: 527
You can use the find command to select just the files and the -exec option to change the permissions:
find top/directory -type f -exec chmod 0644 '{}' \;
find top/directory -type d -exec chmod 0755 '{}' \;

You can also combine both operations into one find command:
Code:
find top/directory  \( -type d -exec chmod -v 755 '{}' \; \) \
                 -o \( -type f -exec chmod -v 644 '{}' \; \)

Last edited by jschiwal; 04-02-2007 at 04:27 AM. Reason: fixed typo.
 
Old 03-31-2007, 05:57 AM   #4
General Failure
Member
 
Registered: Jan 2007
Location: Germany
Distribution: Slackware 13.37
Posts: 384

Rep: Reputation: 34
Or do
Code:
find . -type d -print0 | xargs -0 chmod 0775 # For directories
find . -type f -print0 | xargs -0 chmod 0664 # For files
in the directory where you have the dirs/files.
 
Old 03-12-2010, 04:03 PM   #5
snovak
LQ Newbie
 
Registered: Dec 2007
Posts: 1

Rep: Reputation: 0
another method.

Quote:
Originally Posted by General Failure View Post
Or do
Code:
find . -type d -print0 | xargs -0 chmod 0775 # For directories
find . -type f -print0 | xargs -0 chmod 0664 # For files
in the directory where you have the dirs/files.
For whatever reason, when I tried the above I got an error: -jailshell: fork: Resource temporarily unavailable

So, I figured this out, which worked for me.

Code:
for i in `find . -type d`; do  chmod 755 $i; done
for i in `find . -type f`; do  chmod 644 $i; done
Cheers!
 
Old 12-27-2011, 12:46 AM   #6
slouko
LQ Newbie
 
Registered: Dec 2011
Location: Finland
Posts: 1

Rep: Reputation: Disabled
Or just chmod u+rwX,go+rX *

/sami

Last edited by slouko; 12-27-2011 at 01:07 AM.
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Will this command work? chmod -R 644 *.php abefroman Programming 3 10-22-2005 09:26 AM
chmod 644 /etc/shadow stomach Linux - General 15 09-12-2005 09:28 PM
how to change exisitng files/directory permission from 755 to 770 mweil Linux - Newbie 3 07-01-2004 11:18 AM
Apache and php + chmod 644 daveo Linux - General 2 10-10-2003 09:33 AM
Automatically setting new files on the server as 755 gummyworms Linux - General 3 07-13-2001 12:32 AM


All times are GMT -5. The time now is 09:45 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
Open Source Consulting | Domain Registration