diff --git a/truncate/GNUmakefile b/truncate/GNUmakefile new file mode 100644 index 0000000..5e87aef --- /dev/null +++ b/truncate/GNUmakefile @@ -0,0 +1,25 @@ +include GNUmakevars + +all: truncate + +clean: + rm truncate customize + +install: $(BINDIR) $(BINDIR)/truncate $(MAN1DIR)/truncate.1 + +%: %.pl customize + sh ./customize < $< > $@ + chmod +x $@ + +%: %.sh customize + sh ./customize < $< > $@ + chmod +x $@ + +customize: configure + sh ./configure + +$(BINDIR): + mkdir -p $@ + +include GNUmakerules + diff --git a/truncate/configure b/truncate/configure new file mode 100644 index 0000000..f4c377f --- /dev/null +++ b/truncate/configure @@ -0,0 +1,40 @@ +#!/bin/sh +# +echo "#!/bin/sh" > customize.$$ +echo "sed \\" > customize.$$ +chmod +x customize.$$ + +################################################################ +# find a find which understands -printf +# (like gnu find) +# +now=`date '+%Y%m%d' ` +touch find_printf.$now.$$ + +for i in /usr/bin/find /usr/local/bin/find +do + ts=`$i find_printf.$now.$$ -printf '%TY%Tm%Td\n'` + if [ "x$ts" = "x$now" ] + then + echo $i works + find_printf="$i" + break + fi +done +if [ -z "$find_printf" ] +then + echo could not find a working find_printf command, sorry. + exit 1 +fi +echo " -e 's,@@@find_printf@@@,$find_printf,g' \\" >> customize.$$ +rm find_printf.$now.$$ + + +################################################################ +# finish +# Add trailing newline and rename temp file to final name +# +echo >> customize.$$ + +mv customize.$$ customize + diff --git a/truncate/truncate.1 b/truncate/truncate.1 new file mode 100644 index 0000000..01eb266 --- /dev/null +++ b/truncate/truncate.1 @@ -0,0 +1,23 @@ +.\" $Id: truncate.1,v 1.1 2000-08-23 13:03:42 hjp Exp $ +.\" $Log: truncate.1,v $ +.\" Revision 1.1 2000-08-23 13:03:42 hjp +.\" Initial release +.\" +.\" +.TH truncate 1 +.SH NAME +truncate - truncate files to zero length +.SH SYNOPSIS +.B truncate +[ +.I find-options +] +.SH DESCRIPTION +Truncate uses find with the specified options to find regular files. +Each file is truncated to zero length, but owner, permissions, and +last-modified date are preserved. If the user doesn't have write +permissions for a file, a message is printed and the file is skipped. +.SH DIAGNOSTICS +Various error messages from the used commands. +.SH AUTHOR +Peter J. Holzer (hjp@wsr.ac.at) diff --git a/truncate/truncate.sh b/truncate/truncate.sh new file mode 100644 index 0000000..c89e153 --- /dev/null +++ b/truncate/truncate.sh @@ -0,0 +1,7 @@ +#!/bin/sh +@@@find_printf@@@ "$@" -type f -printf '%TY%Tm%Td%TH%TM.%TS %p\n' | +while read timestamp file +do + echo > "$file" + touch -t "$timestamp" "$file" +done