I have a folderA that contains folderB that contains a lot of files. I would like to get rid of folderB, but not its contents. I want those contents to be inside of folderA. How can I accomplish this on the commandline?
2 Answers
$ cd /path/to/folderA
$ mv folderB/* .
$ rmdir folderB
-
1
-
12Watch out for dot files (files whose name begins with .) as this will not include those. Do
mv folderB/.* .
to move them as well. @NewLinuxUser, the dot in your question is an alias for the working directory (in this case, folderA).– BrianCommented Jun 11, 2010 at 17:36 -
1This fails if
folderB/folderB
exists, so beware of using it in scripts.– filiposCommented Feb 19, 2016 at 15:21 -
1This also fails if
folderB
contains an insane amount of files. You will seebash: /bin/mv: Argument list too long
because of the use of*
. If that's the case usemv
in combination withfind
as stated by @amphetamachine, or with afor loop
Commented Apr 5, 2016 at 15:10
Quick answer:
cd /path/to/folderA
find folderB -maxdepth 1 -mindepth 1 -exec mv {} . \;
rmdir folderB
Code-hardy answer:
cd /path/to/folderA
folderB_temp="$(mktemp -d -t folderB.XXXXXX)"
mv folderB "$folderB_temp"
find "$folderB_temp/folderB" -maxdepth 1 -mindepth 1 -exec mv {} . \;
rmdir --parents --ignore-fail-on-non-empty "$folderB_temp/folderB"