Find & tar execution problem

I'm trying to set up a stanard sh script that will find all the files that have been changed within the last day and then tar them up.

I think the command line should be something like :

find /home/bob -atime +0 -exec \ tar cvf /home/bob/files.tar {}\;

Help please ...

Thanx

There are a few problems here. First -atime is access time. You want -mtime which is modification time. Next the +0 is going to exclude all the files you want and pick up the rest. "find /home/bob -mtime -1" will give you alist of files modified less than a day ago. But you will also get directories as well as files. "-type f" will take care of that. And finally, you don't want a seperate run of tar for each file...you want to run tar just once.

tar cvf /home/bob/files.tar `find /home/bob -mtime -1 -type f`

will do it. But this assumes that you have enought space on your command line to handle all of the files in question. If you "cd /home/bob" first and use "." instead of "/home/bob" in the find command, you will shorten the length of the list and defer the problem. And having the output file in your home directory is dangerous. If you remove yesterday's before you run the new command you should be ok. But if files.tar gets added to the list, you're in trouble. Putting it in /tmp or /var/tmp while the command is running might be safer.

So my final answer...
cd /home/bob
tar cvf /var/tmp/files.tar `find . -mtime -1 -type f`
mv /var/tmp/files.tar .

Thanks for that. Problem though when i type the tar command I get an error :

tar : find . -mtime -1 -type f: no such file or directory.

Thoughts please.

########### PLease ignore had ' instead of ` in line #############

Thanx

Just to complicate matters I want to refine the search to include files that are less than 1 day old and older than 2 hours. Is it possible to search by hours old rather than days.

Thanx

:smiley: