Find Files and Folders with `find` in Bash

InstructorCameron Nokes

Share this video with your friends

Send Tweet

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.

Vinícius Melo
~ 6 years ago

Very Good Course... help me a lot in understand the linux bash/shell.

Pascal Chouinard
~ 6 years ago

I hate find ... I now use https://github.com/sharkdp/fd

Alex
~ 6 years ago

I am building a script that allows me to copy files (including a hashed js bundle) to a new folder. The filename is of the format bundle.[hash].js. Given that I want to do this every time I build the file (with a new hash), how can I find the file name so that I can use it in the cp command, without finding any other files that might be of the same format in child folders?

Cameron Nokesinstructor
~ 6 years ago

how can I find the file name so that I can use it in the cp command, without finding any other files that might be of the same format in child folders?

find dist -name 'bundle.*.js' -maxdepth 1 -exec cp {} somewhere \;

Sounds like something like that would work. You can use the -maxdepth option to prevent find from searching deeper than you want it to. Hopefully that works for you!