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 |
Quote:
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" |
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 |
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:
So please, if you can, post the script. |
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 -@ |
All times are GMT -5. The time now is 04:33 PM. |