awk使用示例
程序员文章站
2022-04-30 14:46:41
...
awk使用示例
一、场景示例
使用docker命令查询出指定的docker镜像然后删除
镜像如下
➜ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
119.23.231.80/town-test/config latest 589f5f9614f1 27 hours ago 552MB
aaa latest 589f5f9614f1 27 hours ago 552MB
119.23.231.80/town_test/config latest bac4554361d7 27 hours ago 552MB
redmine latest 887149aec1cd 2 weeks ago 663MB
kingboy/redis 4 c5355f8853e4 4 weeks ago 107MB
kingboy/nginx 1.13 7f70b30f2cc6 5 weeks ago 109MB
119.23.231.80/library/openjdk 8-jre 1b56aa0fd38c 5 weeks ago 527MB
kingboy/openjdk 8-jre 1b56aa0fd38c 5 weeks ago 527MB
kingboy/rabbitmq 3.7-management df0ee1f2343b 6 weeks ago 151MB
kingboy/mysql 5.6 079344ce5ebd 6 weeks ago 256MB
kingboy/zookeeper 3.5 21141b14d33e 3 months ago 127MB
二、删除指定镜像
删除所有名字包含119.23.231.80的镜像,
docker删除命令为docker rmi REPOSITORY:TAG
首先查询出所有符合条件的镜像
docker images|grep 119.23.231.80
在这基础上使用awk命令将repository和tag使用冒号拼接
docker images|grep 119.23.231.80|awk '{print $1":"$2}'
然后删除之
docker images|grep 119.23.231.80|awk '{print $1":"$2}'|xargs docker rmi