[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: NO! chmod strikes!



%% JoshNarins@aol.com writes:

  j> 1.  ( ) text/plain          (*) text/html           

No need for HTML on the mailing list.

  j> I tried, in a subdir of /root, the command
  j> chmod -R o-rwx .*
  j> It changed the permissions on the parent directory,
  j> the parent's parent directory, all the way up.
  j> Now only root can use my computer.
  j> Was chmod supposed to understand .* so differently
  j> than /bin/ls does?

Both chmod -R and ls -R behave the same way.  However, your description
above is not actually what happens, and I haven't seen anyone else here
correct it in so many words.  So, just to be clear:

Remember that the shell expands all wildcards, not the application.  So,
supposing you had these files/directories in your current working
directory:

 .  ..  .foo  .bar  .biz  baz  boz

Then, the command "chmod -R o-rwx .*" is identical (from the point of
view of chmod, which only gets the postprocessed commandline) to having
typed this:

 chmod -R o-rwx . .. .foo .bar .biz


_Neither_ ls nor chmod (nor any other tool that recurses that I've ever
heard of) will follow ".." in a directory as it's recursing.

However, if you give ".." on the command line, of course it will operate
on that directory just like it would any other directory on the command
line.

The upshot is, "chmod -R o-rwx .." will change the permissions in the
parent directory and all of its subdirectories, recursively; it will
start from the directory above the current directory and walk down.

It will _NOT_ walk back _up_ the tree any further up from the parent.

Ditto for "find", "ls", "diff -r", etc. etc.

So, the what happened here depends on your working directory.  If you
ran the command in /root (or any other directory which is an immediate
subdirectory of /), then the chmod started at / and your entire system
got chmod'd and your system is relatively screwed.

If you ran it from a deeper directory, say /root/foo, then only the files
under /root were changed; that may be less terminal.


BTW, the best way to do what you wanted to do is this:

  $ chmod -R o-owx .[!.]*

That will change everything, recursively, beginning with a ".", except
"." and "..".  Modern shells also accept the more standard RE format:

  $ chmod -R o-owx .[^.]*

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <psmith@baynetworks.com>    HASMAT--HA Software Methods & Tools
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist
-------------------------------------------------------------------------------
   These are my opinions---Nortel Networks takes no responsibility for them.



Reply to: