“head” command for aws s3 to view file contents

前端 未结 8 1300
不知归路
不知归路 2021-02-06 22:44

On Linux, we generally use the head/tail commands to preview the contents of a file. It helps in viewing a part of the file (to inspect the format for instance), rather than ope

8条回答
  •  醉酒成梦
    2021-02-06 23:22

    As others have answered, assuming the file is large, use get-object command with --range bytes=0-1000 to download only part of the file.

    example:
    aws s3api get-object --profile opsrep --region eu-west-1 --bucket --key

    --range bytes=0-10000 "OUTPUT.csv" docs

    As of 2018 you can now run SELECT Queries in AWS CLI. Use LIMIT 10 to preview the "head" of your file.

    example:
    aws s3api select-object-content --bucket --key

    --expression "select * from s3object limit 10" --expression-type "SQL" --input-serialization "CSV={}" --output-serialization "CSV={}" "OUTPUT.csv" docs

    Now you can quickly run head OUTPUT.csv on the small local file

提交回复
热议问题