Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I move files up one directory and delete old directory without specifically naming files?

I use a shell script that takes a single directory, called NewData, with whatever is inside of it, and creates this:

enter image description here

There is one step I want to add, and I am not sure how to do it. I want to move the contents of NewData and NewDataCopy into their respective parent directories (ProtectedOrig and Data) and delete NewData and NewDataCopy. What command(s) would I add to my script to do this without specifically naming the files to be moved (they will be different every time I run the script)?

If it would help, you can have a look at the script here. I'm grateful for whatever assistance I can get!

like image 340
Jeff Severns Guntzel Avatar asked Oct 08 '11 13:10

Jeff Severns Guntzel


1 Answers

You can move everything without naming the files specifically by using a "glob" (aka a "wildcard"). That's a *.

So let's say you are in DataDirectory. You can move everything from Data/NewDataCopy up to Data by doing this: mv Data/NewDataCopy/* Data/. Then delete with a rmdir Data/NewDataCopy.

Starting from DataDirectory then to do everything you'd do this:

mv Data/NewDataCopy/* Data/
rmdir Data/NewDataCopy
mv ProtectedOrig/NewData/* ProtectedOrig/
rmdir ProtectedOrig/NewData
like image 79
drysdam Avatar answered Nov 15 '22 05:11

drysdam