In a shell script.. how do I test if any *.php exist?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tempest
    Too lazy to set a custom title
    • May 2004
    • 10217

    #1

    In a shell script.. how do I test if any *.php exist?

    if test -e *.php; is invalid so how do you do that?
  • kmanrox
    aka K-Man
    • Oct 2001
    • 29295

    #2
    my techs arent around, but if you mean search for .php the comman is locate *.php
    Crypto HODLr
    Crypto mining
    Angel investor

    Comment

    • Tempest
      Too lazy to set a custom title
      • May 2004
      • 10217

      #3
      not to search.. to check if any exists and branch in the script based on it.

      Comment

      • rowan
        Too lazy to set a custom title
        • Mar 2002
        • 17393

        #4
        Maybe something like...

        if [ "`ls *.php`X" = "X" ]; then
        # no *.php
        fi


        That may print out an error to stderr if there's no files. Not sure.

        I wouldn't use 'locate' since that checks the locate database (which is only rebuilt periodically) rather than looking at actual (current) directory entries.

        Comment

        • Pixelbucks Eric
          Confirmed User
          • Nov 2008
          • 496

          #5
          if [ -f *.php ]; then echo "PHP files present"; fi

          Mind you, the spaces need to be there.
          Also, you could do:

          if [ ! -f *.php ]; then echo "no PHP files present"; fi
          New Program! http://www.pixelbucks.com | ICQ: 369055569

          Comment

          • sortie
            Confirmed User
            • Mar 2007
            • 7771

            #6
            Originally posted by Tempest
            if test -e *.php; is invalid so how do you do that?
            Let me guess......you got hacked and you have cheap hosting
            and the host thinks the problem is you.




            Just a WILD guess here.

            Comment

            • Tempest
              Too lazy to set a custom title
              • May 2004
              • 10217

              #7
              Originally posted by sortie
              Let me guess......you got hacked and you have cheap hosting
              and the host thinks the problem is you.



              Just a WILD guess here.
              No.. setting up a script to do an auto update of data files and need to do a cleanup.

              Comment

              • 2012
                So Fucking What
                • Jul 2006
                • 17189

                #8
                Originally posted by sortie
                Let me guess......you got hacked and you have cheap hosting
                and the host thinks the problem is you.




                Just a WILD guess here.
                what dick you are
                best host: Webair | best sponsor: Kink | best coder: 688218966 | Go Fuck Yourself

                Comment

                • 2012
                  So Fucking What
                  • Jul 2006
                  • 17189

                  #9
                  Originally posted by Tempest
                  No.. setting up a script to do an auto update of data files and need to do a cleanup.
                  sounds like you just need this ... http://www.amazon.com/Linux-Command-.../dp/047025128X
                  best host: Webair | best sponsor: Kink | best coder: 688218966 | Go Fuck Yourself

                  Comment

                  • rowan
                    Too lazy to set a custom title
                    • Mar 2002
                    • 17393

                    #10
                    Originally posted by Pixelbucks Eric
                    if [ -f *.php ]; then echo "PHP files present"; fi

                    Mind you, the spaces need to be there.
                    Also, you could do:

                    if [ ! -f *.php ]; then echo "no PHP files present"; fi
                    Might also need to quote "*.php"

                    Comment

                    Working...