Main Content
Copy multiple files - confusing error message from cp Archive - Originally posted on "The Horse's Mouth" - 2006-12-30 09:59:53 - Graham Ellis
Thought you might like me to share this one ...
Copying a whole series of files into a directory (Linux, Unix, OS X) using cp , you give a whole series of source files followed by the name of the target directory. Add the -r option is you want to specify subdirectories to be copied recursively in your input.
So this should work, eh?
grahamellis$ cp -r whc.css images grgen.php ~/back_20061229/htaccess
usage: cp [-R [-H | -L | -P]] [-f | -i | -n] [-pv] src target
cp [-R [-H | -L | -P]] [-f | -i | -n] [-pv] src1 ... srcN directory
grahamellis$
What an odd result. Is the -r option wrong? No - that's not the problem. In my opinion, there's a bug in cp in that the usage line is incomplete, but that's not the real problem. The real problem was that I specified an existing file name as the target for my copy, and cp won't copy a whole series of files into one.
If I correct my command (by specifying a target directory name), it works perfectly:
grahamellis$ cp -r whc.css images grgen.php ~/back_20061229
grahamellis$
Footnote - if you want to preserve file ownerships as you copy them , use tar instead of cp . You need administrator access (i.e. be logged in as root) to do this.
Some other articles
A162 - Backups and File System Management Extracting data from backups to restore selected rows from MySQL tables Backup procedures - via backup server Commenting out an echo killed my bash backup script Checking MySQL database backups have worked (not failed) More or less back - what happened to our server the other day Backups by crossover between network centres - setting up automatic scp transfers An overpractical test of our backup strategy! How much space does my directory take - Linux Some Linux and Unix tips Will your backups work if you have to restore them? Dialects of English and Unix The tourists guide to Linux Linux / Unix - layout of operating system files Linux run states, shell special commands, and directory structures Finding public writeable things on your linux file system This article tar, jar, war, ear, sar files Boys will be boys, saved by Ubuntu Copying files and preserving ownership Finding where the disc space has gone What backup is adequate? Symbolic links and hard links Linux - where to put swap space A101 - Linux -An Introduction For Users Packing a tar, jar or war file - best practise The Kernel, Shells and Daemons. Greek Gods in computing Displaying a directory or file system tree - Linux Oops - I typed ci not vi, and have lost my file ... Recording (a macro) in vi Linux - useful tips including history and file name completion Making Linux Politically correct Accidentally typed ci rather than vi? What does x on a linux directory mean? How much space does my directory take - Linux Always use su with minus. And where do programs come from? Running straight from the jar, but not from a tar Ruby, Perl, Linux, MySQL - some training notes sstrwxrwxrwx - Unix and Linux file permissions Keeping on an even keel Some Linux and Unix tips FTP passive mode - a sometimes cure for upload hangs Yank and Push - copy and move in vi ls command - favourite options Selecting file names in a shell - one word or another Copy and paste / cut and paste and other vi techniques Wireless hotel tips - FTP and Skype connections failing awk - a powerful data extraction and manipulation tool Linux run states, shell special commands, and directory structures Work and play at Well House Manor - Football and Shell Shortcuts Where am I and how did I get here? ls -l report, Linux / Unix - types and permssions This article Moving files between Windows / DOS and Linux / Unix Cardinal numbers and magic numbers Cottage industry or production line data handling methods THE home directory or MY home directory Linux training Glasgow, Python programming course Dundee Copying files and preserving ownership More or less on the edge of the page Web Application Components Finding where the disc space has gone File permissions of Linux and Unix systems Linux commands - some basics An easy way out Aladdin, or careful what you wish. pushd and popd vi - full circle