8
4
Within my ~/docs directory, I want to "touch" all files ending with .txt
How can I do this?
8
4
Within my ~/docs directory, I want to "touch" all files ending with .txt
How can I do this?
20
With find:
find ~/docs -name "*.txt" -exec touch {} \;
~/docsname option will match all txt files
- exec will execute the command touch on the file name, which is substituted in {}\; ends the command and touch will be called once for each file foundNote:
\+ at the end constructs one single command to run touch on all of these files at once. This is not possible with all commands, but it works for touch and saves you a few calls if you have a lot of files that are affected.
4
{} \+would be better here...touchcan handle many filenames on its command line, so for example, with 10 thousand files and{} \;10 thousand calls will be made totouch... Using{} \+will calltouchonly once (depending on available memory)... Here is an excerpt from find's man-page:-exec command {} + ... The command line is built in much the same way that xargs builds its command lines. There is more detail in theman finddocumentation. – Peter.O – 2012-06-04T14:36:17.030@Peter.O True, just a habit of mine to use the other syntax. – slhck – 2012-06-04T14:46:29.347
@slhck: And much slower with higher overhead. – Hello71 – 2012-06-04T20:49:29.773