chmod -R 755 *.cgi

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • HQ
    Confirmed User
    • Jan 2001
    • 3539

    #1

    chmod -R 755 *.cgi

    Why does this command NOT work?

    chmod -R 755 *.cgi
    chmod: getting attributes of `*.cgi': No such file or directory

    I want to recursively change every .cgi file to 755. Is there no way to do a wildcard and recurse at the same time with chmod?
  • Vendot
    Confirmed User
    • May 2002
    • 3376

    #2
    Looks like you need to recurse and wildcard before you chmod the .attribute.

    If you chmod the 755 back to 745 it will also.
    "In a Time of Universal Deceit, Telling the Truth is a Revolutionary Act." - George Orwell

    Comment

    • HQ
      Confirmed User
      • Jan 2001
      • 3539

      #3
      You mean like this?

      chmod -R *.cgi 755
      chmod: invalid mode string: `*.cgi'

      Comment

      • gallerypost
        Confirmed User
        • Nov 2001
        • 711

        #4
        Originally posted by HQ
        Why does this command NOT work?

        chmod -R 755 *.cgi
        chmod: getting attributes of `*.cgi': No such file or directory

        I want to recursively change every .cgi file to 755. Is there no way to do a wildcard and recurse at the same time with chmod?
        bah... well the thing is that when you give it *.cgi it'll search only for *.cgi files for the chmod...
        directories aren't *.cgi so the -R won't help, it won't get into the directories....

        that's why it didn't work, but i don't know what should work, i almost have no clue about *nix .... so if you find the answer... please share it with us ;)

        Comment

        • HQ
          Confirmed User
          • Jan 2001
          • 3539

          #5
          I think you are right. How do I tell it to recurse a directory (the current directory) and apply the *.cgi wildcard at the same time?

          Comment

          • boldy
            Macdaddy coder
            • Feb 2002
            • 2806

            #6
            .
            Last edited by boldy; 09-26-2002, 06:45 AM.
            MacDaddy Coder.

            Comment

            • HQ
              Confirmed User
              • Jan 2001
              • 3539

              #7
              Originally posted by boldy
              .
              I know that. How do I do both though?

              Comment

              • HQ
                Confirmed User
                • Jan 2001
                • 3539

                #8
                [edit]

                I was wrong. This command does NOT work.:

                chmod -R 755 . *.cgi

                It changes ALL files. Same as running this command:

                chmod -R 755 .
                Last edited by HQ; 09-26-2002, 07:24 AM.

                Comment

                • boldy
                  Macdaddy coder
                  • Feb 2002
                  • 2806

                  #9
                  Told u

                  .

                  MacDaddy Coder.

                  Comment

                  • HQ
                    Confirmed User
                    • Jan 2001
                    • 3539

                    #10
                    Nope, I was wrong. That above command CHANGES ALL FILES just as running "chmod -R 755 ." would do.

                    FUCK!

                    Comment

                    • HQ
                      Confirmed User
                      • Jan 2001
                      • 3539

                      #11
                      Anyone know how to do this? If it can not be done, I am going to have to code a script to do this because I have way too many files to manually change.

                      Comment

                      • FuqALot
                        Confirmed User
                        • Dec 2001
                        • 3817

                        #12
                        Hi,

                        cd to the directory and type:
                        find -name '*.cgi' -exec chmod 755 {} \;

                        Hope this helps.

                        Comment

                        • salsbury
                          Confirmed User
                          • Feb 2002
                          • 1070

                          #13
                          to summarize, keep this in mind.

                          your shell is what does the wildcard expansion. so when you type:

                          chmod -R 755 *.cgi

                          your shell expands *.cgi to a list of the files in the current directory that end with .cgi . this would also include directories (which are basically files) that happened to be named something.cgi . only after the expansion is done are the arguments actually sent to chmod.

                          some shells will error out if there are no .cgi files. other shells (better shells) wil just pass '*.cgi' on to the chmod binary. chmod doesn't understand wildcards (most binaries don't, find is an exception) so it would try to change the permissions on a file called '*.cgi'. if that file was a directory it would change them recursively.

                          fuqalot's post is correct. i'm just clarifying why this happens.

                          Comment

                          • HQ
                            Confirmed User
                            • Jan 2001
                            • 3539

                            #14
                            Thanks for explaining how it works salsbury, that helps a lot. So wildcards and recursing are exclusive, which is what I thought, I just did not know exactly why.

                            Comment

                            • HQ
                              Confirmed User
                              • Jan 2001
                              • 3539

                              #15
                              Originally posted by FuqALot
                              cd to the directory and type:
                              find -name '*.cgi' -exec chmod 755 {} \;
                              Oh... and thanks a million, FuqALot, it works.

                              BTW, the "{}" is the list of files that find returns, right? What is the "\" for?

                              Comment

                              • FuqALot
                                Confirmed User
                                • Dec 2001
                                • 3817

                                #16
                                Originally posted by HQ


                                Oh... and thanks a million, FuqALot, it works.

                                BTW, the "{}" is the list of files that find returns, right?
                                Yep.


                                What is the "\" for?
                                The \; just terminates the command (-exec option), so it 'tells' the -exec line has ended.

                                Comment

                                • HQ
                                  Confirmed User
                                  • Jan 2001
                                  • 3539

                                  #17
                                  Excellent. Thanks again.

                                  Comment

                                  Working...