3

I have a folder structure like this:

MAT11NA_09_XX_XX_XXX
MAT11NA_09_XX_XX_XXXL
MAT11NA_11_XX_XX_XXX
MAT11NA_11_XX_XX_XXXL
MAT11NA_10_XX_XX_XXX
MAT11NA_10_XX_XX_XXXL

I want to copy from this server to another just the folder MAT11NA_09_XX_XX_XXX, but not MAT11NA_09_XX_XX_XXXL. When I finish with this I want to copy MAT11NA_09_XX_XX_XXXL but not MAT11NA_09_XX_XX_XXX. This part MAT11NA_09_ doesn't change, the L at the end also doesn't change.

The same for the rest of the folders...

How do I do this in Unix/Linux command line?

Thank you.

3
  • 3
    I'm having a lot of trouble reading this - in particular, I don't see any slashes in your description of your directory structure. Any change you could simplify it a bit?
    – Cascabel
    Oct 2, 2009 at 18:46
  • 1
    Are you asking how to copy something from one server to another? Or how to copy a folder? Or how to cope with long filenames?
    – Beta
    Oct 2, 2009 at 18:50
  • WTF is that "belon" tag?!?
    – Massimo
    Oct 2, 2009 at 19:11

4 Answers 4

5

With an "L"

cp -r *L destination

Without an "L"

cp -r *[^L] desyination
1

I know it's stupid, but at least it's straight forward.

This will copy all files/directories ending with L:

cp `ls | grep -E 'L$'` DEST

This will copy all files/directories NOT ending with L:

cp `ls | grep -vE 'L$'` DEST

Replace DEST with your destination.

2
  • Wouldn't "cp *L DEST" have been a lot simpler?
    – Massimo
    Oct 2, 2009 at 19:10
  • ls is not supposed to be used to generate filenames for shell expansion, it is intended for user presentation of filenames. You should really, really use just shell expansion, or find -print0/xargs -0.
    – Juliano
    Oct 2, 2009 at 23:58
1

For the ones that you do want the L, just do:

scp -r MAT*L destserver:/whatever/

To do ones that do not have L, you want extended Globs with bash:

shopt -s extglob
scp -r ./!(MAT*L) destever:/whatever/

I haven't test this with scp, but this roughly a way to do it. You could also consider using the find command with something like (for ones not with L).

find . ! -iname 'MAT*L' ! -iname '.*' -print0 | xargs -0 tar zcf foo.tar.gz

and then just copy the tar file.

0

Ok, I've tried all of them.

"scp -r MAT*L destserver:/whatever/" - this one looks like it's working.

shopt extglob
scp -r ./!(MAT*L) destever:/whatever/

For this one I ran the command "shopt extglob", then did the copy. But I got this error "-bash: !: event not found"...so, it's not working.

I tried also the first answer... The folder structure is kinda like this:

folder1
   MAT11NA_09_XX_XX_XXX
   MAT11NA_09_XX_XX_XXXL
   MAT11NA_11_XX_XX_XXX
   MAT11NA_11_XX_XX_XXXL
   MAT11NA_10_XX_XX_XXX
   MAT11NA_10_XX_XX_XXXL   

I want to take MAT11NA_09_XX_XX_XXX folders and put in a folder on another server.

Then I want to take MAT11NA_09_XX_XX_XXXL folder and put in another folder on another server.

Then...I want to take MAT11NA_11_XX_XX_XXX folders and put in in a folder (different from the folder where I put MAT11NA_09_XX_XX_XXX) on another server.

The same for MAT11NA_11_XX_XX_XXXL...

I don't want to put ALL L folders in one folder from another server, and I don't want to put ALL non-L folders in another one folder from another server.

Hope you understand this time, sorry. Thank you.

UPDATE

Ok, after the last answerr I am using these and it seems they are working:

scp -r MAT11NA_09_*L contentuser@/destination

scp -r MAT11NA_09_*[^L] contentuser@/destination
4

You must log in to answer this question.