Find the answer to your Linux question:
Results 1 to 2 of 2
hello, i want to chmod 444 all files in a directory, files in subdirs cannot be chmoded same goes for the subdirs themself. So using: Code: chmod -R 444 /dir/ ...
  1. #1
    Just Joined!
    Join Date
    Oct 2008
    Posts
    10

    Unhappy help with chmod (files only)

    hello,

    i want to chmod 444 all files in a directory, files in subdirs cannot be chmoded same goes for the subdirs themself.

    So using:

    Code:
    chmod -R 444 /dir/
    won't work because it will chmod the directorys and files (together with files in subdirectorys)

    I figured out how to chmod files only, but it still will chmod files in subdirectorys.

    Code:
    find /dir/ -type f -print0 | xargs -0 chmod 444
    How can I do it?

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    I'm glad that you discovered the find utility. It's quite useful.

    You can use the -maxdepth option to find to control this behaviour. By setting "-maxdepth 0", you tell find to only operate on the command line arguments. By setting "-maxdepth 1", you tell it to only work on entries directly in the commandline arguments. So try it with "-maxdepth 1" and see if that does it for you.
    DISTRO=Arch
    Registered Linux User #388732

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...