I want to make backups of favorite directories and did wrote a little GUI application that does it. Now i want to make the program not to overwrite existing backups - so i want to add date and time to the file names.
How do i grep, sed or whatever needed date and time out, into a format (variable etc) that i can add easily onto a path-/file name?
Thanks for the Help
RSH
Bash - #!/bin/sh - #!/bin/bash
Bash - #!/bin/sh - #!/bin/bash
[b][url=http://lazy-puppy.weebly.com]LazY Puppy[/url][/b]
[b][url=http://rshs-dna.weebly.com]RSH's DNA[/url][/b]
[url=http://murga-linux.com/puppy/viewtopic.php?t=91422][b]SARA B.[/b][/url]
[b][url=http://rshs-dna.weebly.com]RSH's DNA[/url][/b]
[url=http://murga-linux.com/puppy/viewtopic.php?t=91422][b]SARA B.[/b][/url]
- technosaurus
- Posts: 4853
- Joined: Mon 19 May 2008, 01:24
- Location: Blue Springs, MO
- Contact:
current date and time or the date the file was created?
this will give the files date@time-filename
you may want to cp it with -p
this will only remove the file iff the copy is succesful and will not overwrite existing files with the same date stamp and name
btw for current time use
this will give the files date@time-filename
Code: Select all
NEWFILE=`ls -l $FILE |awk '{print $6 "@" $7 "-" $8 }'`
Code: Select all
cp -p "$FILE" "$NEWFILE" && rm "$FILE"
btw for current time use
Code: Select all
NEWFILE="`date +%F@%T`-$FILE"
Last edited by technosaurus on Sun 11 Mar 2012, 07:27, edited 2 times in total.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].
Current date and time is needed, but maybe others wish to get date and time of file? If you know the solution for both - hm - who knows, maybe someone else will be grateful for that?technosaurus wrote:current date and time or the date the file was created?
But to me current time and date is needed.
[b][url=http://lazy-puppy.weebly.com]LazY Puppy[/url][/b]
[b][url=http://rshs-dna.weebly.com]RSH's DNA[/url][/b]
[url=http://murga-linux.com/puppy/viewtopic.php?t=91422][b]SARA B.[/b][/url]
[b][url=http://rshs-dna.weebly.com]RSH's DNA[/url][/b]
[url=http://murga-linux.com/puppy/viewtopic.php?t=91422][b]SARA B.[/b][/url]
- technosaurus
- Posts: 4853
- Joined: Mon 19 May 2008, 01:24
- Location: Blue Springs, MO
- Contact:
the problem with using current date and time is that you may end up backing up files that are already backed up... so you end up with 1000s of copies of the same picture of a funny cat with different date stamps.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].
Thank you very much!
This --> `date +%F` <-- is exactly what i needed. I just do create directories with that name and then save the files inside the directory.
This --> `date +%F` <-- is exactly what i needed. I just do create directories with that name and then save the files inside the directory.
[b][url=http://lazy-puppy.weebly.com]LazY Puppy[/url][/b]
[b][url=http://rshs-dna.weebly.com]RSH's DNA[/url][/b]
[url=http://murga-linux.com/puppy/viewtopic.php?t=91422][b]SARA B.[/b][/url]
[b][url=http://rshs-dna.weebly.com]RSH's DNA[/url][/b]
[url=http://murga-linux.com/puppy/viewtopic.php?t=91422][b]SARA B.[/b][/url]