LoginSignup
5
5

More than 5 years have passed since last update.

rsyncみたいなwindowsのコマンド

Last updated at Posted at 2018-04-01

xcopyの基本的な使い方

Linuxでrsyncを使うと、以前にコピーしたときから変更がないファイルはそのままで、変更されたファイルと新しいファイルだけコピーしてくれて便利ですよね。私は、別のディスクのバックアップを取りたいときに使っています。

windowsでも同じようなコマンドが使いたいときは、xcopyを使いましょう。

バッチファイルの例を下に示します。

do_xcopy.bat
xcopy "Y:\userLinux\hnishi\work3\hnishi\kek9\kekex"  "G:\work3\hnishi\kek9\kekex" /e /d /h /r /y 

*バッチファイルの名前は、"xcopy.bat"としないようにしましょう。xcopyという、既存のコマンド名と競合して、動きません。

以下、xcopyコマンドのオプションの説明です。

:: /E Copy folders and subfolders, including Empty folders.
:: can be used to modify /T.
:: /D:mm-dd-yyyy
:: Copy files changed on or after the specified date.
:: If no date is given, copy only files whose
:: source date/time is newer than the destination time.
:: /H Copy hidden and system files and folders (default=N)
:: /R Overwrite read-only files.
:: /Y Suppress prompt to confirm overwriting a file.
:: can be preset in the COPYCMD env variable.

同じようなので、robocopyというものもあります。
"Robust File Copy"という意味らしいです。

除外リスト

特定の拡張子を持ったファイルはコピーしたくないというときには、/EXCLUDEオプションを使いましょう。

do_xcopy.bat
xcopy "Y:\userLinux\hnishi\work3\hnishi\kek9\kekex"  "G:\work3\hnishi\kek9\kekex" /e /d /h /r /y /EXCLUDE:list_xcopy_exclude.txt 

下記のように、テキストファイルを作って、オプションの引数にファイル名を指定してください。

list_xcopy_exclude.txt
.xtc
.trr
.tar.gz
.tar.z

参考

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5