Linux 将文件的副本保存在同一目录中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7714764/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 06:35:26  来源:igfitidea点击:

Keeping a copy of a file in a same directory

linux

提问by user974802

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

我正在处理 linux 脚本,假设该目录由以下这些脚本组成。

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 .

我的问题是,在对 test.sh 脚本进行任何修改之前,我想保留它的备份副本,这样如果出现任何问题,我就不会被搞砸。请告诉我如何将 test.sh 的副本保存在同一目录中?在对实际文件 test.sh 进行任何修改之前。

Thank you very much .

非常感谢 。

采纳答案by gpojd

Consider using revision control, such as gitor Subversion.

考虑使用修订控制,例如gitSubversion

You can make a copy before your work too:

您也可以在工作前复印一份:

cp test.sh test.sh.orig

回答by sehe

The usual approach is to

通常的做法是

 cp test.sh test.sh~

(or test.sh.bckor 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)

(或test.sh.bck任何命名约定)。事实上,任何体面的编辑器都应该有一个选项可以为您自动执行此操作。Vim 默认这样做(在修改时保存备份名称 filename~)

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

我可以衷心地为此目的建议一个版本控制解决方案吗?

Good 'starter' options include:

好的“入门”选项包括:

  • bazaar
  • mercurial
  • 市场
  • 水银的

I personally vouch for git.

我个人担保git

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

我小心地命名了具有充足互操作性选项的 (D)VCS 方法,以防止数据锁定。

回答by chown

cp test.sh test.sh.`date +"%m_%d_%Y"`

Will make a timestamped backup named test.sh.10_10_2011

将制作一个带时间戳的备份,名为 test.sh.10_10_2011