LinuxQuestions.org
Support LQ: Use code LQCO20 and save 20% on CrossOver Office
Go Back   LinuxQuestions.org > Forums > Linux > Linux - General
User Name
Password
Linux - General This 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
 
Thread Tools Search this Thread
Old 03-30-2007, 11:46 PM   #1
cope
LQ Newbie
 
Registered: Apr 2005
Distribution: rhel, centos, ubuntu
Posts: 18
Thanked: 0
chmod all files 644 and files 755


[Log in to get rid of this advertisement]
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.
cope is offline     Reply With Quote
Old 03-31-2007, 12:22 AM   #2
Simon Bridge
Guru
 
Registered: Oct 2003
Location: Red Beach (NZ)
Distribution: Ubuntu 9.10
Posts: 8,483
Blog Entries: 4
Thanked: 134
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..
Simon Bridge is offline     Reply With Quote
Old 03-31-2007, 12:32 AM   #3
jschiwal
Moderator
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 13,312
Thanked: 294
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.
jschiwal is offline     Reply With Quote
Old 03-31-2007, 05:57 AM   #4
General Failure
Member
 
Registered: Jan 2007
Location: Germany
Distribution: Slackware64-current
Posts: 377
Thanked: 6
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.
General Failure is offline     Reply With Quote

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
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 02:38 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.
Advertisement
Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Click Here to receive a complimentary subscription courtesy of LQ.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration