Last Update 2014/03/11
ファイルやディレクトリを移動します。
mv オプション1 ファイルパス1 ファイルパス2
mv オプション1 ファイルパス1 ... ディレクトリ
オプション1(任意)
-f, --force
ファイルパス2のファイルが既に存在し、開く事ができない場合、削除してから再実行する
-i, --interactive
ファイルパス2のファイルが既に存在する場合に、対話形式で確認する
ファイルパス1(必須)
移動元ファイル(ディレクトリ)
ファイルパス2(必須)
移動先ファイル(ディレクトリ)
ディレクトリ(必須)
移動先ディレクトリ
※ オプションなどは個人的に重要と考えられるものを記述しており、記載の無いものは、manページや関連書籍などを参照願います。
※ 実行例の記述は、不要と考えられる部分の削除などの修正を行ったものを掲載しています。
※ 実行例の実行環境はUbuntu 12.10です。
※ 実行例の記述は、不要と考えられる部分の削除などの修正を行ったものを掲載しています。
※ 実行例の実行環境はUbuntu 12.10です。
(例) オプション無し 移動先ファイル名指定無し
$ mv testdir1/test.txt testdir2/
実行前
$ ls -l testdir1
total 4
-rw-r--r-- 1 ******* ******* 5 Dec 16 20:39 test.txt
$ ls -l testdir2
total 0
実行後
$ ls -l testdir1
total 0
$ ls -l testdir2
total 4
-rw-r--r-- 1 ******* ******* 5 Dec 16 20:39 test.txt
(例) オプション無し 移動先ファイル名指定有り
$ mv testdir1/test.txt testdir2/test_move.txt
実行前
$ ls -l testdir1
total 4
-rw-r--r-- 1 ******* ******* 5 Dec 16 20:39 test.txt
$ ls -l testdir2
total 0
実行後
$ ls -l testdir1
total 0
$ ls -l testdir2
total 4
-rw-r--r-- 1 ******* ******* 5 Dec 16 20:39 test_move.txt
$ mv -f testdir1/test.txt testdir2/test.txt
実行前
$ ls -l testdir1
total 4
-rw-r--r-- 1 ******* ******* 5 Dec 17 23:42 test.txt
$ ls -l testdir2
total 4
-r--r--r-- 1 ******* ******* 10 Dec 17 23:03 test.txt ← 書き込み不可
実行後
$ ls -l testdir1
total 0
$ ls -l testdir2
total 4
-rw-r--r-- 1 ******* ******* 5 Dec 17 23:42 test.txt ← コピー元ファイルを上書き
$ mv -i testdir1/test.txt testdir2/test.txt
実行前
$ ls -l testdir1
total 4
-rw-r--r-- 1 ******* ******* 5 Dec 18 11:18 test.txt
$ ls -l testdir2
total 4
-r--r--r-- 1 ******* ******* 10 Dec 18 11:19 test.txt ← 書き込み不可
確認メッセージ
mv: try to overwrite `testdir2/test.txt', overriding mode 0444 (r--r--r--)?
実行後(確認メッセージで「y」を入力)
mv: try to overwrite `testdir2/test.txt', overriding mode 0444 (r--r--r--)? y ← 「y」を入力
$ ls -l testdir1
total 0
$ ls -l testdir2
total 4
-rw-r--r-- 1 ******* ******* 5 Dec 18 11:18 test.txt ← 移動元ファイルを上書き