1

I've looked through other answers and they do not appear to quite fit what I'm trying to do, so please excuse me if I've missed something and this is a repeated question.

I'm trying to move files in subfolders. Here is the current folder tree:

Parent_folder
|     |SubfolderA
|     |     |Sub_subfolderAA
|     |     |     |FileAAA.abc
|     |     |     |FileAAB.abc
|     |     |     |FileAAB.abc
|     |     |Sub_subfolderAB
|     |     |     |FileABA.abc
|     |     |     |FileABB.abc
|     |     |     |FileABB.abc
|     |SubfolderB
|     |     |Sub_subfolderBA
|     |     |     |FileBAA.abc
|     |     |     |FileBAB.abc
|     |     |     |FileBAB.abc
|     |     |Sub_subfolderBB
|     |     |     |FileBBA.abc
|     |     |     |FileBBB.abc
|     |     |     |FileBBB.abc

What I would like to be able to do in this example is run a command which moved all files within the Sub_subfolders into their parent Subfolder, and repeats that for all of the Subfolders within the Parent folder.

1
  • Does the answer need to be a bash command?
    – MadMike
    Oct 3, 2019 at 9:23

1 Answer 1

1

If there's nothing but files in your subfolders (no folders), these lines of code should do it:

cd Parent_folder
for folder in *   #loop over all folders in the Parent_folder
do
    cd $folder
    mv */* .      # move all the files inside folder to their parent subfolder
    cd ..         # go back to Parent_folder
done

You must log in to answer this question.

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