Solved

Set Permisssions differently on files and folders

Posted on 2006-07-03
10
1,421 Views
Last Modified: 2013-12-16
Hi all,
My problem is as follows:

What i want to do is set the mode of files and directories differently (including hidden files and hidden directories)



So lets say i want to make all files 0640 and the directories 6750

I know i can always recursively set the permissions on everything by typing:
        cd /my/root/dir/
      chmod -R 0640 *

but is there a way to pick up every subdir and give it different values without manually going through each directory?

The directories i'm refering to have many nested files and folders so the manual process of first setting the files permissions is easy, but setting the folders is boring.

I presume this can be achieved with the recursive option in chmod and some intelligent use of grep, but i have no idea how.

Any help would be greatly appreciated.

couldntcarebear
0
Comment
Question by:couldntcarebear
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
10 Comments
 
LVL 22

Expert Comment

by:pjedmond
ID: 17030109
The following changes directories only :

find /my/root/dir -type d | awk {'print "chmod +755 " $0'} | /bin/sh

Lets talk through it:

find /my/root/dir -type d

lists only the directories - This is passed to

awk {'print "chmod +755 " $0'}    where $0 is the directory path. awk merely builds up the command. If you run

find /my/root/dir -type d | awk {'print "chmod +755 " $0'}

you can see the commands that you would like to run:) A good test to run this to confirm what commands you will get before the next step!

...As we'd like to run these commands, lets pipe them to a shell:


find /my/root/dir -type d | awk {'print "chmod +755 " $0'} | /bin/sh

This is an extrmely powerful process for building up very selective commands!

(   (()
(`-' _\
 ''  ''



0
 
LVL 22

Accepted Solution

by:
pjedmond earned 500 total points
ID: 17030116
Best I read the Q!

>So lets say i want to make all files 0640 and the directories 6750

1. Directories:

find /my/root/dir -type d | awk {'print "chmod 6750 " $0'} | /bin/sh

2. Files:

find /my/root/dir -type f | awk {'print "chmod 0640 " $0'} | /bin/sh

There are other 'types' for symbolic links etc

(   (()
(`-' _\
 ''  ''
0
 
LVL 16

Expert Comment

by:xDamox
ID: 17037281
Hi,

You could try the followng:

find /path -type d -exec chmod 6750 {} \;
find /path -type f -exec chmod 0640  {} \;
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 3

Expert Comment

by:bryanlloydharris
ID: 17164373
I like Damox' way, but here is another:

cd /path/
chmod -R 6750 .
find . -type f -exec chmod 0640 {} \;

PJ, why do you have to pipe to "sh"?  Won't it do it correctly without that?
0
 
LVL 16

Expert Comment

by:xDamox
ID: 17333809
why should pjedmond just get the points it should be a point split between

pjedmond xDamox and bryanlloydharris
0
 
LVL 25

Expert Comment

by:Cyclops3590
ID: 17333926
I was debating whether to split the points or not between pjedmond and you (xDamox) since they were different solutions to the same issue.  Reason I didn't was because  because pjedmond's solution is correct and was first.

However, I wasn't going to split to bryanlloydharris, because it just seemed like too much of a duplicate of your (xDamox) post.

The moderator can split however they please as this one is questionable, but if there is a split I'd recommend only between pjedmond and xDamox; however, I will stand by my original recommendation.
0
 
LVL 22

Expert Comment

by:pjedmond
ID: 17335571
I'm also a little dubious about this as a process. I personally feel that for this site to perform in the best possible manner for those searching for solutions, then given the option to split points between accurate and useful solutions helps indicate to the person browsin the site that those marked are valid solutions. Then again, the solutions marked as being correct by some users (or indeed occassionally the moderators) does sometimes leave something to be desired.

However a guess that is site 'policy' decision as to guidelines provided. I'm happy with the decision either way, and appreciate the work done by the cleanup voluteers - Having done a bit myself, I have to confess that it doesn't really excite me that much! Considering that, Cyclops does an exceptionally good job in keeping this TA tidy - keep up the good work.

...and to answer bryanlloydharris' Q - You need to pipe it to a shell to execute the commands, otherwise they are merely printed to the console.

(   (()
(`-' _\
 ''  ''

0
 
LVL 25

Expert Comment

by:Cyclops3590
ID: 17335684
pjedmond, thank you for the kind remark.

However I do want to say that if someone does disagree with my recommendation, I do want to hear it.  While keeping a TA tidy is probably the key function of a CV, I want to make sure to be as fair as possible to all the experts while making sure that the recommendations I make (since they are accepted most of the time) will give the greatest value to the EE database. (Being as I am one who searches the database for answers as well)   If I am being unfair or am using bad logic in coming to a recommendation let me know and I'll change if it is sufficiently pointed out to me.
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
lunix and unix command 21 116
How to mount nfs share on this CentOS server? 6 56
LogmeIn using Linux Ubuntu 16.04 6 111
Looking for a program called HoneyMine. 3 64
Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question