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.
Very Good Course... help me a lot in understand the linux bash/shell.
I hate find ... I now use https://github.com/sharkdp/fd
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?
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!