Linux shell Programming Notes-Common find and xargs__ block chains

Source: Internet
Author: User
The Find command tool is used to locate files in the directory (or even the entire file system), search Path_name-option [-print-exec-ok] #find的一般格式; 1, Find command Options (-option) 1.1. Find files and directories by name (-name):cb@standalone14:~/documents$ find. -name "cb*"-print #在当前目录下, look for the beginning of CB documents and directories; 1.2, according to file modification time to find files and directories (-mtime):cb@standalone14:~/documents$ find. -mtime-2-print #在当前目录下, find files and directories modified within 2 days; cb@standalone14:~/documents$. -mtime +5-print #在当前目录下 to find files and directories modified 5 days ago; 1.3. Find files or directories according to file type (-type):Find. -type D-print #在当前目录下, find all directories; 1.4. Use exec and OK in Find to execute shell command:cb@standalone14:~/documents$ find.     -type f-exec ls-l {} \; #在当前目录下, locate all the files, and then execute the ls-l command; cb@standalone14:~/documents$ find.    -name "Myfile2"-ok rm {} \; #用安全模式ok, find files and delete files; < RM .... /shellt/myfile2 >?    Yes root@standalone14:/home/cb/documents# find/etc-name "passwd*"-type f-exec grep "cb" {} \; #查找文件 and through grep to see if there are any lines in the file that contain CB. 2, XargsXargs the results of find to the shell command, to avoid the process of consuming the resources of the machine. cb@standalone14:~/documents$ find. -type F-print | Xargs file #查找当前目录下, all files, and then view the files type of these files.
Related Article

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: 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.