Computer Hope

Software => BSD, Linux, and Unix => Topic started by: UnixKid on March 01, 2012, 10:47:25 PM

Title: Modify bash_profile to set permissions automatically
Post by: UnixKid on March 01, 2012, 10:47:25 PM
Hey all -

Running Fedora Core 11 here. I'm editing my .bash_profile so it will execute the following:

alias "chmodWeb"="chmod ugo-rwx *.* | chmod u+rwx *.* | chmod o+rx *.*"

Theoretically, this should take all files and folders within a given directory and change the permissions as follows:

u: rwx
g: ---
o: r-x

However, when I run this, it's.... strange. I have yet to get anything consistent from this. Sometimes it changes the permissions of one out of four files to rwx------, sometimes it changes all of them to ------r-x. Can someone help me figure out what is going on and how to fix it? If you've got another idea for quickly changing permissions to rwx---r-x via command line without installing additional software, I'm all ears. Well, eyes, in this case.

Thanks!
Title: Re: Modify bash_profile to set permissions automatically
Post by: Rob Pomeroy on March 14, 2012, 05:38:51 AM
Why are you using the pipe symbol?  Did you mean ';' instead of '|'?
Title: Re: Modify bash_profile to set permissions automatically
Post by: UnixKid on March 14, 2012, 12:05:34 PM
Why are you using the pipe symbol?  Did you mean ';' instead of '|'?

I want them to execute the commands with one command, not three. The whole idea is to simplify setting permissions for web pages.

The problem is it seems to want to execute all sessions at the same time, rather than in order. I tried using ';' instead of '|', and I got the same results. What is the difference, in theory, between ';' and '|'?
Title: Re: Modify bash_profile to set permissions automatically
Post by: Rob Pomeroy on March 22, 2012, 05:01:12 AM
Pipe takes the output of the command to the left of the pipe and sends it as input to the command to the right of the pipe.

I really don't think you want to execute these commands simultaneously.  If for example the first command happened to run a millisecond after the second and third commands, you'd just end up undoing the effects of the latter commands.  (Think about it.)

Anyway, as it happens, the Gnu version of chmod can do all this in one command, so how about this instead:
Code: [Select]
alias chmodWeb="chmod g-rwx,u+rwx,o+rx *"
The ".*" is redundant in Linux/Unix.  You're thinking of Windows/DOS.
Title: Re: Modify bash_profile to set permissions automatically
Post by: UnixKid on March 26, 2012, 01:28:35 AM
Pipe takes the output of the command to the left of the pipe and sends it as input to the command to the right of the pipe.

I really don't think you want to execute these commands simultaneously.  If for example the first command happened to run a millisecond after the second and third commands, you'd just end up undoing the effects of the latter commands.  (Think about it.)

Anyway, as it happens, the Gnu version of chmod can do all this in one command, so how about this instead:
Code: [Select]
alias chmodWeb="chmod g-rwx,u+rwx,o+rx *"
The ".*" is redundant in Linux/Unix.  You're thinking of Windows/DOS.
This worked. Thanks a ton!
Title: Re: Modify bash_profile to set permissions automatically
Post by: Rob Pomeroy on March 26, 2012, 06:09:15 AM
You're welcome.  :)