Find./-name *.bak | Xargs RM-RF

Source: Internet
Author: User

#####################################################################################################

#find ...-exec rm {} \;

The find command can be found to delete the results, the difference is simply the former is to find the results of the search to the EXEC option, so when the number of files, there may be "too many parameters" error.

-exec must be made up of one;   End, and because usually the shell will be right;   For processing, so use \; Prevent this situation. {} may need to write ' {} ', also to avoid being filtered by the shell

EG1:

[[email protected] xusx]# Touch 1.sh 2.sh 3.sh 1.txt 2.txt 3.txt
[[email protected] xusx]# ls
1.sh 1.txt 2.sh 2.txt 3.sh 3.txt passwd
[[email protected] xusx]# Find/-type f-name "passwd"-exec rm {} \;

[[email protected] xusx]# ls
1.sh 1.txt 2.sh 2.txt 3.sh 3.txt

#####################################################################################################

#find ... | Xargs RM-RF

This command avoids this error because the Xargs command will process the results in batches. So it seems, "find ... | Xargs RM-RF "is a more general method, recommended use!

RM does not accept standard input, so you cannot use Find/-name "Tmpfile" |rm

EG1:

[[email protected] a]# ls
1.sh 1.txt 2.sh 2.txt 3.sh 3.txt

[[email protected] a]# Find/-type f-name "1.sh" |xargs rm-f
[[email protected] a]# ls
1.txt 2.sh 2.txt 3.sh 3.txt

#####################################################################################################

./ indicates a search from the current directory
-type F, which means that only files, file types, directories, and other bytes are found.
-exec passes the file name of find to the following command line instead of the {} part
-exec after the command line, you must use "\;" End

Find./-name *.bak | Xargs RM-RF

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.