Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the skills of dealing with common problems in Linux system

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

What are the skills of dealing with common problems in Linux system? I believe many inexperienced people are at a loss about this. Therefore, this paper summarizes the causes and solutions of the problems. Through this article, I hope you can solve this problem.

For Linux developers, text processing needs to be done every day, so it is important to master text processing commands and skills skillfully.

Background

I have a lot of Docker images on my developer machine, and now I need to delete those named none:

$docker images

How to operate it? Is it possible to delete them one by one by hand?

Docker image rm f0fa889be9e8 imagine, if there are hundreds of such images to be deleted, how many years and months do you want to get them? But how can it be improved?

Text filtering

Consider filtering the image named none from the results, and the grep command can be done:

$docker images | grep none

Field extraction

Next, extract the container ID column, which is pediatric for awk:

$docker images | grep none | awk'{print $3}'

Of course, you can get the same result by segmenting fields with the cut command. Because cut can only be segmented by a single character, and there are multiple spaces in the original text, text replacement is required first.

Text substitution

Text substitution is what the sed command is good at. Replace one or more spaces with one:

$docker images | grep none | sed's / * / / g'

Text segmentation

Next, use the cut command to split the result further and fetch the third field:

$docker images | grep none | sed's / * / / g' | cut-d''- f 3

Yes, we got the same result as using the awk command.

Batch deletion

Next, delete the images in batch via xargs:

$docker images | grep none | awk'{print $3}'| xargs docker image rm

In this example, xargs will eventually execute the following command:

$docker image rm f0fa889be9e8 257954316455 99739acbfe7a 52b10754a70c 86878eefdd39 see, all unwanted images have been deleted, and only one operation is needed:

$docker images

The following operation is also equivalent:

$docker images | grep none | sed's / * / / g' | cut-d'- f 3 | after reading the above, have you mastered the skills of dealing with common problems in Linux system? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report