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.


echo "Enter Your Source Directory"
read soure

echo "Enter Your Destination Directory"
read destination 

echo "Enter Days"
read days

find $soure -mtime -$days -exec mv {} $destination \;
echo "Files which were $days Days old moved from $soure to $destination"

my script runs without error, but I am not getting required output. When I run to move 30 day old files of /home/ketan/maxi folder to /home/ketan/google, it moves whole maxi folder to google rather than files.

I need to be able to move files that meet the age criteria as per the script. What is wrong with this script?

share|improve this question
up vote 5 down vote accepted

The find expression will match the parent directory as well. You need to tell it to only operate on regular files if you want it to move the files only. Additionally, you should quote your expansions.

find "$soure" -type f -mtime "-$days" -exec mv {} "$destination" \;
share|improve this answer
Thanks a lot....Finally working.... – K.K Patel Dec 20 '12 at 13:19

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.