In Terminal (using bash and tcsh) cp -r copies the contents of a folder instead of the folder if the folder argument has a / at the end.

Given the following structure:


The following command copies fileA and fileB to destination instead of copying folderA to the destination:

cp -r folderA/ destination

So it acts as

cp -r folderA/* destination

This is super annoying because by default completion in tcsh adds a / at the end of the folder, so I always end up having to clean up if I forget to delete the / at the end. This behavior is different from every other *nix I've worked on.

Is there any way to change this and make cp -r folderA/ copy the folder instead of its contents?

  • Relevant explanation of the difference between the BSD and GNU implementations of cp - jondavidjohn.com/blog/2012/09/linux-vs-osx-the-cp-command Sep 26, 2012 at 16:36
  • I would think that the two cp commands do not act the same as the second would not copy hidden files and directories in folderA, while the other does. Jul 24, 2014 at 5:08
  • I rather like that feature, as long as I don't forget it's there. If I do cp foo bar, I'll either get bar/ as a clone of foo (if bar/ didn't already exist), or bar/foo/ (if it did.) It's a little confusing. On the other hand, if I do cp foo/ bar then the results are consistent. Mar 10, 2016 at 22:06

3 Answers 3


There is a case to be made that this behavior makes more sense (and I believe it's used by rsync, even on GNU/Linux). Consider the following case:


The the semantics of these three specifiers are all different:

 cp -r mydir   dest/   # creates dest/mydir, containing both files
 cp -r mydir/  dest/   # copies both files directly into dest
 cp -r mydir/* dest/   # copies fileB, but not .fileA, directly into dest

I believe this is an example of a difference between BSD and GNU. You can install GNU flavored tools using fink (see coreutils package), but these might not preserve all HFS+ metadata, so proceed with caution.

You can intercept the command and strip out the trailing slash. I'll leave that as an exercise to the reader, or other answerers.

You can alter the tab-completion behavior so the slash isn't added in the first place. Add the following to your ~/.tcshrc:

 unset addsuffix

You can achieve a similar effect in bash and misc readline utilities by adding the following to your ~/.inputrc:

 set mark-directories off
  • 1
    It adds unnecessary complexity imo. In bash, i'm for shopt -s dotglob all the way. May 23, 2009 at 6:29
  • shopt doesn't work in tcsh, does it? I don't have strong feelings either way, I'd just like them to offer a "--strip-trailing-slashes" command line switch: gnu.org/software/coreutils/manual/html_node/…
    – Matt G
    May 23, 2009 at 7:05

Without manually deleting the '/' appended in a default installation? Unfortunately not as stated on Apple's Darwin man page for cp is "If the source_file ends in a /, the contents of the directory are copied rather than the directory itself." So it appears it's part of the design of Darwin's cp.

It is however possible to unset the addsuffix shell variable in tcsh in order to drop the '/' from being added to directories. The big downside being that it's now very difficult to tell if you're dealing with a directory or a file just from the completion. To do so type on your command line (or add to your .tcshrc):

 unset addsuffix

For bash you can use the mark-directories setting. You can type the following or add it to your .bashrc:

 bind 'set mark-directories off'

Source for use of mark-directories: MacNN Forums: Hal Itosis


"You can intercept the command and strip out the trailing slash. I'll leave that as an exercise to the reader, or other answerers." Adding

function cp() { /bin/cp $(echo "$*" | sed 's|/ | |g'); }

to ~/.bashrc seems to do the trick.

You must log in to answer this question.

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