Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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]


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.

share|improve this question
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 – K.K 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 – K.K Patel Dec 20 '12 at 11:22
up vote 1 down vote accepted

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.

share|improve this answer
Thanks a lot Friend.... – K.K Patel Dec 20 '12 at 11:07
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] – K.K Patel Dec 20 '12 at 11:09
Thank a lot Again friend............ – K.K Patel Dec 20 '12 at 11:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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