LinuxQuestions.org
Visit Jeremy's Blog.
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 03-30-2007, 10: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-30-2007, 11:22 PM   #2
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
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-30-2007 at 11:31 PM.
 
Old 03-30-2007, 11:32 PM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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 03:27 AM. Reason: fixed typo.
 
Old 03-31-2007, 04:57 AM   #4
General Failure
Member
 
Registered: Jan 2007
Location: Germany
Distribution: Slackware 13.37
Posts: 387

Rep: Reputation: 37
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, 03: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-26-2011, 11:46 PM   #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 12:07 AM.
 
Old 10-26-2013, 09:06 PM   #7
Always_Learning
LQ Newbie
 
Registered: Nov 2010
Posts: 25

Rep: Reputation: 1
Quote:
Originally Posted by snovak View Post
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
The above doesn't work if any of the folders or files contain spaces in their names. You can mess about with the $IFS variable to change the for loop's whitespace handling or you can use a while loop instead, ala:
Code:
find . -type d | while read folder ; do chmod 755 "$folder" ; done
find . -type f | while read file ; do chmod 644 "$file" ; done
 
Old 01-04-2014, 10:52 PM   #8
linuxdev2013
LQ Newbie
 
Registered: Jan 2014
Posts: 7

Rep: Reputation: Disabled
I have a slightly different situation but don't wanna make things mudder so ill ask first (should have done to begin with)


have a tri boot sda1 win7 / sda5 Fc20design / sda6 mint 16 and sda8 is home in ntfs


both win7 and fc20 took home partition perms just fine after manually pointing fc20 to sda8 instead of a system-based /home
however when i installed mint it was fine with system-based /home but after pointing it to the sda8 partition I get an error dialog on login stating that the user's $HOME/.dmrc is being ignored and needs chmod 0644 i used another tutorial from a forum to re-generate the file using [$ sudo touch /home/myusername/.dmrc and it shows in a ls -l -a readout but with rwx across the board how can i get this to be rwxr--r-- as it needs to be $ and # chmod 0644 -c ~/home/username/.dmrc don't affect the change..


also is it a file or dir that needs re generated......thanks coming back to linux after over a decade of solely windows
 
  


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
Will this command work? chmod -R 644 *.php abefroman Programming 3 10-22-2005 08:26 AM
chmod 644 /etc/shadow stomach Linux - General 15 09-12-2005 08:28 PM
how to change exisitng files/directory permission from 755 to 770 mweil Linux - Newbie 3 07-01-2004 10:18 AM
Apache and php + chmod 644 daveo Linux - General 2 10-10-2003 08:33 AM
Automatically setting new files on the server as 755 gummyworms Linux - General 3 07-12-2001 11:32 PM

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

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