How to chmod files and dirctories via SSH

Discussion in 'Programming' started by WebTrooper, Aug 14, 2008.

to remove all ads.
  1. WebTrooper

    WebTrooper New Member

    Messages:
    2
    Hi all, great forum you have going here. Can someone please help me out with this? I know how to chmod via SSH. What I need to know is how to chmod a directory and all it's subdirectories to 0777 and chmod all files to 0644.

    I'm using SSH Secure Shell client and writing to a centos box. Thanks! :)
     
  2. jnjc

    jnjc New Member

    Messages:
    493
    chmod -R

    will set permissions recursively
     
  3. WebTrooper

    WebTrooper New Member

    Messages:
    2
    Thanks jnjc, but how do I chmod only the files, or only the subdirectories? -R is just recursive everything.

    I think what I need is something like...

    chmod 0777 -R Directories Only
    chmod 0644 -R Files Only
     
    Last edited: Aug 16, 2008
  4. jnjc

    jnjc New Member

    Messages:
    493
    What you are describing is actually a bit tricky. One way you could do it is:

    chmod 0644 -R *

    which will change all files and directories.
    Then use something like this:

    du | awk '{print "chmod 0644 " $2}' | sh -v

    which will change all directories. Do the commands in this order and it should do what you want (that said you might want to test it out before you do it on a production box).
     

Share This Page