Changes

Jump to navigation Jump to search
1,214 bytes added ,  14:33, 24 March 2017
Adds one-liner explaining how to reorganize Picture files from highly nested structure to flat structure
== Move Nested Files to Flat Date Structure ==
Just like in the [[Organize music files]] article, you might need to organize your Photo files. Let's say you use [[Shotwell]] to organize your files on import, but inadvertently switch the structure of imported files from YYYY-MM-DD to YYYY/MM/DD Big difference. How do you quickly move hundreds of files from the latter to the former structure?
 
The following command will use <code>find</code> to find all '''files'''; ignoring any hidden files or files in hidden directories. Then sed just turns the results into a command that uses back-references to put things in the right place. Note that the command as shown doesn't actually do anything but print out the commands that we use <code>sed</code> to construct -- so you can refine it if it's not correct. By adding an '''e''' at the end like <code>%e'</code> in the final invocation, it instructs sed to execute those as commands.
<source lang="bash">
find /home/greg/Pictures/2017/ -type f | grep --perl-regex -v '/\.' | sed 's%/home/greg/Pictures/2017/\([0-9][0-9]\)/\([0-9][0-9]\).*%mkdir -p "/home/greg/Pictures/2017-\1-\2" \&\& mv "&" "/home/greg/Pictures/2017-\1-\2/"%'
</source>
 
== Resources ==
# Tutorial: http://www.grymoire.com/Unix/Sed.html
[[Category:System Administration]]
[[Category:Bash]]
[[Category:Files]]
4,558

edits

Navigation menu