Find specified type files in Linux and delete examples

Source: Internet
Author: User
Tags in domain

Run the WebLogic server on the Linux server, every time you need to shut down the WebLogic server, will leave some *.lok files in domain, cause the next time to start because these files can not start, therefore, need to delete all the resulting. Lok files.
Manual one of the delete more troublesome, need domain of each directory to go in to see if there is no, some words deleted.
You can see which of these files and bulk delete them by executing the following command.

Find./-name "*.lok"//Lookup file

Find./-name "*.lok" |xargs rm-fr//locate file and delete

1. Find-name ' *lck* '-exec rm {}\;

Finds files with the "lck" character in all filenames under the current folder and its subfolders and deletes them. Note that Find-name *lck*, which means no single quotes, searches only files in the current directory and does not search for files within subfolders.

By the way find the relevant use

1. Find/-name Test | Xargs rm-rf (This command can find the test file or directory and delete it!) )

2. Use the following command to find files that have been modified in the last two days of/home: Find/home-type f-mtime-2

If you want to delete these files, then you can: Find/home-type f-mtime-2-exec rm {}\;

-type F Find Files
-type d Lookup Directory

-mtime-2 modification time within 2 days
-mtime +3 modification time 3 days ago

-exec RM {}\; Perform the RM a.txt command by locating the file (assuming the name of the file is A.txt)

Find has a lot of parameters, found one time to look up multiple specified files or exclude a class of files, in GREP to match multiple keywords method

(1) Linux find at one time search for multiple specified files:

Find a.html and b.html
Find. -name "a.html"-name "b.html"

Find. -regex '. *\.txt\|. *\.doc\|. *\.mp3 '
Find. -regex '. *\.txt\|. *\.doc\|. *\.mp3 '
./a.txt
./a.doc
./a.mp3

(2) Exclude certain file types:

Exclude all files that end with HTML in the directory:
Find. -type f! -name "*.html"

Find. -type f! -name "*.html"
./ge.bak.02.09
./ge.html.changed.by.jack
./a.txt
./a.doc
./a.mp3

(3) Examples of various file types excluded:

Find. -type f! -name "*.html"-type f! -name "*.php"-type f! -name "*.svn-base"-type f! -name "*.js"-type f! -name "*.gif"-type f! -name "*.png"-type f! -name "*.cpp"-type f! -name "*.h"-type f! -name "*.O"-type f! -name "*.jpg"-type f! -name "*.so"-type f! -name "*.bak"-type f! -name "*.log"

(3) methods to match multiple keywords in GREP:

grep finds files for multiple numbers:

-R Recursive,-e: Regular-L: Show only file names

root@116.255.139.240:~/a# grep-r-E ' 0341028|100081|10086|10001 ' *
a.txt:100081
b.txt:10086
c/cc.txt:0341028
c/cc.txt:100081
c/cc.txt:10086
c/cc.txt:10001
c.txt:10001
d.txt:0341028

Grep-r-e-l ' 0341028|100081|10086|10001 ' *
A.txt
B.txt
C/cc.txt
C.txt
D.txt

Several types of file examples:

Find. -name "*.html"-o-name "*.js" |xargs grep-r "Busitree"

In awk:

Find. -name "*.php" |awk ' {print ' cat "$" |grep-h Dbsys. Www.111cn.net "} ' |sh

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.