Ubuntu – Copy files from a directory to a sub-directory (excluding the sub-directory itself)

command linecpdirectory

I have created a folder (directory) named Parent which contains several files (namely file1 file2file100) and subdirectories (Folder2, Folder3 etc) and a particular sub-directory named Child1 which itself may contain files and folders.
Now, I want to copy all the contents of Parent excluding Child1 into the folder Child1.

The final content of 'Child1' should be something like this:

 Old content of Child1
 file1 ... file100 + Folder2 Folder3 + etc.

How can I achieve this?

Best Answer

Assuming you are using bash as your interactive shell, you can enable extglob which allows you to specify "all files except these ones".

shopt -s extglob
cd Parent
cp !(Child1) Child1/