The find command is mainly used for file search. It has been described in detail in the previous article (see the system home Linux find command common usage summary), today Xiaobian wants to give Everyone introduced the use of the Linux find command and the xargs command. Let's take a look at it. When
In the process -exec option to use the find command to match the file, find the command will be passed along to all matching files to execute exec. However, some systems have restrictions on the length of commands that can be passed to exec, so that after a few minutes of the find command, an overflow error will occur.
The error message is usually "The parameter column is too long" or "Parameters" Column overflow & rdquo;. This is where the xargs command is used, especially with the find command.
The find command passes the matching file to the xargs command, while the xargs command only gets a portion of the file at a time instead of all, unlike the -exec option. This way it can process the first part of the file first, then the next one, and continue with it.
In some systems, using the -exec option will initiate a corresponding process for processing each matched file, not all of the matched files will be executed as parameters once; in some cases There are too many processes and system performance degradation, so it is not efficient; while using the xargs command there is only one process. In addition, when using the xargs command, whether to get all the parameters at a time, or to get the parameters in batches, and the number of parameters obtained each time will be determined according to the options of the command and the corresponding adjustable parameters in the system kernel.
Use Case:
Instance 1: Find each regular file in the system, and then use the xargs command to test which file they belong to.
Command:
The code is as follows:
find . -type f -print |
Xargs file
Output:
The code is as follows:
[root@localhost test]# ll
Total 312
-rw- R--r-- 1 root root 302108 11-03 06:19 log2012.log
-rw-r--r-- 1 root root 0 11-12 22:25 log2013.log
-rw-r--r-- 1 root root 0 11-12 22:25 log2014.log
drwxr-xr-x 6 root root 4096 10-27 01:58 scf
drwxrwxrwx 2 root root 4096 11-12 19:32 test3
drwxrwxrwx 2 root root 4096 11-12 19:32 test4
[root@localhost test]# find . -type f -print |
Xargs file
. /log2014.log: empty
. /log2013.log: empty
. /log2012.log: ASCII text
[root@localhost test]#
Instance 2: Find the memory dump file (core dump) in the entire system, then save the result to /The
command in the tmp/core.log file:
The code is as follows:
find /-name “core” -print |
Xargs echo “” ”/tmp/core.log
Output:
The code is as follows:
[root@localhost test]# find /-name “core&rdquo ; -print |
Xargs echo “” ”/tmp/core.log
[root@localhost test]# cd /tmp
[root@localhost tmp]# ll
Total 16
-rw-r--r-- 1 root root 1524 11-12 22:29 core.log
drwx------ 2 root root 4096 11-12 22 :24 ssh-TzcZDx1766
drwx------ 2 root root 4096 11-12 22:28 ssh-ykiRPk1815
drwx------ 2 root root 4096 11- 03 07:11 vmware-root
Previous1234Next page Total 4 pages
As an operating user of Ubuntu system, the Linux kernel cant be used when it is jus
Learning to use a Linux system is actually a process of mastering many commands, bu
The Nginx log in the Linux system can view the system running records and error des
Under Linux, you need to implement file transfer between two servers. You can use t
How to set up Kde5 for Gentoo Linux system?
Ubuntu 12.04 installation Xen FAQ and solution
Detailed method for automatic backup and deletion of website data under Linux
Linux how to install and configure rz/sz command
How to use the Linux system Passwd command
Linux to see if the system is attacked by cc
How to solve Ubuntu 12.04 boot error Checking Battery State problem
Linux system rescue mode operation example
Linux accidentally delete the log file syslog how to do?
Linux system apachectl command instructions
How to delete Windows 7 system search bar history
Add a cool background image to your disk
7 command line tools for monitoring Linux systems
Win7 installation software "Unable to access Windows Installer service" problem solving method
You don't know the input function of the top ten useful functions
Retrieve Win8.1 (windows server 2012 R2) double spell
Win7 play League of Legends game crash pop-up error report dialog solution