LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-13-2011, 11:17 PM   #1
nixanwin
LQ Newbie
 
Registered: Mar 2010
Posts: 24

Rep: Reputation: 0
Help with "find" command in backup/zip script


Hi, I am fairly new to scripting and I am trying to write a script that finds and zips a file named file1.xml from multiple sub-directories. So basically I want to find them and zip them all together. The disk directory structure is as follows:

/mnt/data/user_name1/db/file1.xml
/mnt/data/user_name2/db/file1.xml
(etc, etc where user_name varies)

This is what I have so far, but I keep getting an error relating to the -name command.

filename=`date +%d%m%Y-%H:%M`
find /mnt/data/ -name file1.xml -maxdepth 2 -type d | zip -rp $filename.zip -@


I keep getting the following error but don't know how to fix it. Is what I am trying to do even possible?

find: warning: you have specified the -maxdepth option after a non-option argument -name, but options are not positional (-maxdepth affects tests specified before it as well as those specified after it). Please specify options before other arguments.

Thank you in advance for your patience
 
Old 02-14-2011, 12:17 AM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 373Reputation: 373Reputation: 373Reputation: 373
Quote:
Originally Posted by nixanwin
I keep getting the following error but don't know how to fix it. Is what I am trying to do even possible?

find: warning: you have specified the -maxdepth option after a non-option argument -name, but options are not positional (-maxdepth affects tests specified before it as well as those specified after it). Please specify options before other arguments.
You're not getting an error. As the message says, you're getting a "warning." Typically, a warning does not stop the program, but alerts you that you may not get the results you expect. This warning tells you that the -maxdepth option should be placed before -name on the command line. It also says that, in the case of -maxdepth, it will have the desired effect regardless.

In a nutshell, the program is telling you the form of the command is not what the developers expect--certain command line switches can have different effects depending on where they are placed on the command line.

That said, I think your command is wrong for a different reason. You say you are looking for a "file" named "file1.xml" but your find command is looking for a directory (-type d). I think you probably intended "-type f"
 
Old 02-21-2011, 11:00 AM   #3
nixanwin
LQ Newbie
 
Registered: Mar 2010
Posts: 24

Original Poster
Rep: Reputation: 0
Sorry for the delay! I tried change the "d" to and "f" and get the following error. For the record, I'm open to a different way to accomplish this. I'm just learning this stuff...

find: warning: you have specified the -maxdepth option after a non-option argument -name, but options are not positional (-maxdepth affects tests specified before it as well as those specified after it). Please specify options before other arguments.


)ip error: Invalid command arguments (no such option:
: command not foundes.sh: line 9:


Any help is appreciated. I'm open to pay for a fix if someone want's to PM me. Thanks
 
Old 02-21-2011, 03:03 PM   #4
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 373Reputation: 373Reputation: 373Reputation: 373
Ok, would it be possible to post the script here?

The message you copy-pasted this last time included some more info: there's more going on than just a warning from find. There's a parsing error:

Quote:
)ip error: Invalid command arguments (no such option:
: command not foundes.sh: line 9:
And in my experience, that typically means there could be a mistake as simple as a missing space/semicolon or how the script variables are being used or referenced.

So please, if you can, post the script.
 
Old 02-22-2011, 12:44 AM   #5
nixanwin
LQ Newbie
 
Registered: Mar 2010
Posts: 24

Original Poster
Rep: Reputation: 0
Got it working. I'm not sure what the problem was exactly. Thank you for pointing out the "f" switch

filename=`date +%d%m%Y-%H:%M`
find /mnt/data/ \
-name Profile.xml -maxdepth 3 -type f | zip -rp $filename.zip -@
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Errors executing shell script: "command not found" and "no such file or directory" eko000 Linux - Newbie 1 01-14-2011 08:54 AM
bash script: how to check stderr after command "find" Vilmerok Programming 1 07-08-2009 08:35 AM
Shell Script: Find "Word" Run "Command" granatica Linux - Software 5 07-25-2007 08:42 AM
Can't install "glibmm" library. "configure" script can't find "sigc++-2.0&q kornerr Linux - General 4 05-10-2005 03:32 PM
preserve file ownership with the "zip" command? zovres Linux - General 2 11-25-2004 10:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration