How do I recursively touch files matching a pattern
Within my ~/docs directory, I want to "touch" all files ending with .txt
How can I do this?
With find
:
find ~/docs -name "*.txt" -exec touch {} \;
- You search in
~/docs
- The
name
option will match alltxt
files -exec
will execute the commandtouch
on the file name, which is substituted in{}
-
\;
ends the command andtouch
will be called once for each file found
Note:
- A slight variation,
\+
at the end constructs one single command to runtouch
on all of these files at once. This is not possible with all commands, but it works fortouch
and saves you a few calls if you have a lot of files that are affected.