AliyunCLI支持使用filter参数对指令返回的结果进行过滤输出。从开放API调用返回数据, 默认采用Json格式,所以用户在使用AliyunCLI时, 可以根据Json的特点, 使用过滤功能直接获取所需子节点数据。
下面举例说明:
原始数据:
# aliyuncli ecs DescribeImages --ImageOwnerAlias system --output json --PageSize 1 --PageNumber 1 { "PageSize": 1, "RegionId": "cn-hangzhou", "TotalCount": 39, "PageNumber": 1, "RequestId": "A0F91B21-BD8D-48D9-9EC8-36FB7E1D387E", "Images": { "Image": [ { "Status": "Available", "ProductCode": "", "Platform": "Freebsd", "Description": "freebsd1001_64_20G_aliaegis_20150527.vhd", "IsCopied": false, "Tags": { "Tag": [] }, "IsSubscribed": false, "IsSelfShared": "", "CreationTime": "2015-06-19T10:45:56Z", "OSName": "FreeBSD 10.1 64\u4f4d", "DiskDeviceMappings": { "DiskDeviceMapping": [ { "Format": "", "ImportOSSBucket": "", "Device": "/dev/xvda", "SnapshotId": "", "ImportOSSObject": "", "Size": "20" } ] }, "ImageId": "freebsd1001_64_20G_aliaegis_20150527.vhd", "Usage": "instance", "ImageName": "freebsd1001_64_20G_aliaegis_20150527.vhd", "Architecture": "x86_64", "ImageOwnerAlias": "system", "OSType": "linux", "Progress": "100%", "ImageVersion": "1.0.0", "Size": 20 } ] } } |
# aliyuncli ecs DescribeImages --ImageOwnerAlias system --output json --PageSize 1 --PageNumber 1 --filter TotalCount 39 |
# aliyuncli ecs DescribeImages --ImageOwnerAlias system --output json --PageSize 1 --PageNumber 1 --filter Images { "Image": [ { "Status": "Available", "ProductCode": "", "Platform": "Freebsd", "Description": "freebsd1001_64_20G_aliaegis_20150527.vhd", "IsCopied": false, "Tags": { "Tag": [] }, "IsSubscribed": false, "IsSelfShared": "", "CreationTime": "2015-06-19T10:45:56Z", "OSName": "FreeBSD 10.1 64\u4f4d", "DiskDeviceMappings": { "DiskDeviceMapping": [ { "Format": "", "ImportOSSBucket": "", "Device": "/dev/xvda", "SnapshotId": "", "ImportOSSObject": "", "Size": "20" } ] }, "ImageId": "freebsd1001_64_20G_aliaegis_20150527.vhd", "Usage": "instance", "ImageName": "freebsd1001_64_20G_aliaegis_20150527.vhd", "Architecture": "x86_64", "ImageOwnerAlias": "system", "OSType": "linux", "Progress": "100%", "ImageVersion": "1.0.0", "Size": 20 } ] } |
# aliyuncli ecs DescribeImages --ImageOwnerAlias system --output json --PageSize 1 --PageNumber 1 --filter Images.Image[0] { "Status": "Available", "ProductCode": "", "Platform": "Freebsd", "Description": "freebsd1001_64_20G_aliaegis_20150527.vhd", "IsCopied": false, "Tags": { "Tag": [] }, "IsSubscribed": false, "IsSelfShared": "", "CreationTime": "2015-06-19T10:45:56Z", "OSName": "FreeBSD 10.1 64\u4f4d", "DiskDeviceMappings": { "DiskDeviceMapping": [ { "Format": "", "ImportOSSBucket": "", "Device": "/dev/xvda", "SnapshotId": "", "ImportOSSObject": "", "Size": "20" } ] }, "ImageId": "freebsd1001_64_20G_aliaegis_20150527.vhd", "Usage": "instance", "ImageName": "freebsd1001_64_20G_aliaegis_20150527.vhd", "Architecture": "x86_64", "ImageOwnerAlias": "system", "OSType": "linux", "Progress": "100%", "ImageVersion": "1.0.0", "Size": 20 } |
# aliyuncli ecs DescribeImages --ImageOwnerAlias system --output json --PageSize 1 --PageNumber 1 --filter Images.Image[0].ImageId "freebsd1001_64_20G_aliaegis_20150527.vhd" |
# aliyuncli ecs DescribeImages --ImageOwnerAlias system --output json --PageSize 1 --PageNumber 1 --filter Images.Image[*].ImageId [ "freebsd1001_64_20G_aliaegis_20150527.vhd" ] |
# aliyuncli ecs DescribeImages --ImageOwnerAlias system --output json --PageSize 1 --PageNumber 1 --filter Images.Image[0].DiskDeviceMappings.DiskDeviceMapping[0].Device "/dev/xvda" |
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。