你如何在bash中获取目录中的第一个文件?首先是 shell glob 首先找到的内容。
我在 bash 中搜索目录中的第一个文件,这让我看到了一个带有非常具体要求的旧帖子。我想为后代记录我对一般问题的解决方案,并为人们提供一个放置他们想要分享的替代解决方案的地方。
如果我有这棵树:
.
??? child
??? dir1
??? dir2
??? dir3
??? file1
??? file2
??? file3
Run Code Online (Sandbox Code Playgroud)
这是在以下范围内发出这些命令的结果child
: 这可以工作并复制所有文件和目录:
.
??? child
??? dir1
??? dir2
??? dir3
??? file1
??? file2
??? file3
Run Code Online (Sandbox Code Playgroud)
这仅复制child
和文件,但不复制任何目录:
cp -r ../* .
----
cp: cannot copy a directory, '../child', into itself, './child'
Run Code Online (Sandbox Code Playgroud)