Tomorrow is Friday

January 9, 2008

Copying a directory to an existing directory as in mv (or the trailing slash significance)

Filed under: shell script — dirkn @ 10:45 am

When copying a directory to a different location where the destination directory already exists and you would simply use:

  cp -R source-dir existing-dest-dir

then you are actually putting a copy of source-dir inside existing-dest-dir instead of replacing existing-dest-dir by source-dir.

The solution to this is to use a trailing slash for source-dir:

  cp -R source-dir/ existing-dest-dir

Watch out since, e.g., zsh removes this slash on <tab>.

Advertisements

2 Comments »

  1. About zsh: you can change this by disabling the option ‘AUTO_REMOVE_SLASH’, for more info see http://zsh.dotsrc.org/Doc/Release/zsh_15.html#IDX383

    Comment by Dries — January 23, 2008 @ 4:20 pm | Reply

  2. […] destination directory already exists and you do not use a trailing slash on the source-dir, then you are actually putting a copy of source-dir inside dest-dir. But our svn copy invocation used trailing slashes on both the source and destination […]

    Pingback by Why Caution Is Advised When SVN Copying Directories — August 17, 2012 @ 11:10 am | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: