My favorite "trick" is really a small shell script. I wrote a quick script called "supersplice" which accepts a sed-style search/replace expression and a list of filenames. When run, it applies that expression to every file listed. It runs sed on each one (sending output to a temp file, then copying the temp file over the original).
It's really handy for making massive search/replace changes over a large body of files, especially when coupled with commands like find or "grep -Rl" to provide the list of filenames.
Of course, a command like this is massively dangerous when it screws up. In my case, I'm usually running it against files that are under version control. So I make a point of first doing a "git add" or "git commit" to snapshot my current state. Then I run the supersplice and use "git diff" to check the results and (if it screwed up) other git commands to undo the damage.
The trick of cloning a directory with two instanced of tar worked decades ago when many of cp's options didn't exist. In particular, those that preserve user/group/permissions, those that copy symlinks (instead of following them) and other options necessary for making a backup-type clone.
Today, most of it can be done with cp's "-a" and "-R" options, but that's a relatively recent innovation.
Authored Comments
My favorite "trick" is really a small shell script. I wrote a quick script called "supersplice" which accepts a sed-style search/replace expression and a list of filenames. When run, it applies that expression to every file listed. It runs sed on each one (sending output to a temp file, then copying the temp file over the original).
It's really handy for making massive search/replace changes over a large body of files, especially when coupled with commands like find or "grep -Rl" to provide the list of filenames.
Of course, a command like this is massively dangerous when it screws up. In my case, I'm usually running it against files that are under version control. So I make a point of first doing a "git add" or "git commit" to snapshot my current state. Then I run the supersplice and use "git diff" to check the results and (if it screwed up) other git commands to undo the damage.
The trick of cloning a directory with two instanced of tar worked decades ago when many of cp's options didn't exist. In particular, those that preserve user/group/permissions, those that copy symlinks (instead of following them) and other options necessary for making a backup-type clone.
Today, most of it can be done with cp's "-a" and "-R" options, but that's a relatively recent innovation.