Windows provides very featureful command which is used to copy files can take backups named xcopy
. Xcopy can be used copy files from one partition to other partition or a usb drive. Xcopy also supports incremental backup which create advantages while taking backups. We will look different usage examples of xcopy in this tutorial.
Windows提供了非常有用的命令,该命令用于复制文件,可以进行名为xcopy
备份。 可以使用Xcopy将文件从一个分区复制到另一分区或USB驱动器。 Xcopy还支持增量备份,这在进行备份时具有优势。 在本教程中,我们将查看xcopy的不同用法示例。
帮帮我 (Help)
Detailed help about xcopy command can be show with /?
option like below.
可以使用/?
显示有关xcopy命令的详细帮助/?
如下所示的选项。
$ xcopy /?
复制档案(Copy Files)
One of the most used type of xcopy is providing no option and just copying files from source path to the destination file. In this example we will provide source file named systeminfo.txt
to the Downloads
directory.
xcopy最常用的一种类型是不提供任何选项,而只是将文件从源路径复制到目标文件。 在此示例中,我们将向Downloads
目录提供名为systeminfo.txt
源文件。
$ xcopy systeminfo.txt Downloads
忽略错误(Ignore Errors)
While copying files there may some errors related permission, corrupt data, changed data etc. These will create errors and these error will be printed to the terminal by default and these errors can be interrupt the copy operation. These errors can be ignored with /c
option.
在复制文件时,可能会出现一些与权限有关的错误,数据损坏,数据更改等。这些都会创建错误,并且默认情况下会将这些错误打印到终端,并且这些错误可能会中断复制操作。 使用/c
选项可以忽略这些错误。
$ xcopy /c systeminfo.txt Downloads
使用日期和时间戳备份数据 (Backup Data Using Date and Time Stamp)
One of the very useful feature is copying files according to their date and time stamp. While we are making backups regularly we can specify time which files those are changed specified time to backup. For example we take backup in following periodic dates.
非常有用的功能之一是根据文件的日期和时间戳复制文件。 当我们定期进行备份时,我们可以指定更改文件的时间和指定的备份时间。 例如,我们在以下定期日期进行备份。
- 01-04-2017 2017年1月4日
- 08-04-20172017年08月04日
- 15-04-201715-04-2017
- … …
We can specify date where we will only copy files changed after that time. In this example only files those changed after 15-04-2017 will be copied.
我们可以指定仅复制该时间之后更改的文件的日期。 在此示例中,仅复制在15-04-2017之后更改的文件。
$ xcopy \project \project-backup /d:15-04-2017
详细操作 (Verbose Operation)
Other useful feature is printing files during copy operation. This will give us feedback about the copy operation. We will use /f
option for this.
其他有用的功能是在复制操作期间打印文件。 这将为我们提供有关复制操作的反馈。 我们将使用/f
选项。
$ xcopy /f Downloads Downloads-backup
仅复制现有目标文件(Copy Only Files Existing Destination)
While copying files from source to the destination we can set a rule which will only copy the files existing in remote destination.
在将文件从源复制到目标时,我们可以设置一条规则,该规则将仅复制远程目标中存在的文件。
$ xcopy /u Downloads Downloads-backup
复制隐藏文件和系统文件 (Copy Hidden and System Files)
Windows have different type of files attributed like System
and Hidden
. These files especially used by operating system or related applications. These files are not copied by default. In order to copy these type of files we will provide /h
Windows具有不同类型的文件,例如System
和Hidden
。 这些文件特别由操作系统或相关应用程序使用。 默认情况下,不会复制这些文件。 为了复制这些类型的文件,我们将提供/h
$ xcopy /h Downloads Downloads-backup
排除文件和扩展名进行复制 ( Exclude Files and Extension For Copy)
While copying we may need to not copy some file names or extensions. For example a developer do not want to copy binary or temporary files. So we need to exclude these type of files and file names. We will create a file which stores file names and extensions line by line those will be excluded. We have a file ex.txt
which have following contents.
复制时,我们可能不需要复制某些文件名或扩展名。 例如,开发人员不想复制二进制或临时文件。 因此,我们需要排除这些类型的文件和文件名。 我们将创建一个文件,逐行存储将被排除的文件名和扩展名。 我们有一个文件ex.txt
,其中包含以下内容。
.exe
temp
We want to exclude .exe
and temp
file names and extensions
我们要排除.exe
和temp
文件的名称和扩展名
$ xcopy /exclude:ex.txt Downloads Downloads-backup
翻译自: https://www.poftut.com/copy-files-backup-xcopy-windows/