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