Results 1 to 13 of 13
  1. #1
    Join Date
    Aug 2010
    Posts
    5

    Unanswered: find: invalid switch

    hi,

    i have a script that includes the following:

    dir1='D:\Program Files\archive'

    for Dir in "$dir1"
    do
    cd "$Dir"
    echo `pwd`
    find `pwd` -mtime +60 -type f {} \;

    done

    exit 0






    then this is the logs:



    + dir1=D:\Program Files\archive
    + cd 'D:\Program Files\archive'
    ++ pwd
    + echo /cygdrive/d/Program Files/archive
    ++ pwd
    + find /cygdrive/d/Program Files/archive -mtime +60 -type f '{}' ';'
    FIND: Invalid switch
    + exit 0




    why do i have such "invalid switch"? please help...thanks!!!

  2. #2
    Join Date
    Aug 2010
    Posts
    5
    the scrip is located in a remote server where there is cygwin and i'm trying to use bash...

  3. #3
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    It seems to be calling the Windows version of "find"; you will need to provide the full path to the cygwin's "find".

  4. #4
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    Or possibly modify your PATH statement so that cygwin is searched before Windows.

  5. #5
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    man find

    This is invalid syntax:
    Code:
    Here >-----------------------------------------------------+----+
                                                               V    V
    find /cygdrive/d/Program Files/archive -mtime +60 -type f '{}' ';'
    man find
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  6. #6
    Join Date
    Aug 2010
    Posts
    5
    hi n i and kitaman,

    do you mean i should put these as first statements in my scrip??>

    #!/cygdrive/c/cygwin/bin/bash -x
    #!/cygdrive/c/cygwin/bin/find -x

    im just new in unix and scripting... how can i do such providing of full path to cygwin???




    hi lkbrwn dba


    my syntax is

    find `pwd` -mtime +60 -type f {} \;


    '{}' ';' >>> are just in the log message... anyway, is there anything wrong with my syntax of 'find' above????




    hi all!!!

    thanks for the replies... thanks much!!! ive read about find command and the "man" says when there's no path provided, the default path is the current pwd so i tried

    find * -mtime +60 -type f {} \; >>>> there was an error: Find parameter incorrect


    i also tried

    find -mtime +60 -type f {} \; >>>> there was the same error: Find parameter incorrect

  7. #7
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool Man find!!!

    Did you check out the syntax of find in the manual?

    Try this and see what happens:
    Code:
    find `pwd` -mtime +60 -type f -exec cksum {} \;
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  8. #8
    Join Date
    Aug 2010
    Posts
    5
    hi lkbrwn_dba,

    i have read before the find man page, it says if no -exec is provided then the default -exec is -print... Anyways, ive tried ur

    find `pwd` -mtime +60 -type f -exec cksum {} \;

    still there's the same error......... please help me!

  9. #9
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool cygwin is a bash.

    Quote Originally Posted by maxtodoscripts View Post
    the scrip is located in a remote server where there is cygwin and i'm trying to use bash...
    Ok cygwin is another animal...
    Try this:
    Code:
    dir1='Program Files/archive'
    cd D:
    
    find "$dir1" -mtime +60 -type f
    
    exit 0
    The issue is the space in the name of the "Program Files" directory.
    Last edited by LKBrwn_DBA; 08-23-10 at 11:57. Reason: New script
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  10. #10
    Join Date
    Aug 2010
    Posts
    2
    Please Try below:-

    dir1="D:\Program Files\archive"
    for Dir in "$dir1"
    do
    cd "$Dir"
    echo `pwd`
    find `pwd` -mtime +1 -type f -print
    done
    exit 0

  11. #11
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool Recursive?

    Quote Originally Posted by script View Post
    Please Try below:-

    dir1="D:\Program Files\archive"
    for Dir in "$dir1"
    do
    cd "$Dir"
    echo `pwd`
    find `pwd` -mtime +1 -type f -print
    done
    exit 0
    You do NOT need the for loop, the find command will recourse the directory tree including it's sub-directories.
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  12. #12
    Join Date
    Aug 2010
    Posts
    5
    hi lkbrwn,,,

    i used ur script, please see LOGS below


    + dir1=Program Files/archive
    + cd D:
    + find 'Program Files/archive' -mtime +60 -type f
    File not found - -MTIME
    File not found - +60
    File not found - -TYPE
    File not found - F
    + exit 0


    it seemed like it's using the find of command prompt as i've read its syntax





    hi script and lkbrwn,,


    it's ok to use for loop because i'm actually creating the scrip for multiple directory,, i just first tried to one...



    hi script,,

    i used ur scrip, the error was "find: invalid switch"

  13. #13
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Thumbs down Wrong, very wrong.

    Quote Originally Posted by maxtodoscripts View Post
    hi lkbrwn,,,

    i used ur script, please see LOGS below

    + dir1=Program Files/archive
    + cd D:
    + find 'Program Files/archive' -mtime +60 -type f
    File not found - -MTIME
    File not found - +60
    File not found - -TYPE
    File not found - F
    + exit 0

    it seemed like it's using the find of command prompt as i've read its syntax


    hi script and lkbrwn,,


    it's ok to use for loop because i'm actually creating the scrip for multiple directory,, i just first tried to one...

    hi script,,

    i used ur scrip, the error was "find: invalid switch"
    You are doing something WRONG, both my script and script's script work.
    Are you using cygwin to execute? and are you saving the script in "Unix" format?
    Show us your script.

    PS: And it is NOT ok to loop because the find command already recourses the sub-directories.
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

Posting Permissions

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