Question

I have a list of 20 directories, each one has another directory with the contents I need (i.e. the contents are needlessly one level deeper than they need to be), the names of each super-directory is different to one another and their sub-directories are the same as their parent but without "_100bp" suffix:

E.g. I have: directory_100bp/directory/<some content>

E.g. I need: directory_100bp/<some content>

I know I can create a bash script to iterate for each directory:

mv ./directory/* ../

But is there a way I can do this one or two lines? I don't mind if the empty sub-directory remains after moving the contents one level up.

Was it helpful?

Solution

If your top level directory is named mydir:

find mydir -mindepth 1 -maxdepth 1 -type d -exec bash -c 'mv {}/* mydir; rm -ri {}' \;

This will prompt you for each directory, you can change the -i flag to -f to force deletion without prompting.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top