如何使用mv命令在Linux中移动文件夹
时间:2020-01-09 10:42:41 来源:igfitidea点击:
如何使用bash命令行选项在BSD/Linux/Apple OX或者Unix操作系统中移动文件夹?
您需要使用mv命令在Linux终端中移动文件夹,文件和目录。
语法如下所示:mv源目标mv文件夹1文件夹2目标mv文件夹1文件1目标mv -option源目标下面的示例将不更改名称的名为document的文件夹从当前目录移动到当前目录的现有子目录名为/backups的目录:
mv documents /backups
mv命令可用于在单个命令中移动任意数量的文件和文件夹。
在此示例中,以下命令将所有文件夹(包括这些目录的所有内容)从当前目录移动到名为/nas03/users/home/v/Hyman的目录
mv * /nas03/users/home/v/Hyman
请注意,星号是通配符,代表当前目录中的所有文件和文件夹。
在下一个示例中,仅将foo和bar文件夹从/home/tom目录移动到名为/home/jerry的目录:
mv /home/tom/foo /home/tom/bar /home/jerry
或者
cd /home/tom mv foo bar /home/jerry
mv可以看到解释使用-v选项的操作,即在移动文件之前显示每个文件的名称:
mv -v /home/tom/foo /home/tom/bar /home/jerry
输出示例:
`/home/tom/foo/' -> `/home/jerry/foo' `/home/tom/bar/' -> `/home/jerry/bar'
如果目标目录中已经存在相同名称的文件/文件夹,则可以在覆盖之前提示提示,即通过-i选项使mv具有交互性:
mv -i foo /tmp
输出示例:
mv: overwrite `/tmp/foo'?
其他选项
--backup[=CONTROL]
make a backup of each existing destination file
-b like --backup but does not accept an argument
-f, --force
do not prompt before overwriting
-n, --no-clobber
do not overwrite an existing file
If you specify more than one of -i, -f, -n, only the final one takes effect.
--strip-trailing-slashes
remove any trailing slashes from each SOURCE argument
-S, --suffix=SUFFIX
override the usual backup suffix
-t, --target-directory=DIRECTORY
move all SOURCE arguments into DIRECTORY
-T, --no-target-directory
treat DEST as a normal file
-u, --update
move only when the SOURCE file is newer than the destination file or when the destination file is missing

