Unix Linux Find command – how to copy files – how to tar files – based on creation time – based on modification time

I had to tar a bunch of directories from a unix file system today based on the creation time.
Log story short the directories were assigned random numbers for names so there was no way to tell new and old directories apart other than using the creation time.

I was hoping to do this with a single command however it never worked, I did end up getting it to work in 2 steps and would love to hear from someone regarding whether the syntax of the single command needs tweaking.

Initially I created the following
find . -depth -type d -ctime -2 -exec tar -zcvf ../cal2012.tar.gz {} \;
This tarred everything not just the stuff that was within two days old.

I ended up having to write all of the out put to a file like this
find . -depth -type d -ctime -2 -print > file.txt

From there I could tar it by reading the data from the file
tar -c -f cal2012.tar.gz –files-from files.txt

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s