如何通过 * 将包括隐藏文件在内的所有文件移动到父目录中 [英] How to move all files including hidden files into parent directory via *

查看:16
本文介绍了如何通过 * 将包括隐藏文件在内的所有文件移动到父目录中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这一定是一个热门问题,但我找不到答案.

Its must be a popular question but I could not find an answer.

如何通过 * 移动所有文件,包括隐藏文件以及像这样的父目录:

How to move all files via * including hidden files as well to parent directory like this:

mv /path/subfolder/* /path/

这将像预期的那样将所有文件移动到父目录,但不会移动隐藏文件.该怎么做?

This will move all files to parent directory like expected but will not move hidden files. How to do that?

推荐答案

您可以在 UNIX &Linux 对如何将所有文件(包括隐藏文件)从一个目录移动到另一个目录的回答?.它展示了 Bash、zsh、ksh93、标准 (POSIX) sh 等中的解决方案.

You can find a comprehensive set of solutions on this in UNIX & Linux's answer to How do you move all files (including hidden) from one directory to another?. It shows solutions in Bash, zsh, ksh93, standard (POSIX) sh, etc.

您可以同时使用这两个命令:

You can use these two commands together:

mv /path/subfolder/* /path/   # your current approach
mv /path/subfolder/.* /path/  # this one for hidden files

或一起(感谢 pfnuesel):

mv /path/subfolder/{.,}* /path/

扩展为:

mv /path/subfolder/* /path/subfolder/.* /path/

(示例:echo a{.,}b 扩展为 a.b ab)

请注意,这将显示几个警告:

Note this will show a couple of warnings:

mv: cannot move ‘/path/subfolder/.’ to /path/.’: Device or resource busy
mv: cannot remove /path/subfolder/..’: Is a directory

忽略它们:这是因为 /path/subfolder/{.,}* 也扩展为 /path/subfolder/./path/subfolder/..,分别是目录和父目录(见."和.."是什么意思什么时候在文件夹中?).

Just ignore them: this happens because /path/subfolder/{.,}* also expands to /path/subfolder/. and /path/subfolder/.., which are the directory and the parent directory (See What do "." and ".." mean when in a folder?).

如果你只想复制,你可以使用一个:

If you want to just copy, you can use a mere:

cp -r /path/subfolder/. /path/
#                     ^
#                     note the dot!

这将复制所有文件,包括普通文件和隐藏文件,因为 /path/subfolder/. 扩展为此目录中的所有内容"(来源:如何用cp复制包含隐藏文件和隐藏目录及其内容?)

This will copy all files, both normal and hidden ones, since /path/subfolder/. expands to "everything from this directory" (Source: How to copy with cp to include hidden files and hidden directories and their contents?)

这篇关于如何通过 * 将包括隐藏文件在内的所有文件移动到父目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆