/errors/coreutils/cp-r-not-specified-omitting-directory
cp: -r not specified; omitting directory 'dir'
verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · ls (GNU coreutils) 8.32updated
- tool
- GNU coreutils
- exit code
- 1
- versions
- GNU coreutils 8.x – 9.x
- os
- linux, windows
GNU cp copies only files unless you ask for recursion. When a source is a directory it prints cp: -r not specified; omitting directory 'dir', skips it, and exits with status 1. Add -r (or -R) to copy the directory and everything in it, or -a to also keep permissions, timestamps and symlinks.
Older coreutils versions print the same error as cp: omitting directory 'dir'. On macOS (BSD cp) the message is cp: dir is a directory (not copied).; the fix is the same.
Reproduce it
mkdir -p project/src && echo 'x' > project/src/main.c && echo 'y' > project/README
mkdir backup
cp project backup/Output · exit 1
cp: -r not specified; omitting directory 'project'
With a glob, files are copied and directories skipped, and the exit status is still 1:
mkdir -p project/src && echo 'x' > project/src/main.c && echo 'y' > project/README
mkdir backup
cp project/* backup/ || echo "cp exit status: $?"
ls backupOutput
cp: -r not specified; omitting directory 'project/src' cp exit status: 1 README
Fix
mkdir -p project/src && echo 'x' > project/src/main.c && echo 'y' > project/README
cp -r project copy1
cp -a project copy2
mkdir copy3 && cp -r project/. copy3/
find copy1 copy2 copy3 -type f | sortOutput
copy1/README copy1/src/main.c copy2/README copy2/src/main.c copy3/README copy3/src/main.c
| Command | Result |
|---|---|
| cp -r project dest | dest/project/... if dest exists, otherwise dest becomes the copy |
| cp -r project/. dest/ | Contents of project copied into dest, including hidden files |
| cp -a project dest | Recursive, keeps mode, ownership, timestamps and symlinks |
| cp -rn project dest | Recursive, never overwrite existing files |
Sources
Related pages
errors · coreutilsbash: /usr/bin/rm: Argument list too longArgument list too long (E2BIG) means a glob like rm *.log expanded to more arguments than the kernel accepts. Use find -delete, find -exec {} + or xargs.errors · bashbash: ./script.sh: Permission deniedbash prints Permission denied (exit 126) when a script has no execute bit or sits on a noexec mount. Run chmod +x script.sh, or start it with bash script.sh.cheat sheets · bashBash cheat sheet: variables, tests, loops and expansionsBash cheat sheet with the syntax you use daily: variables, parameter expansion, tests, loops, functions, arrays, redirection and safe script headers on a page.