Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keeping a copy of a file in a same directory [closed]

Tags:

linux

I am working on linux scripts , Assume that the directory is consisting of these following scripts .

ls *.sh

test.sh 
MyScripts.sh 

My question is , before making any modifications to test.sh script , i want to keep a backup copy of it , so that if anything messes up , i will be not screwed up . please tell me how can i keep a copy of test.sh in the same directory ?? before making any modifications to the actual file test.sh .

Thank you very much .

like image 589
user974802 Avatar asked Oct 10 '11 15:10

user974802


People also ask

How to create a copy of a file in a different directory?

How to: Create a Copy of a File in a Different Directory in Visual Basic. The My.Computer.FileSystem.CopyFile method allows you to copy files. Its parameters provide the ability to overwrite existing files, rename the file, show the progress of the operation, and allow the user to cancel the operation.

How do I use CopyFile?

The following code examples demonstrate how to use CopyFile. ' Copy the file to a new location without overwriting existing file. My.Computer.FileSystem.CopyFile ( "C:\UserFiles\TestFiles estFile.txt", "C:\UserFiles\TestFiles2 estFile.txt") ' Copy the file to a new folder, overwriting existing file.

How do I copy a text file to another folder?

To copy a text file to another folder. Use the CopyFile method to copy a file, specifying a source file and the target directory. The overwrite parameter allows you to specify whether or not to overwrite existing files. The following code examples demonstrate how to use CopyFile. ' Copy the file to a new location without overwriting existing file.

How do I copy a file without overwriting it?

Use the CopyFile method to copy a file, specifying a source file and the target directory. The overwrite parameter allows you to specify whether or not to overwrite existing files. The following code examples demonstrate how to use CopyFile. VB. ' Copy the file to a new location without overwriting existing file.


2 Answers

Consider using revision control, such as git or Subversion.

You can make a copy before your work too:

cp test.sh test.sh.orig
like image 72
gpojd Avatar answered Sep 20 '22 08:09

gpojd


The usual approach is to

 cp test.sh test.sh~

(or test.sh.bck or whatever naming convention). In fact, any decent editor should have an option to do this automatically for you. Vim does it by default (saves a backup name filename~ on modification)

May I heartily suggest a version control solution for this purpose instead?

Good 'starter' options include:

  • bazaar
  • mercurial

I personally vouch for git.

I took care to name (D)VCS methods that have ample interoperability options so as to prevent data lockin.

like image 30
sehe Avatar answered Sep 21 '22 08:09

sehe