[CentOS] how to replace files only if larger

John Summerfield debian at herakles.homelinux.org
Wed Mar 28 00:14:33 UTC 2007


Robert Moskowitz wrote:
> I am consolidating a lot of files.  I have archives of Internet drafts, 
> from over the years.
> 
> I just pulled down all the current Internet Drafts.
> 
> I want to mv all my other stored IDs to this current directory ONLY if, 
> they are larger.
> 
> You may be aware that when a draft is expired, a small file is left in 
> the directory for some time with content like:
> 
> "This Internet-Draft has been deleted. Unrevised documents placed in the
> Internet-Drafts directories have a maximum life of six months. After
> that time, they are deleted. This Internet-Draft was not published as
> an RFC. "
> 
> 
> If I have the actual draft, I would like it to replace this little tab.  
> But if the draft is still available, then my old archive will tend to 
> have a newer date, as I use to grab IDs via FTP which would date my copy 
> the date I grabbed them.  I built my current directory with wget with 
> the -m option, which perserves the original file's date...
> 
> I would even be willing to do this with Nautilus, but so far it just 
> tells me the file exists in the target directory and do I want to 
> replace it...
> 
> Thanks for any help you can provide...
> 
> ============================
> 
> Just had a 'nasty' thought.  By using mget -m to maintain my IDs 
> directory, all my efforts would be for naught, as the deleted message 
> file will have a newer date than my copy of the original draft and 
> overwrite it.
> 
> Crude.
> 
> Got to think some more on this......

find <someplace> -type f -print |\
	 xargs  grep -l "This Internet-Draft has been deleted" \
	| xargs rm

Keep known good while you practice.



Perl has a function to return a file's size, so a little perl may be useful.

Stat makes reports like this:
[summer at bilby ~]$ stat .bash_history
   File: `.bash_history'
   Size: 321324          Blocks: 648        IO Block: 4096   regular file
Device: 303h/771d       Inode: 87460       Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/  summer)   Gid: ( 1000/  summer)
Access: 2007-03-28 07:06:59.000000000 +0800
Modify: 2007-03-27 21:02:15.000000000 +0800
Change: 2007-03-27 21:02:15.000000000 +0800
[summer at bilby ~]$
  One can get the number with a little awk:
[summer at bilby ~]$ stat .bash_history | awk '/Size/ {print $2}'
321324
[summer at bilby ~]$
(but this is better:-)
[summer at bilby ~]$ stat -c '%s' .bash_history
321324
[summer at bilby ~]$


and do it all in sh.



-- 

Cheers
John

-- spambait
1aaaaaaa at coco.merseine.nu  Z1aaaaaaa at coco.merseine.nu

Please do not reply off-list



More information about the CentOS mailing list