1

So I unzipped a file with 1000+ folders, is there a way to "flatten" these folders? As in, grab all the contents from every folder and dump them into another directory.

3 Answers 3

5

The easiest way is when you unzip them. If you uncheck the "preserve paths" option (it may have a different name in your zip tool), the folder structure will be ignored during the unzip process, and everything will get put into one folder.

For unzip this would be the option -j to junk paths:

unzip -j archive.zip

Edit: I must share credit for the correct answer with Takkat. The first paragraph was my answer, but the next two lines were Takkat's.

2
  • Thank you so much, I've been running a rather complicated set of bash commands (a for loop) for this very thing.
    – Shelby. S
    Jul 13, 2012 at 20:10
  • No need to share credit @Tom. This site is from the community for the community - sometimes its just better to improve an existing good answer than to write another one ;)
    – Takkat
    Jul 13, 2012 at 21:00
2

If you already unzipped the files (and folders) try this:

First open a terminal, and change directory to the folder where you wish the files to be dropped.

cd path_to_folder

Then drop this in the same terminal:

find PATHtoWHEREtheFILESare -type f -exec mv -iv \{} . \;

This will recursively move everything in the PATHtoWHEREtheFILESare (you must provide a full path folder's name) into the current folder.

Good luck!

0

If you know the file type of the folder its easy. File type means file extension.

File extension: jpg, jpeg, png, gif, mp3, ogg, avi, mkv, exe, bin, deb, sh and many more. Its usually last few letter of a file after .yyy.

Let assume you have One folder.....

Named A which have 1000+ folder and all are full of .jpg file.

You can grub all jpg at once...for that open folder A and click on search (It's up side of the window). Type your file type .jpg in the search box and press Enter . It will find all jpg from all sub folder. Then you can simply select all file by pressing Ctrl+a and cut/copy. Paste it where you want to put it.

2
  • I should've been more specific, I'm working solely in the terminal
    – Shelby. S
    Jul 13, 2012 at 20:06
  • Then you need to follow what Tom said.
    – Kaktarua
    Jul 13, 2012 at 20:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .