1

I'm trying to copy files from a directory while excluding a folder and a file. My problem is that a get an error with shopt extglob activated. Here is my code:

DEPLOY_SIMULATION_ENV="/home/user/Desktop/fancyproject/"
shopt -s extglob
cp -r ./!(nbproject|zexp.html) "$DEPLOY_SIMULATION_ENV"
shopt -u extglob

It gives me

‘/home/user/Desktop/myfancyproject/’ is not a directory

Of course, I want cp to create the directory myfancyproject atuomatically. I have a workaround with mkdir $DEPLOY_SIMULATION_ENV first but is there a way to do it with cp? It behaves strangely when extglob is active.

1 Answer 1

1

Are you sure the problem is not the usage of "user" here...

DEPLOY_SIMULATION_ENV="/home/user/Desktop/fancyproject/"

If the account name is not "user" it will fail with the same error as you show. You need $USER if you want the actual user.


Is there a way to do it with cp

Yes... but not how you expect it.

--parents

Form the name of each destination file by appending to the target directory a slash and the specified name of the source file. The last argument given to cp must be the name of an existing directory. For example, the command:

      cp --parents dir1/dir2/file1 dir3
 

will create /dir1/dir2 inside dir3 (needs to already exist) and copy file1 into it.

1
  • Oh, it is such a stupid mistake of mine. I just forgot about --parents and -p. But anyway, yes, the user exists. Thanks!
    – shadox
    Sep 22, 2014 at 12:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .