Go to main content

マニュアルページ セクション 1: ユーザーコマンド

印刷ビューの終了

更新: 2022年7月27日
 
 

mv(1)

名前

mv - move files

形式

/usr/bin/mv [-finu] source target_file
/usr/bin/mv [-finu] source... target_dir
/usr/xpg4/bin/mv [-finu] source target_file
/usr/xpg4/bin/mv [-finu] source... target_dir

説明

In the first synopsis form, the mv utility moves the file named by the source operand to the destination specified by the target_file. source and target_file can not have the same name.If target_file does not exist, mv creates a file named target_file.target_file が存在していれば、その内容は上書きされます。最終オペランドが既存のディレクトリを示していないとき、mv はこの第 1 形式であると見なします。

第 2 の形式の mv は、 source オペランドで指定された各ファイルを target_dir オペランドが示す既存ディレクトリ中のファイルに移動します。各 source 用の宛先パス名は、宛先ディレクトリ名のあとにスラッシュ (/) と source の最終パス名部分を付加したものとなります。オペランドが既存のディレクトリを示しているとき、mv はこの第 2 形式であると見なします。

mv は、target_file のモードが書き込み禁止であると判断すると、モードを表示し (chmod(2) を参照)、応答を要求して、標準入力を 1 行読み取ります。If the response is affirmative, the mv occurs, if permissible; otherwise, the command exits.Notice that the mode displayed can not fully represent the access permission if target is associated with an ACL.source の親ディレクトリが書き込み可能でスティッキ・ビットセットを持っている場合、次の条件のうち 1 つ以上が真である必要があります。

  • ユーザーはファイルを所有している必要がある

  • ユーザーはディレクトリを所有している必要がある

  • ファイルはユーザーが書き込み可能である必要がある

  • ユーザーは特権ユーザーである必要がある

If source is a file and target_file is a link to another file with links, the other links remain and target_file becomes a new file.

If source and target_file/target_dir are on different file systems, mv copies the source and deletes the original.Any hard links to other files are lost. mv attempts to duplicate the source file characteristics to the target, that is, the owner and group id, permission modes, modification and access times, ACLs, and extended attributes, if applicable.シンボリックリンクに対しては、mv はリンク自体の所有者 ID やグループ ID だけを保存します。

If unable to preserve owner and group id, mv clears S_ISUID and S_ISGID bits in the target. mv prints a diagnostic message to stderr if unable to clear these bits, though the exit code is not affected. mv might be unable to preserve extended attributes if the target file system does not have extended attribute support. /usr/xpg4/bin/mv prints a diagnostic message to stderr for all other failed attempts to duplicate file characteristics.終了コードには影響しません。

ソースファイルの特性を保存するには、ユーザーが適切なファイルのアクセス権を持っている必要があります。This includes having the {PRIV_FILE_CHOWN}, {PRIV_FILE_OWNER}, and {PRIV_FILE_SETID} privileges; or having the same owner id as the destination file.

オプション

サポートしているオプションは、次のとおりです。

–f

mv は、既存の target に書き込む場合でもプロンプトを出さずにファイルを移動します。標準入力が端末でない場合これがデフォルトになることに注意してください。

–i

mv は、移動により既存の target が上書きされる場合は、必ず、確認のプロンプトを出します。これは、入力が端末から送られているかどうかに関係なく実行されます。確認のプロンプトでエラーが発生した場合は、ユーザーによる否定応答と同等です。肯定を応答すれば、移動処理は続行されます。その他の応答では、mvtarget を上書きしません。

–n

mv does not overwrite an existing target.

–u

mv moves the file only when the target is older than the source file or when the target is missing.

/usr/bin/mv

–f–i のオプションを両方指定してもエラーとは見なされません。The –f option overrides the –i, –n, and –u options.The –i option overrides the –n and –u options.The –n option overrides the –u option.

/usr/xpg4/bin/mv

–f–i のオプションを両方指定してもエラーとは見なされません。最後に指定したオプションが mv の動作を決定します。

オペランド

次のオペランドがサポートされています。

source

移動するファイルまたはディレクトリのパス名

target_file

移動するファイルまたはディレクトリの新たなパス名

target_dir

ファイルの移動先となる既存ディレクトリのパス名

環境変数

See environ(7) for descriptions of the following environment variables that affect the execution of mv: LANG, LC_ALL, LC_COLLATE, LC_CTYPE, LC_MESSAGES, and NLSPATH.

肯定応答は、ユーザーのロケールの LC_MESSAGES カテゴリの yesexpr キーワードで定義されている拡張正規表現を使用して処理されます。LC_COLLATE カテゴリに指定されているロケールは、yesexpr に定義されている式に使用される範囲、同等クラス、および複数文字照合要素の動作を定義します。LC_CTYPE に指定されているロケールは、テキストデータのバイト列を文字として解釈するロケールや、yesexpr に定義されている式に使用される文字クラスの動作を定義します。locale(7) を参照してください。

終了ステータス

次の終了ステータスが返されます。

0

入力ファイルはすべて正常に移されました。

>0

エラーが発生しました。

属性

属性についての詳細は、マニュアルページの attributes(7) を参照してください。

/usr/bin/mv

属性タイプ
属性値
使用条件
system/core-os
CSI
有効
インタフェースの安定性
確実

/usr/xpg4/bin/mv

属性タイプ
属性値
使用条件
system/xopen/xcu4
CSI
有効
インタフェースの安定性
標準

関連項目

cp(1), cpio(1), ln(1), rm(1), chmod(2), attributes(7), environ(7), fsattr(7), privileges(7), standards(7)

-- によって、ユーザーはコマンド行オプションの終端を明示的にマーク付けできるので、mv- で始まるファイル名引数を認識できるようになります。As an aid to BSD migration, mv accepts - as a synonym for --.この導入補助は、将来のリリースでは提供されない可能性があります。

History

Support for the –n and –u options was added to the mv command in Oracle Solaris 11.4.30.

The /usr/xpg4/bin/mv command was added in the Solaris 2.5 release.

The mv command, with support for the –f and –i options, has been present in all Sun and Oracle releases of Solaris.