Total Commander F㼲 Mac Os X Download
Have yous ever needed to flatten a directory structure, moving all file contents from a directories child folders into a single folder? While you lot tin do this manually by moving around files and folders from the file organisation of Mac Os X or Linux, a faster option is to plow to the command line. Maybe at one point you created a nested hierarchy of directories that you now need to undo by moving all files out of those nested folders and back into a unmarried directory, or maybe yous're looking to simplify a directory structure, whatever the reason, this trick works quite well.
Using the command line to attain flattening of files and directory structures is manifestly best reserved for advanced users who are comfortable with using terminal in general, if that doesn't draw y'all, consider doing it manually through Finder, or using the Mac Automator app to accomplish similar automation of file system activities. We're focusing on directory flattening from the command line here, all the same.
Case of Flattening a Nested File Directory
To better understand what nosotros're trying to accomplish, let'due south accept an example imaginary directory structure called TestDirectory located in a user Home folder. In this example, TestDirectory contains subfolders like SubDirectory1, SubDirectory2, SubDirectory3, etc, each with files in those corresponding folders. What nosotros're looking to do hither is flatten the directory construction, moving all files from SubDirectory(10) to the parent directory "TestDirectory". The initial directory and contents shown recursively with the could look something like this:
$ find ~/TestDirectory/ -type f
~/TestDirectory/rooty.jpg
~/TestDirectory/SampleDirectory1/beta-tool-preview.jpg
~/TestDirectory/SampleDirectory1/alphabeta-tool.jpg
~/TestDirectory/SampleDirectory2/test-tools.jpg
~/TestDirectory/SampleDirectory3/test-png.jpg
~/TestDirectory/SampleDirectory3/test1.jpg
~/TestDirectory/SampleDirectory3/test2.jpg
To flatten this directory and subdirectory contents out back into the TestDirectory folder, you lot would use the following control string:
find TargetDirectory/ -mindepth 2 -type f -exec mv -i '{}' TargetDirectory/ ';'
Later the directory contents have been flattened, it should look like this when listed out:
~/TestDirectory/rooty.jpg
~/TestDirectory/beta-tool-preview.jpg
~/TestDirectory/alphabeta-tool.jpg
~/TestDirectory/exam-tools.jpg
~/TestDirectory/test-png.jpg
~/TestDirectory/test1.jpg
~/TestDirectory/test2.jpg
Note the subdirectories will still exist, they'll just be empty. Make sense? If not, or if that doesn't demonstrate what you lot want to accomplish, you probably don't want to flatten a directory at all, maybe yous're looking to merge or utilise ditto to practice a complex copy to elsewhere.
Flattening a Directory Structure & Nested File Bureaucracy with the Command Line
Ready to go on? The command cord nosotros're going to utilize to flatten a directory structure and motility all files from subdirectories to the base of the target directory is as follows:
discover [DIRECTORY] -mindepth 2 -type f -exec mv -i '{}' [DIRECTORY] ';'
Supersede [DIRECTORY] with the directory of your choice to flatten, as demonstrated in the example above.
Yes, the directory appears twice in the control string, the first time is the directory beingness searched to flatten subdirectories of, and the second time as the destination for the found items.
Exist precise with the specified destination, because this is not reversible (well, at least without a lot of transmission work on your part), and so merely do this if you're admittedly certain you want to relocate all the files in the target directories child directories back to the target root folder.
As mentioned earlier, you could also exercise this in the Finder of OS X, or at least find the file and folder changes in the Finder. Option+clicking the little arrows in the List view opens up all subdirectories, showing the folder hierarchy similar this:
Subsequently fiddling with a multifariousness of fustigate and zsh alternatives, this handy play tricks was left by a commenter on StackExcange and it ended up being the easiest and most compatible method. If you know of a meliorate way to flatten a nested directory, do let us know in the comments!
Total Commander F㼲 Mac Os X Download
Posted by: gonzalezenbraing.blogspot.com