Score:0

Remove contents of directories without deleting contents

de flag

What I am trying to do is remove only the folders that the files are contained within.

For example:

  • Download
    -Folder1
    --File1
    -Folder2
    --File2

My goal is to remove Folder 1 and 2 and be left with the following:

  • Download

-File1

-File2

Esther avatar
es flag
you need to first move file1 and file1 into Download, and then delete folder1 and folder2
HelloMrMeseeks avatar
de flag
Yeah im not doing that 1000 times. Looking for an automatic method.
Esther avatar
es flag
bash wildcards with mv and rm, I'm writing one for you now but that's the gist of it
Will avatar
id flag
@HelloMrMeseeks - put the detail from your comment in your question (ie that you need an automated process that will operate on 1000 directories).
user535733 avatar
cn flag
This resembles a common homework problem. Lots of folks here are happy to help you learn, but wary of perhaps doing homework for you.
Score:4
es flag

You would have to first move (or copy) the files into the parent folder, and then delete the sub-folders. You could use the following commands from inside the Download folder:

mv */* .              # moves all items that are in folders to the current directory
rmdir */              # removes all empty directories from the current directory

From anywhere else in your system, just add the full path before the * and use the full path instead of ., for example

mv /home/hellomrmeseeks/Downloads/*/* /home/hellomrmeseeks/Downloads/
rmdir /home/hellomrmeseeks/Downloads/*/
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.