|
|
Flatten a directory structure
While I've sometimes used one-liners such as those being described here, I've all too often regretted it: A minor typo and files end up in the wrong place or with almost but not quite the intended names. And then you're left with coming up with a new command to fix things up. (Even worse, your one-liner fails part way through, and you now have two different problems to solve: The original one for the remaining files, and a new one for the mis-directed files.)
Two approaches make this safer: 1. Don't get fancy with one-liners. Use find to generate a list of input files; then convert it into a list of shell commands to carry out the necessary actions. Finally, when you've looked everything over and are satisfied with it, feed the commands to a shell ($ sh <command-file).
You can build the list of commands using whatever tools are comfortable and appropriate: sed, cut/paste, awk, tr (handy for changing upper to lower case, or '/' to '_'), emacs, vi. Sometimes a mix of tools is best - e.g., sed to do most of the work, emacs to fix up a few special cases.
2. If you do use a one-liner, check it first. Easy approach: Put echo in front of the command that actually renames or moves files or in any other way changes stuff. That way, nothing is actually done but you can see the commands that would have been executed. All too often, you'll find yourself feeling relief for not having "let it rip" without testing.--- -- Jerry Edited on Mar 18, '13 03:55:08AM by leichter
|
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.09 seconds |
|