Solved Chown preserve-root

I noticed that --preserve-root options are not available on FreeBSD for chown chgrp and chmod.

Is there any other options to prevent me from doing something stupid, like a recursive change on the wrong folder?

I don't even see an -i option to invoke a standard prompt, similar to when you do cp -i.

Sometimes us humans need to protect us from ourselves.
 
Have a look at chflags(1), in particular the schg flag.

I don't even see an -i option to invoke a standard prompt, similar to when you do cp -i.
It depends on the shell you are using. For csh(1):
Code:
       rmstar (+)
               If set, the user is prompted before `rm *' is executed.

And cp(1):
Code:
     -i    Cause cp to write a prompt to the standard error output before
           copying a file that would overwrite an existing file.  If the
           response from the standard input begins with the character `y' or
           `Y', the file copy is attempted.  (The -i option overrides any pre-
           vious -f or -n options.)
 
I see, so this basically works like chattr, where you have to go through and set the files/folders that you want to become immutable.

Now if I was to set this flag on important files/folders that need to be updated by the system, I would gather that this flag would need to be toggled off every time in order to update those files/folders?

I don't even see an -i option to invoke a standard prompt, similar to when you do cp -i.

I was trying to say that I didn't see an option for the change commands that has similar functions to when you do cp -i.
 
You can use GNU's gchmod, gchown etc. from sysutils/coreutils if you need --preserve-root.
Is there any other options to prevent me from doing something stupid, like a recursive change on the wrong folder?
Prevent never, but mitigate yes: make a filesystem snapshot before doing something potentially dangerous or stupid. Though this is only convenient if you use ZFS. Even better if you let the system create snapshots automatically.
 
Thanks. GNU's chmod is exactly what I was looking for.

I already take nightly snapshots when the traffic is at it's lowest. It's true that you cannot prevent every disaster, but I would rather avoid the flood by taking all necessary measures rather than trying to mitigate the damage from the flood.

SirDice: Thanks for the heads up on schg from the chflags(). Although I haven't had to use the equivalent of the GNU chattr. It will certainly come in handy soon enough.
 
I was trying to say that I didn't see an option for the change commands that has similar functions to when you do cp -i.
Still not sure what you mean but I noticed on a some Linux distributions there are a few aliases defined:

Code:
alias cp='cp -i'
alias rm='rm -i'
alias mv='mv -i'
 
I don't even see an -i option to invoke a standard prompt, similar to when you do cp -i.

I was just trying to use cp -i as an example, as in there is no -i option with the change commands that prompts you before doing something like a recursive chown on root. I was just looking for some protective measures with the change commands. I'm sorry for the confusion of using cp -i as an example.

However tobik pointed out that there is a GNU gchown, gchmod, etc available in the ports collection that has the --preserve-root which prevents that kind of mistake.

Since cp has been brought up, I do like how in the BSD implementation that cp -P is default and I do not have to define it as an alias or in the command line as it's automatically assumed by BSD not to recursively follow symlinks. Linux does not assume that at all it will just churn along those symlinks in an endless loop. An example on Linux would be doing a recursive copy on a clients web folders that has symlinks. It just churns on forever until eventually your monitoring software (if any is implemented) warns of home becoming full.
 
Back
Top