If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > find: invalid switch

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-19-10, 07:39
maxtodoscripts maxtodoscripts is offline
Registered User
 
Join Date: Aug 2010
Posts: 5
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!!!
Reply With Quote
  #2 (permalink)  
Old 08-19-10, 07:43
maxtodoscripts maxtodoscripts is offline
Registered User
 
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...
Reply With Quote
  #3 (permalink)  
Old 08-19-10, 08:52
n_i n_i is online now
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,233
It seems to be calling the Windows version of "find"; you will need to provide the full path to the cygwin's "find".
Reply With Quote
  #4 (permalink)  
Old 08-19-10, 15:26
kitaman kitaman is offline
Registered User
 
Join Date: Sep 2009
Location: Ontario
Posts: 526
Or possibly modify your PATH statement so that cygwin is searched before Windows.
Reply With Quote
  #5 (permalink)  
Old 08-19-10, 16:37
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,413
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
Reply With Quote
  #6 (permalink)  
Old 08-20-10, 00:02
maxtodoscripts maxtodoscripts is offline
Registered User
 
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
Reply With Quote
  #7 (permalink)  
Old 08-20-10, 11:12
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,413
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
Reply With Quote
  #8 (permalink)  
Old 08-23-10, 01:55
maxtodoscripts maxtodoscripts is offline
Registered User
 
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!
Reply With Quote
  #9 (permalink)  
Old 08-23-10, 11:28
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,413
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.
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

Last edited by LKBrwn_DBA; 08-23-10 at 11:57. Reason: New script
Reply With Quote
  #10 (permalink)  
Old 08-26-10, 04:00
script script is offline
Registered User
 
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
Reply With Quote
  #11 (permalink)  
Old 08-27-10, 10:03
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,413
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
Reply With Quote
  #12 (permalink)  
Old 08-31-10, 03:08
maxtodoscripts maxtodoscripts is offline
Registered User
 
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"
Reply With Quote
  #13 (permalink)  
Old 08-31-10, 09:55
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,413
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
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On