[Bash] Find Files and Folders with `find` in Bash

find is a powerful tool that can not only find files but it can run a command on each matching file too. In this lesson, we’ll learn how to find all the images that match a pattern and run an image optimization tool on them.

 

FInd files:

find images/ -name "*.png"
find images/ -iname "*.png"  # case insensetive

 

Find folder:

find . -type d -name "images"  # find folder named images

 

Doing deleting: '-delete'

find dist/ -name "*.built.js" -delete

 

Run command after finding the matching:  '-exec'

find images/ -name "*.png" -exec pngquant {} \; 

 

posted @ 2018-10-15 14:38  Zhentiw  阅读(152)  评论(0)    收藏  举报