Need help to tar files in a directory older(creation date) than 45 days old

Need help to tar files in a directory older(creation date) than 45 days old

Post by dano196 » Sat, 13 Aug 2005 04:03:05



Need help to tar files in a directory older(creation date) than 45 days
old.  say there is 1000 files in the directory and only 300 of them are
older than 45 days old..i want to have it archive(tar) only the 300
older files and leave the rest.  Filename structure is:

filename.dat.Z (they have been compressed already

I just cant seem to get anything I try to work correctly please help!

I was trying combinations of find and tar wasn't working right.

 
 
 

Need help to tar files in a directory older(creation date) than 45 days old

Post by Michael Tosc » Sat, 13 Aug 2005 05:45:37



> Need help to tar files in a directory older(creation date) than 45 days
> old.  say there is 1000 files in the directory and only 300 of them are
> older than 45 days old..i want to have it archive(tar) only the 300
> older files and leave the rest.  Filename structure is:

> filename.dat.Z (they have been compressed already

> I just cant seem to get anything I try to work correctly please help!

> I was trying combinations of find and tar wasn't working right.

Linux:
find . -type f -mtime +45 -print0 | xargs -0 tar cf ../file.tar

Solaris, HPUX11.11:
find . -type f -mtime +45 -exec tar cf ../file.tar {} +

If none of the above works, and file names do not have spaces:
find . -type f -mtime +45 -print | xargs tar cf ../file.tar

--


 
 
 

Need help to tar files in a directory older(creation date) than 45 days old

Post by Jim » Sat, 13 Aug 2005 05:56:12


Quote:> find . -type f -mtime +45 -print0 | xargs -0 tar cf ../file.tar
> find . -type f -mtime +45 -exec tar cf ../file.tar {} +
> find . -type f -mtime +45 -print | xargs tar cf ../file.tar

Wouldn't the above methods overwrite "../file.tar" each time the max #
of arguments to 'tar' is reached (first and third cases, due to
repeating the tar invocation with a new list of filename arguments), or
for each new file found (second case, one tar invocation per file
found)?
 
 
 

Need help to tar files in a directory older(creation date) than 45 days old

Post by Michael Heimin » Sat, 13 Aug 2005 06:16:29




>> Need help to tar files in a directory older(creation date) than 45 days
>> old.  say there is 1000 files in the directory and only 300 of them are
>> older than 45 days old..i want to have it archive(tar) only the 300
>> older files and leave the rest.  Filename structure is:

>> filename.dat.Z (they have been compressed already

>> I just cant seem to get anything I try to work correctly please help!

>> I was trying combinations of find and tar wasn't working right.

> Linux:
> find . -type f -mtime +45 -print0 | xargs -0 tar cf ../file.tar

Without xargs:

  find . -type f -mtime +45 -print | tar -cf file.tar -T -

Seems we are missing something like uuox award? ;-)

[..]

--
Michael Heiming (X-PGP-Sig > GPG-Key ID: EDD27B94)

#bofh excuse 110: The rolling stones concert down the road
caused a brown out

 
 
 

Need help to tar files in a directory older(creation date) than 45 days old

Post by Robert Bono » Sun, 14 Aug 2005 08:21:33






>>> Need help to tar files in a directory older(creation date) than 45 days
>>> old.  say there is 1000 files in the directory and only 300 of them are
>>> older than 45 days old..i want to have it archive(tar) only the 300
>>> older files and leave the rest.  Filename structure is:

>>> filename.dat.Z (they have been compressed already

>>> I just cant seem to get anything I try to work correctly please help!

>>> I was trying combinations of find and tar wasn't working right.

>> Linux:
>> find . -type f -mtime +45 -print0 | xargs -0 tar cf ../file.tar

>Without xargs:

>  find . -type f -mtime +45 -print | tar -cf file.tar -T -

Works *ONLY* if you have a version of tar that supports the '-T' option.
 
 
 

Need help to tar files in a directory older(creation date) than 45 days old

Post by Robert Bono » Sun, 14 Aug 2005 08:28:49




>> find . -type f -mtime +45 -print0 | xargs -0 tar cf ../file.tar

>> find . -type f -mtime +45 -exec tar cf ../file.tar {} +

>> find . -type f -mtime +45 -print | xargs tar cf ../file.tar

>Wouldn't the above methods overwrite "../file.tar" each time the max #
>of arguments to 'tar' is reached (first and third cases, due to
>repeating the tar invocation with a new list of filename arguments), or
>for each new file found (second case, one tar invocation per file
>found)?

ABSOLUTELY *CORRECT* !!!

The foolproof way requires first creating a tarfile ("c" option) with a single
file , then using one of the above find commands, with the 'u' option,
_instead_ of 'c'.  if that single file is small, nothing is really hurt
if it also gets included in the stuff done by the 'find' command.

Some versions of tar * and moan if you specify 'u' or 'r', and the
tarfile _does_not_ exist.

 
 
 

Need help to tar files in a directory older(creation date) than 45 days old

Post by Michael Heimin » Sun, 14 Aug 2005 08:30:14







>>>> Need help to tar files in a directory older(creation date) than 45 days
>>>> old.  say there is 1000 files in the directory and only 300 of them are

[..]

Quote:>>> Linux:

    ^^^^^

Quote:>>> find . -type f -mtime +45 -print0 | xargs -0 tar cf ../file.tar

>>Without xargs:

>>  find . -type f -mtime +45 -print | tar -cf file.tar -T -
> Works *ONLY* if you have a version of tar that supports the '-T' option.

??

--
Michael Heiming (X-PGP-Sig > GPG-Key ID: EDD27B94)

#bofh excuse 444: overflow error in /dev/null

 
 
 

Need help to tar files in a directory older(creation date) than 45 days old

Post by John » Sun, 14 Aug 2005 10:26:45







> >>> Need help to tar files in a directory older(creation date) than 45 days
> >>> old.  say there is 1000 files in the directory and only 300 of them are
> >>> older than 45 days old..i want to have it archive(tar) only the 300
> >>> older files and leave the rest.  Filename structure is:

> >>> filename.dat.Z (they have been compressed already

> >>> I just cant seem to get anything I try to work correctly please help!

> >>> I was trying combinations of find and tar wasn't working right.

> >> Linux:
> >> find . -type f -mtime +45 -print0 | xargs -0 tar cf ../file.tar

> >Without xargs:

> >  find . -type f -mtime +45 -print | tar -cf file.tar -T -

> Works *ONLY* if you have a version of tar that supports the '-T' option.

Linux will likely use Gnu tar which does.

But as Jim points out elsethread, the find -exec and xargs versions are
dangerous and should not be used.

Probably the best portable answer is to use a two-step process:
first, use find to create either an include or an exclude list, then,
second, call tar with the include or exclude list. Alternatively, use
cpio (which does read stdin) rather than tar.

--
John.

 
 
 

Need help to tar files in a directory older(creation date) than 45 days old

Post by John » Sun, 14 Aug 2005 10:50:08



> Need help to tar files in a directory older(creation date) than 45 days
> old.

You can't use the creation date, only the date/time
the file was last modified or last accessed.

If you really do want the creation date, and the files
may have been modified since creation, then you need
to store the creation date yourself, perhaps by including
it in the filename (eg file.2005-08-13).

--
John.

 
 
 

Need help to tar files in a directory older(creation date) than 45 days old

Post by Jim » Mon, 15 Aug 2005 22:46:47


Quote:> Alternatively, use cpio (which does read stdin)
> rather than tar.

Or pax, which can read the file list from stdin but can also output
tar-format archives, if that's what you need.
 
 
 

1. "find"ing directories older than 7 days old.

Hi,

Find is creating me yet more puzzles.

What I am trying to do is, remove all directories that are older than
7 days.  I have set up a daily cron job and the script looks something
like this.

ARCHDIR=/home/nigel/archive

for i in 'find ?????what should I pt here???????'
do
rm -r $i
done

Every night a new directory is created and some files are backup up
there, every day someone has to find last weeks archive directorys sub
directory of that day last week and delete it.

This can be automated can't it?

Cheers,


2. How do i get bash as the default shell?

3. Locating files older than some date or number of days

4. printing selected lines in a file

5. tar of files older then n days

6. AST Premium SVGA (XFree Setup)

7. Scripting Help: tar a dir with time and date as file tar file name..................TIA

8. Installing KonCD Onto Red Hat 7.2 , KDE 2.2 -11

9. WANTED OLD (real old)unix for pdp-11/45

10. Need script to delete files older than 5 days

11. Help deleting files older than 30 days.

12. Need help about hubs with RJ-45 and bnc ports

13. Need help doing a find in current directory only of zero byte file that is older that is older than 10 minutes and move it to a subdirectory off the current directory