We Recommend

bash Cookbook: Solutions and Examples for bash Users bash Cookbook: Solutions and Examples for bash Users
bash Cookbook teaches shell scripting the way Unix masters practice the craft. It presents a variety of recipes and tricks for all levels of shell programmers so that anyone can become a proficient user of the most common Unix shell -- the bash shell -- and cygwin or other popular Unix emulation packages.


Posted By

willcodeforfood on 12/16/07


Tagged

bashrc


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

basicmagic


Alias's for quick backup


Published in: Bash 


URL: http://bashscripts.org/viewtopic.php?t=317

  1. Some might rather have backup put key files somewhere else ie in .backup or /backup
  2.  
  3.  
  4. You could do that pretty easily too...
  5. Code:
  6.  
  7. bu () { cp $1 /backup/${1}-`date +%Y%m%d%H%M`.backup ; }
  8.  
  9. This would put all files into /backup/
  10.  
  11. Code:
  12.  
  13. bu () { cp $1 ~/.backup/${1}-`date +%Y%m%d%H%M`.backup ; }
  14.  
  15. This would put all the files into ~/.backup (in your home directory)
  16.  
  17. this would require that you are IN the directory of the file you want to backup. You would move the file with the bu FILENAME ...... you could not use the /path/filename method like i listed above.
  18.  
  19. Here's a twist to so you can maintain your backed-up file in the same directory structure in your .backup directory
  20. Code:
  21.  
  22. bu ()
  23. {
  24. if [ "`dirname $1`" == "." ]; then
  25. mkdir -p ~/.backup/`pwd`;
  26. cp $1 ~/.backup/`pwd`/$1-`date +%Y%m%d%H%M`.backup;
  27. else
  28. mkdir -p ~/.backup/`dirname $1`;
  29. cp $1 ~/.backup/$1-`date +%Y%m%d%H%M`.backup;
  30. fi
  31. }

Report this snippet 

You need to login to post a comment.