Flatten Directory Structure in Linux

Move all the files with extension pdf in the directory tree starting at the current location as root to directory bla.

So for example it would find ./path/to/image/lex.pdf and move it to ./bla/lex.pdf

0 thoughts on “Flatten Directory Structure in Linux

  1. Andrew

    I was relieved to find this advice as i though it would save me some time compared to doing the same task using a GUI.

    I tried this command to move a load of jpg files from subdirectories into one place. However what i ended up with was one file called bla rather than a directory with all the files in!

    I think i can recover the files from my dodgy back up disc but can you help me with what happened. Should i have created the directory bla before running the command?

    My setup is Ubuntu 11.10 and i was using a standard terminal. Any feedback much appreciated…. Thanks

    Reply
    1. Lex Post author

      Yes, you got it right, the problem is that you didn’t create the directory “bla” first before running the command. Hopefully that helps. Thanks.

      Reply
  2. Warwick Chapman

    What about subfolders with PDFs which might have the same name in them. How do you avoid overwrites?

    eg.
    Folder
    — Subfolder 1/1.pdf
    — Subfolder 2/1.pdf

    Need it flattened and 1.pdf to be renamed (however) so as not to overwrite one another.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *