How to loop through file names returned by find?

TL;DR: If you’re just here for the most correct answer, you probably want my personal preference (see the bottom of this post): # execute `process` once for each file find . -name ‘*.txt’ -exec process {} \; If you have time, read through the rest to see several different ways and the problems with most … Read more

How to use regex with find command?

find . -regextype sed -regex “.*/[a-f0-9\-]\{36\}\.jpg” Note that you need to specify .*/ in the beginning because find matches the whole path. Example: susam@nifty:~/so$ find . -name “*.jpg” ./foo-111.jpg ./test/81397018-b84a-11e0-9d2a-001b77dc0bed.jpg ./81397018-b84a-11e0-9d2a-001b77dc0bed.jpg susam@nifty:~/so$ susam@nifty:~/so$ find . -regextype sed -regex “.*/[a-f0-9\-]\{36\}\.jpg” ./test/81397018-b84a-11e0-9d2a-001b77dc0bed.jpg ./81397018-b84a-11e0-9d2a-001b77dc0bed.jpg My version of find: $ find –version find (GNU findutils) 4.4.2 Copyright (C) 2007 … Read more

find -exec with multiple commands

find accepts multiple -exec portions to the command. For example: find . -name “*.txt” -exec echo {} \; -exec grep banana {} \; Note that in this case the second command will only run if the first one returns successfully, as mentioned by @Caleb. If you want both commands to run regardless of their success … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)