Linux Terminal下如何删除带有指定字符的文件

水一下,不然这里就完全变成没有生气的代码堆了(还乱的一批)
最近几周实在太浪了,完全没学习(= ̄ω ̄=大概是的吧)
然后这个博客的硬货数量也还停留在一篇,近期应该再会写一篇
(2021年初观光:学个吊毛,写个吊毛,起来看番啊)

好了,言归正传

How to search and delete files who contain specific string in name?

Please be careful
This following command with the parameter -delete deletes all the files with something in the name in the specified directory and in all subdirectories.


Open a terminal and go to the right folder:

1
cd <your_search_starts_here>

test with

1
find . -type f -name "*something*"

and delete with

1
find . -type f -name "*something*" -delete

Or a shorter version:

1
find <your_search_starts_here> -type f -name "*something*" -delete

1. For your home folder:

Warning: first run a test!!!

1
find ~ -type f -name "*something*"

and then

1
find ~ -type f -name "*something*" -delete

2. For the whole filesystem(从根目录开始搜索):

Warning: first run a test !!!

1
sudo find / -type f -name "*something*"

and test again and than delete with

1
sudo find / -type f -name "*something*" -delete

3. Or only in the specified directory(在指定文件夹下搜索):

1
find <your_search_starts_here> -maxdepth 1 -type f -name "*something*" -delete

And because you have used the tag locate:

The results of a search with locate are based on a database. This may be outdated. Start an update with sudo updatedb. find performs a true search. However, it also takes longer.

出处:原文