-1

I am new to bash script and want to create bash script that moves some days old files between source and destination as per days defined in script.

When I run this script I get error

find: paths must precede expression: mv Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]

#!/bin/bash

echo "Enter Your Source Directory"
read soure

echo "Enter Your Destination Directory"
read destination 

echo "Enter Days"
read days




   find $soure -mtime +$days  mv $soure $destination {} \;

  echo "Files $days old moved from $soure to $destination"

What's missing or wrong ???? please help me to create this script.

  • What are you trying to accomplish with this do-done pair? I don't see any while or for loop definition. I think it will work fine without these two lines. I also suggest you to start reading on basic Bash scripting. – gertvdijk Dec 20 '12 at 10:57
  • I think I don't need it in this script – Ketan Patel Dec 20 '12 at 11:01
  • Don't change your question completely - ask a new one instead. Your original question was about a do/done syntax error, now you have problems in the find command. – gertvdijk Dec 20 '12 at 11:15
  • ok sorry friend – Ketan Patel Dec 20 '12 at 11:22
1

To my understanding of what you're trying to accomplish, you don't want the two do and done lines in your file. Just remove them.

Usually, they're used in for and while loops, but I don't see any of them in your script and I think you don't need them.

update (your question has become a completely new one!)

The find command lacks the -exec option to the command you want to run. Additionally, if you want to move files into a new destination, use find like this:

find $soure -mtime +$days -exec mv {} $destination \;

The {} already match your source files.

  • Now I am getting following error find: paths must precede expression: mv Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression] – Ketan Patel Dec 20 '12 at 11:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.