bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: DWIM feature request for cp


From: Bob Proulx
Subject: Re: DWIM feature request for cp
Date: Wed, 15 Aug 2007 14:34:38 -0600
User-agent: Mutt/1.5.9i

Roberto Rodríguez wrote:
> Hello, I want to ask the developers what do they think about implementing a
> way to do "cp -r .* target" (copy files and directories starting with dot)
> without copying the parent directory ".." (I think that's what the user
> usually intends to do)

The first thing to think about is that the command line shell is where
the expansion is taking place.  The 'cp' command does not see the *
and does not know that you have used a wildcard.  You can verify what
the cp command is seeing by using the echo command.

  echo cp -r .* target

The cp command is seeing the literal names that are being given to
it.  Therefore it seems inconsistent to me to give it a name and then
add an option to tell it to ignore a name.  Better simply not to give
the name to it in the first place.

If you are using GNU bash then it is pretty easy to avoid .. if you
want.

  echo cp -r .!(.|) target/

That will expand to be every dot name except the . and .. name.  The
command won't have those handed to it as an argument and won't have to
avoid them.

It is of course possible to do more fancy stuff too but personally I
would probably copy the directory from the directory above in that
case because then things get simple.

Also, if I want to do some complicated picking of filenames then I
would use 'find' for this.

  find . -name 'foo*' -exec cp --target-directory=target {} +

  find . -type d -exec cp --target-directory=target {} +

  find . -type f -exec cp --target-directory=target {} +

The find command is very powerful and can select almost any
interesting combination of files.

Bob




reply via email to

[Prev in Thread] Current Thread [Next in Thread]