Linux commands (2)---Find command with xargs_find tips

Source: Internet
Author: User

Xargs

Using Find to locate a file is a batch output, but there is no need to do this, but when the file you are looking for needs to be processed, it is possible that the parameter column is too long or the parameter column overflows to cause an error in the message, or you cannot get the result that you want to output.

At this point, find can be piped to achieve this function, its role is to convert the parameter list into small pieces to pass to other commands, to avoid the parameter column information error problem, and can get the available output results.

"Instance 1" means querying all the normal files in the current directory and listing them in a long format, but the output of the catalog file is not the result of the output, which can be achieved using Xargs.

[[Email protected] tmp]# find -type f | ls -ltotal 20-rw-r--r--.  1 root      root          0 apr  6 10:57 file4-rw-r--r--.  1 root       ROOT      1562 APR 14 16:41 PASSWD----------.  1  root      root      1114 apr 14  16:41 shadowdrwxr-xr-x. 2 root      root       4096 apr 14 17:59 test1-rw-rw-r--.  1 nodelinux nodelinux     0 apr 14 15:38 test10-rw-rw-r--.  1 nodelinux  Nodelinux    0 apr 14 15:39 test11-rw-rw-r--.  1 hadoop     hadoop       0 apr 14 15:49 test13-rw-rw-r--.  1 hadoop     hadoop       0 Apr 14 15:49  Test14-rw-rw-r--.  1 hadoop    hadoop       0  apr 14 15:49 test15drwxr-xr-x. 2 root      root       4096 apr 14 18:09 test2drwxr-xr-x. 2 root       root      4096 apr 14 18:09  test3//indicates that the results found in find are entered into Xargs, and then handled by "Ls -l", where the "rm" command can be executed, a bit similar to   "-exec" but can cause overflow. [[Email protected] tmp]# find -type f | xargs ls -l-rw-r--r--.  1 root      root          0 Apr  6 10:57 ./file4-rw-r--r--.  1 root      root       1562 APR 14 16:41 ./PASSWD----------.  1 root       root      1114 apr 14 16:41 ./shadow-rw-rw-r--.  1  nodelinux nodelinux    0 apr 14 15:38 ./test10-rw-rw-r--.  1 nodelinux nodelinux    0 apr 14 15:39 ./ Test11-rw-rw-r--.  1 hadoop    hadoop       0  apr 14 15:49 ./test13-rw-rw-r--.  1 hadoop    hadoop        0 apr 14 15:49 ./test14-rw-rw-r--.  1 hadoop     hadoop       0 apr 14 15:49 ./ test15//also allows for batch modification of permissions [[Email proTected] tmp]# find -type f | xargs chmod u-w[[email protected]  tmp]# lltotal 20-r--r--r--.  1 root      root          0 apr  6 10:57 file4-r--r--r--.   1 root      root      1562 apr 14  16:41 PASSWD----------.  1 root      root       1114 Apr 14 16:41 shadowdrwxr-xr-x. 2 root       root      4096 Apr 14 17:59  Test1-r--rw-r--.  1 nodelinux nodelinux    0 apr 14 15:38  test10-r--rw-r--.  1 nodelinux nodelinux    0 Apr 14  15:39 test11-r--rw-r--.  1 hadoop    hadoop       0 apr 14 15:49  test13-r--rw-r--.  1 hadoop    hadoop        0 apr 14 15:49 test14-r--rw-r--.  1 hadoop    hadoop        0 Apr 14 15:49 test15drwxr-xr-x. 2  root      root      4096 apr 14  18:09 test2drwxr-xr-x. 2 root      root       4096 apr 14 18:09 test3//list file types [[Email protected] tmp]# find  -type f | xargs file    ./test13: empty./shadow: ascii  text./file3:  ASCII text./passwd: ASCII text./test10: empty./test15:  Empty./test14: empty./test11: empty./file4:  empty//queries the specified file and filters the "hell" content in the file [[Email protected] tmp]# find  -type f -print | xargs grep  "Hell"./file3:hello word// To find all files in the current directory that are not part of the catalog file, package them [[email protected] tmp]# find -not -type d |  xargs tar zcvf b.tar.gz./test13./shadow./file3./passwd./a.tar.gz./test10./test15./test14./ test11./thu./file4[[email protected] tmp]# lsthu        b.tar.gz  file3  passwd  test1   test11  test14   test2a.tar.gz  file15    file4  shadow  test10   test13  test15  test3//a meaning to package all files belonging to ordinary files in the current directory, [[email protected] tmp]#  find -type f -print0 | xargs -0 tar zcvf c.tar.gz./test13./ shadow./file3./passwd./a.tar.gz./test10./test15./test14./test11./thu./b.tar.gz./file4[[email protected] tmp]# lsthu        b.tar.gz  file15  file4   shadow  test10   test13  test15  test3a.tar.gz  c.tar.gz  file3    passwd  test1   test11  test14  test2

This article is from the "Perthon" blog, make sure to keep this source http://perthon.blog.51cto.com/10484057/1764652

Linux commands (2)---Find command with xargs_find tips

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.