home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / boot / i386 / rescue / usr / bin / old < prev    next >
Text File  |  2006-11-29  |  763b  |  42 lines

  1. #!/bin/bash
  2.  
  3. #
  4. # This script simply renames files or directories to <name>-<date>[<num>]
  5. #
  6. # Copyright (c) 1996-2002 SuSE Linux AG, Nuernberg, Germany.
  7. #
  8. # please send bugfixes or comments to http://www.suse.de/feedback.
  9. #
  10. #
  11. # usage - tell user to use program
  12. #
  13.  
  14. function usage() {
  15.     echo usage: "$0" file\|dir [file\|dir ...]
  16. }
  17.  
  18.  
  19. if [ $# -eq 0 ] ; then
  20.     usage
  21.     exit
  22. fi
  23.  
  24. DATESTRING=`date +"%Y%m%d"`
  25.  
  26. for i in "$@" ; do
  27.     i=${i%%/}
  28.     if [ -e "$i" ] ; then
  29.         NEWNAME=$i-$DATESTRING
  30.         NUMBER=0
  31.         while [ -e "$NEWNAME" ] ; do
  32.             NEWNAME=$i-$DATESTRING-$NUMBER
  33.             let NUMBER=$NUMBER+1
  34.         done
  35.         echo moving "$i" to "$NEWNAME"
  36.         mv "$i" "$NEWNAME"
  37.     else
  38.         echo "$i" does not exist.
  39.     fi
  40. done
  41.  
  42.