Easiest way to move contents of all subfolders into parent folder

Discussion in 'Other Operating Systems' started by shredder, Oct 23, 2018.

  1. shredder

    shredder Member

    Joined:
    Dec 26, 2001
    Messages:
    10,937
    Location:
    Dec 27, 1991
    Ubuntu 18. Everyday home usage.

    A simple little process. How can you best automate it?

    1. A script (nice)? Could do this easily in DOS 25 years ago, with a bat. Help me create the linux version.

    2. A GUI extension (nicer)? Could do this easily in Windows 10 or 20 years ago (as in, somebody else had created the right-click GUI extension, and you could easily obtain and install it). Can we add this to Ubuntu?

    EXAMPLE OF PROCESS:

    Before:
    Code:
    PARENT_FOLDER/SUB1/file1.txt
                      /file2.wtf
                      /otherthing.docxxx
    PARENT_FOLDER/THING/spreadsheetoftheuniverse.xls
                       /whatever.txt
    PARENT_FOLDER/XTREEGOLD/xtg.bat
                           /yolo.txt
    ...etc...
    
    After:
    Code:
    PARENT_FOLDER/file1.txt
                 /file2.wtf
                 /otherthing.docxxx
                 /spreadsheetoftheuniverse.xls
                 /whatever.txt
                 /xtg.bat
                 /yolo.txt
    ...etc... 
    I could Google this and figure it out myself, but thought it might be a bit of fun (and educational) for the experts here to discuss the best alternatives for solving a simple file process in modern Linux.
     
    Last edited: Oct 23, 2018
  2. BAK

    BAK Member

    Joined:
    Jan 7, 2005
    Messages:
    899
    Location:
    MornPen, VIC
  3. OP
    OP
    shredder

    shredder Member

    Joined:
    Dec 26, 2001
    Messages:
    10,937
    Location:
    Dec 27, 1991
    Thanks for your input BAK. Your 2009 link is a good starting point.

    I don't want to have to type that long technical sentence every time. Let's make it so I only have to jump to terminal in a given folder, and run a three letter command (let's call it "stp", short for "subfolders to parent") to execute the process.

    I also encourage further discussion of the other questions in my post, and other alternatives, in the vein of the principle stated:
    For example, once we have the 3 letter script sorted, we can move on to the GUI implementation.
     
    Last edited: Oct 23, 2018
  4. BAK

    BAK Member

    Joined:
    Jan 7, 2005
    Messages:
    899
    Location:
    MornPen, VIC
    Have a look at "alias", it should achieve this for you. You can use it to create aliases for commands. You could also create a script that runs that command, and name it "stp" and place it in a folder that your shell interprets as containing binaries, such that when you type "stp" it runs that script.
     
  5. Statitica

    Statitica Member

    Joined:
    Dec 29, 2009
    Messages:
    3,161
    Location:
    Lae, Morobe, PNG
    Couldn't this be done with something like:
    Code:
    # mv would work just as well, if not better for the OP's intent
    cp -Ruv * ../
    ?

    EDIT: I guess it depends on the start point (mine assumes you are in the sub-folder when you run the command). You could mess around with for loops, or write a python script and make it run, but to be honest BAK's solution is probably the simplest.

    Which file browser are you using? Thunar (xfce) has context sensitive scripting enabled by default, and to most of the others you can add an extension called "filemanager-actions" or "caja-actions" in MATE. You don't need to worry about the CLI, you just put your command in behind an alias, right click on your folder and go for gold.
     
    Last edited: Jan 23, 2019
    shredder likes this.

Share This Page