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

How to use the shell programming command xargs

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

Share

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

This article shows you how to use the shell programming command xargs, which is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

First, before you say the xargs command, talk about what shell programming is.

What is shell programming? to put it bluntly, it is to organize all kinds of commands according to certain rules and accomplish certain things. It's purely personal understanding, . Whether it is interactive shell or non-interactive shell, it is made up of commands.

So orders are important. Xargs is one of them, and it is also a very important command. Why is it important because it can be used in conjunction with other commands to pass the output of one command as an argument to another command. The exec in this root find command parameter is very similar, but different: the following four points are found on the Internet. The first point is personal experience. I use arch linux at home. When you send a lot of data to the following commands through exec, where will it get stuck? others have not been tried. If you are interested, you can compare their speed.

[zhangy@BlackGhost music] $time find / home/zhangy/download/-name ".gz"-printreal 0m0.053suser 0m0.003ssys 0m0.003s

1. When you use the exec option of find to process the matching options, find passes the matching parameters to exec for execution at one time. However, some systems have a limit on the length of parameters passed by exec, so that an overflow will be reported a few minutes after the execution of the find command, and the error message is usually "parameter column is too long" or "parameter column overflow".

2when find is used with the find command, find passes the matching command to xargs, and xargs only gets part of the file at a time, not all of it. Batch processing.

3, using the exec option, each matching file processing will be assigned a process, instead of executing the matched file as a parameter at one time, which will trigger multiple processes, which will degrade the system performance and affect the processing efficiency.

4 xargs has only one process, but whether it is processed in batches and batch size will also be affected by some adjustable parameters of the system.

Second, an example of xargs application

1. Find the file and change the user to which the file belongs

# will change the file user starting with test in the current directory to zhangy [root@BlackGhost download] # find. -name "test*"-print | xargs chown zhangy:users# to view the file that begins with test in the current directory belongs to the user [root@BlackGhost download] # find. -name "test*"-print-exec ls-al {}\;. / test.sql.zip-rw-r--r-- 1 zhangy users 1981 Feb 2 16:05. / test.sql.zip./test.zip-rw-r--r-- 1 zhangy users 16 May 23 22:54. / test.zip

2. Count the users of the system.

[zhangy@BlackGhost download] # cut-d:-F1

< /etc/passwd | xargs echo >

> / home/zhangy/userlist.txt

3. Back up files

[zhangy@BlackGhost ddd] $ls | xargs-I cp {} {}. Bakcp test test.bak the above is how to use shell programming commands xargs. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

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

Servers

Wechat

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

12
Report