Results 1 to 3 of 3
What I want to do is write a script that will rename a file, possibly by appending a date or time, when I open it for editing. If I open ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 01-16-2006 #1
- Join Date
- Jan 2005
how to write a filename script?
This is just an idea that occurred to me as I have a couple of classes that will require me working on the same files multiple times throughout the semester and I thought it would be handy if I could just write a script for it instead of renaming each file manually as I edit (I'm hopeless at keeping track of my work and I always seem to overwrite something I shouldn't)registered linux user: 387197
- 01-16-2006 #2Code:
#!/bin/bash # make a copy of the file in /tmp cp $1 /tmp/ # start your editor $EDITOR $1 DIFF=$(diff $1 /tmp/$1) # If the output of diff is 1 (edited) then change the filename if [ -n DIFF ]; then mv $1 $1-`date +"%T"`-`date +"%d"`-`date +"%m"`-`date +"%y"` fi #remove copy in /tmp rm /tmp/$1
- 01-16-2006 #3
- Join Date
- Oct 2001
- Täby, Sweden
Alternatively, you could just set up a local Subversion repository to store your files in. That way, you won't have to worry about overwriting stuff you shouldn't (at least not as long as you check in your work properly).