D
D
DonCarBon2020-12-02 00:16:45
linux
DonCarBon, 2020-12-02 00:16:45

How to delete files in a directory but leave files by mask?

You need to delete all files in the specified folder on the server , but you need to leave only those that end with:

*_large.jpg
*_thumbnail.jpg
*_large.jpeg
*_thumbnail.jpeg
*_large.png
*_thumbnail.png

If this helps , here's a command that works great, but it just deletes all files in the directory and subdirectories.

find public_html/images/test/01 -type f -name "*.*" -delete


Perhaps it is necessary to somehow specify exceptions in it, but I don’t have enough skill ....

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Saboteur, 2020-12-02
@DonCarBon

find public_html/images/test/01 -type f ! -name '*_large.*' ! -name '*_thumbnail.*' -delete

C
Codebaker, 2020-12-02
@Codebaker

rm -v !(*_large.jpg|*_thumbnail.jpg|*_large.jpeg|*_thumbnail.jpeg|*_large.png|*_thumbnail.png)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question