Copy linux directory into another one - delete contents

0

BIG EDIT:

I currently have a directory with folders and files inside:

-css
--addons
---myaddon
----addon
-----firsfile.xml
-----secondfile.xml
----cfg
-----anotherfile.cfg
-----lastcfg.cfg
---mysecondaddon
----addon
-----thirdfile.xml
-----fourthfile.xml
----cfg
-----againfile.cfg
-----othercfg.cfg

I want to copy it in another directory:

-css_server_1
--cstrike
---cfg

Now I have a GUI allowing me to list my addons (/css/addons/) and I want to install one of the addons (mysecondaddon from /css/addons/mysecondaddon) on my first server (css_server_1/cstrike)

The final result must be:

-css_server_1
--cstrike
---addon
----firsfile.xml
----secondfile.xml
---cfg
----againfile.cfg
----othercfg.cfg

If I chose to add the other addon (myaddon from /css/addons/myaddon), the result will be:

-css_server_1
--cstrike
---addon
----firsfile.xml
----secondfile.xml
----thirdfile.xml
----fourthfile.xml
---cfg
----againfile.cfg
----othercfg.cfg
----againfile.cfg
----othercfg.cfg

Finally, I would want to remove one of the addons installed (mysecondaddon).

I am looking for a linux command allowing me to delete in the /css_server_1/cstrike directory all the files appearing in (/css/addons/mysecondaddon), so the result will be:

-css_server_1
--cstrike
---addon
----firsfile.xml
----secondfile.xml
---cfg
----againfile.cfg
----othercfg.cfg

I know I can use the rm -rf command to delete the /css_server_1/cstrike/addon folder, but this will delete all the addons...

I hope it was clearer this time :D

jeremyb

Posted 2015-06-01T14:12:30.657

Reputation: 101

did you tried with -rf options? – Francisco Tapia – 2015-06-01T14:16:29.403

Why don't you mv? – Werner Henze – 2015-06-01T14:39:06.810

mv will move the folder, I want to keep the source intact. – jeremyb – 2015-06-01T16:23:40.147

I'll rewrite it tomorrow – jeremyb – 2015-06-01T21:13:14.240

just edited my topic – jeremyb – 2015-06-02T08:21:30.460

Still confusing. For example you have two "againfile.cfg" files in the same directory (css_server_1/cstrike/cfg/). – gogators – 2015-06-02T12:22:24.843

Answers

1

Your question is still confusing, but I think I know what you want to do. Take a look at the rsync command. For example:

rsync -av --delete css/addons/myaddon/ css_server_1/cstrike/

or something similar should do the trick for you. The important thing is the --delete option which will remove extraneous files from css_server_1/cstrike/ that are not in css/addons/myaddon/.

gogators

Posted 2015-06-01T14:12:30.657

Reputation: 1 183

Just edited the main topic, thx for your answer – jeremyb – 2015-06-02T08:21:01.457

it's getting interesting, I'm trying this tonight and will upvote helpful answers. Thx! – jeremyb – 2015-06-02T12:40:11.333

0

Try rm -rf /path/to/directory/todelete

or mv /src /dest

Joseph

Posted 2015-06-01T14:12:30.657

Reputation: 617