Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving files based on time created 3

Status
Not open for further replies.
Aug 30, 2004
12
0
0
CA
Can anyone help me out with this?

I would like to run a cron job that will periodically move all files in a specified directory, to a seperate folder ...if the files were created above a specified date.

What I have so far is:

find ${directory} -name fimename.* -ctime +60 -exec mv {} \ archive/;

In the above scipt, I was hoping to move all files above 60 days old, with name pattern filename.*, to the directory 'archive'.

But no dice, the script does not work. It comes back as 'incomplete statement'.

Can anyone help point out where I have erred?
 
find ${directory} -name 'filename.*' -ctime +60 -exec mv {} /path/to/archive \;

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
To explain PHV's solution, you need to prevent the shell that is running your find command from expanding *.filename, otherwise you end up with an invalid find syntax, e.g. (preuming there are three files that match that file specification):

[tt]find ${directory} -name filename.one filename.two filename.three -ctime +60 -exec mv {} /path/to/archive \;[/tt]



Annihilannic.
 
Annihilannic, I also escaped the terminating semi-colon.
 
Thanks for all your tips :)

When I ran the script, I received the following message:

>>find: bad option filename
>>find: path-list predicate-list

Googling did not enlighten - would you have any tips why the error occured?
 
Can you post exactly what your command was? Look as if you might have missed out the apostrophes, but there may be other culprits.

Alan Bennett said:
I don't mind people who aren't what they seem. I just wish they'd make their mind up.
 
A possibility is that ${directory} has no value.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I entered the following:

find {Directory_Path} -name *.* -ctime +60 -exec mv '{}' {Directory_Path_to_Move Files} \;

and received the following error messages:

>>find: bad option filename
>>find: path-list predicate-list

Thanks for all your great tips :)
 
What are EXACTLY {Directory_Path} and {Directory_Path_to_Move Files} ?
I strongly suggest you protect your code against shell expansion:
-name [!]'[/!]*.*[!]'[/!]

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
As PHV says, use single quotes around the wildcard filenames. In addition, the quotes around the {} in the exec aren't required.

Alan Bennett said:
I don't mind people who aren't what they seem. I just wish they'd make their mind up.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top