LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise
User Name
Password
Linux - Enterprise This forum is for all items relating to using Linux in the Enterprise.

Notices


Reply
  Search this Thread
Old 09-10-2007, 02:23 AM   #1
manoj.linux
Member
 
Registered: Aug 2007
Posts: 276

Rep: Reputation: 17
Question chmod on files only


Hi,

I want to know How to run chmod command on Files Only,

For Example I am in test directory
Under which serveral dirs are and around 1000 files are there how to run this command on files only.
 
Old 09-10-2007, 02:48 AM   #2
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
There are probably several methods, but one is to use find to produce a list of all files (not directories) and then execute chmod on each of them. For example
Code:
find /my/directory -type f -exec chmod 644 '{}' +
Change the red parts to fit your needs. If you wonder what that '{}' is..well, you may have guessed that it's where the filelist is being put when exec'ing the given command on each file.

You can also first try the command without chmod'ing to see that it affects the right files:
Code:
find /my/directory -type f
The above would find all regular files (not directories, for example) from within /my/directory.

If the command happens to throw you an error about the exec part, chances are it's because of the plus sign (+) that ends the exec part. In this case try replacing the plus (+) with an escaped semicolon (\;) so it becomes
Code:
find /my/directory -type f -exec chmod 644 '{}' \;
On some machines I remember that it worked with semicolon (which needs a backslash in front of it, to protect it from being interpreted by your shell), but on my current installation it's the plus sign (without a backslash).

Another way would probably be to list all regular files on the directory (using either find or any tool that can just list all files without directories) and then pipe the output to xargs with which the chmod was run.

Hope this helps..read
Code:
man find
man xargs
for more information. Enjoy!

Last edited by b0uncer; 09-10-2007 at 02:50 AM.
 
Old 09-10-2007, 02:50 AM   #3
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975
i'd just use find...

find /var/blah/ -type f -exec chmod 744 {}\;
 
Old 09-10-2007, 02:50 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975
wow, that reply puts me to shame...
 
  


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
chmod recursion -- files only Risc91 AIX 16 09-28-2016 11:15 AM
chmod all files 644 and files 755 cope Linux - General 7 01-04-2014 10:52 PM
chmod deleted my files NonSumPisces Linux - Newbie 14 09-22-2007 11:37 PM
using chmod for multiple files matrix13 Linux - General 3 02-14-2007 04:45 AM
chmod recursive on files on dlublink Linux - Newbie 6 03-02-2005 08:45 AM

LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise

All times are GMT -5. The time now is 09:41 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration