如何使用CLI中的其他命令中的其他命令访问文件

发布于 2025-02-08 07:08:48 字数 330 浏览 1 评论 0原文

我想在大型文件上使用AWS CLI的一些命令,这些命令存储在S3存储桶中,而无需将文件复制到本地目录 (我熟悉AWS cp 命令,这不是我想要的)。

例如,假设我想使用一个简单的bash命令,例如“ head”或“更多”。 如果我尝试这样使用它:

head s3://bucketname/file.txt

但随后我得到:

head:bear s3://bucketname/file.txt'for阅读:没有这样的文件或目录 我还能怎么做?

我还能怎么做?

提前致谢。

I want to use some commands with the aws cli on large files that are stored in a s3 bucket without copying the files to the local directory
(I'm familiar with the aws cp command, it's not what I want).

For example, let's say I want to use a simple bash commands like "head" or "more".
If I try to use it like this:

head s3://bucketname/file.txt

but then I get:

head: cannot open ‘s3://bucketname/file.txt’ for reading: No such file or directory
How else can I do it?

How else can I do it?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寂寞陪衬 2025-02-15 07:08:48

命令是否能够通过S3存储键访问文件是否完全取决于命令。在引擎盖下,每个命令只是一个程序。当您运行Head FileName之类的内容时,参数fileName将作为参数传递给Head Command的Main()函数。您可以在此处查看源代码: https://github.com /coreutils/coreutils/blob/master/src/head.c

本质上,由于Head命令不支持S3 URI,因此您无法执行此操作。您可以:

  1. 将S3文件复制到STDOUT,然后将其输送到头:AWS S3 CP Fileanme - |头。如果文件对于管道缓冲区来说太大,这似乎不是可能的选项。
  2. 使用s3curl复制一个字节范围:如何使用CLI 中的其他命令中的命令中的命令中的文件访问文件

Wether a command will be able to access a file over s3 bucket or not depends entirely on the command. Under the hood, every command is just a program. When you run something like head filename, the argument filename is passed as an argument to the head command's main() function. You can check out the source code here: https://github.com/coreutils/coreutils/blob/master/src/head.c

Essentially, since the head command does not support S3 URIs, you cannot do this. You can either:

  1. Copy the s3 file to stdout and then pipe it to head: aws s3 cp fileanme - | head. This doesn't seem the likely option if file is too big for the pipe buffer.
  2. Use s3curl to copy a range of bytes: how to access files in s3 bucket for other commands using cli
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文