Tuesday, October 2, 2007

Unix utils on your Windows box, eg. quick cleanup of dirs

With MKS Toolkit or GnuWin32 on a Windows box you can reuse most of your unix oneliners. Very handy for simple administration. There are other unix tools for Windows, but it seems GnuWin32 is very active!

Here is an example, how to cleanup .txt files created more than 35 days ago:

sh -c "find \\\\host\\sharename -name \"*.txt\" -ctime +35 -exec rm \"{}\" \";\""

That is a nice quick way to delete files older than a specific date, it can easily be modified to do more complex stuff.

More complex sample:

sh -c "find \\\\host\\sharename -name \"*.log\" -depth -mtime +0 -exec echo \"{}\" %date% \";\" grep -v \"renamed\" awk '{print \"mv \"$1\" \"$1$2$3\"renamed.log\"}' sh "


EDIT1:

The %date% syntax is really useful in batch scripts, eg:

echo %time%

11:02:54,16


echo %date%

03-10-2007


echo %date:~6%%date:~3,2%%date:~0,2%-%time:~0,2%%time:~3,2%%time:~6,2%

20071003-110300


The end.

1 comment:

daspeac said...

I have heard about another way of how to repair corrupted word document. Besides, you can visit my blogs at: http://daspeac.livejournal.com/ or http://daspeac.blogspot.com/ where I’m trying to share my experience with regard to data corruption issues.