cp - Command-line tool to copy a file

learn more… | top users | synonyms

8
votes
2answers
318 views

Why do `cp` and `rm` treat directories separately?

Why do tools like cp and rm treat directories separately from regular files? They both require the user to explicitly specify she wants a recursive behavior, or else they won't deal with directories ...
2
votes
1answer
188 views

What happens when I copy a file from one network location to another

Suppose I have three networked computers: A, B and C. A mounts a directory from B and from C. A/mnt/im-on-B/ A/mnt/im-on-C/ A then copies a file: cp /mnt/im-on-B/file ../im-on-C/ What happens ...
2
votes
3answers
224 views

How to copy a list of files and adjust destination filenames on the fly?

When I don't need to adjust destination filenames I can do something like this: $ find -type f -name '*.pat' -print0 | xargs -O cp -t /path/to/dest It is safe because the filenames may even ...
1
vote
1answer
272 views

Killed `rm` and `cp` on nfs share

I am just testing an rsnapshot installation on my laptop which should backup to a NAS mounted via nfs on my laptop. On one test rsnapshot died with a cp -al problem (i.e. a problem with hard links) ...
1
vote
2answers
149 views

Shell : Сopy one directory to multiple directories

There is a directory YYY and a structure on the site: site1.ru/wp-content/plugins/ site2.ru/wp-content/plugins/ ... site10.ru/wp-content/plugins/ Task: YYY directory to copy all directories plugins ...
2
votes
3answers
195 views

How to cp or rm files based on ownership / permission

After a problem with spam, I stopped postfix postfix stop and checked through the mailq manually to find hundreds of thousands of unsent spam. The spam was sent from one of the sites hosted ...
7
votes
1answer
89 views

Is there a way to express: `--link` or fall back to ordinary copy in cp (from GNU coreutils)?

Is there a way to tell cp to --link (i.e. create hard links), but fall back in the case where I am attempting inter-device hardlinks? Inter-device links aren't possible and would cause cp to fail. ...
2
votes
3answers
359 views

Use find + sed + cp to find files and copy them to a directory with a different name

I'm trying to copy a bunch of files named folder.jpg into a folder. The problem is because all the files are named the same thing, I need to rename them in the process. I know I can probably do it ...
3
votes
3answers
89 views

What are some quick ways of making N copies of a particular file?

Say, if I wanted to make N copies of a.txt, and wanted them to be numbered a1.txt, a2.txt, a3.txt, etc... How would I do such a thing succinctly?
2
votes
1answer
157 views

How can I copy a git repo from a Makefile?

I'm writing a Makefile to sync my local dotfiles with GitHub. I recently decided to also add my .vim folder to the repo. But when trying to copy the .vim folder I keep getting a Permission denied ...
0
votes
0answers
45 views

Move files replacing? [duplicate]

Possible Duplicate: ‘mv’ equivalent of drag and drop with replace? I'd like to take a folder /a/b/c, and copy all files in /a/b/x into /a/b/c, replacing all files in /a/b/c with the ones in ...
1
vote
1answer
770 views

How to copy symbolic links while preserving the validity of the link?

Say under directory /usr/local/boost_1_52_0/stage/lib, I have a symbolic link: libboost_timer.so, which points to the regular file libboost_timer.so.1.52.0 in the same directory. How can I cp the ...
2
votes
2answers
199 views

cp file device:directory on Minix

In my operating systems class we had to modify the boot screen of the Minix OS. I understood just about everything we did, but at the end of the make for compiling the new OS, there's a line: cp ...
9
votes
6answers
1k views

How to copy every 4th file in a folder

I have a lot of files in a folder, named like 00802_Bla_Aquarium_XXXXX.jpg. Now I need to copy every 4th file to a subfolder, saying in selected/. 00802_Bla_Aquarium_00020.jpg <= this one ...
5
votes
2answers
3k views

tar files from another directory without copying them

This should be very simple for experts in here. I have a Linux account with user disk quota of only 6GB. There is some data-folder in /opt with about 3GB of data with when compressed comes up 1GB. ...
1
vote
2answers
476 views

Copying only differences?

I want to recursively copy one directory over another, however I only want to copy differences. The reason is that I'm doing this on Solaris on a volume which is snapshot, i.e. if I'm copying 100gig ...
0
votes
1answer
358 views

Unix cp wildcard with directory structure [duplicate]

Possible Duplicate: How can I copy a subset of files from a directory while preserving the folder structure? I have a bunch of directories like this: /Artists/Example Name ...
1
vote
2answers
1k views

How to avoid cp -r ~/some/folder/ . copying all files to the current folder's top level?

(Update: this happens on Mac OS X -- I am using Mountain Lion.) It sometimes happen that I use the tab key to complete the path, so my command may be: cp -r ~/some/folder/ . but it turns out that ...
0
votes
3answers
2k views

How do I cp the folder, not just the folder content?

Let's say I have folder structure like this: /parentFolder/ folder1/ folder1.1/ file1 folder2/ file2 How do I copy folder2 inside folder1.1 so that file2 is also in ...
4
votes
4answers
1k views

Make cp return an error value if the target exists

Is there a way to make cp (from GNU coreutils on Linux) return a nonzero value in case the target file does already exist? Or is there any other small utility which is commonly available and which ...
3
votes
3answers
543 views

Copy multiple files to one dir with parallel

I'm using the following script to copy multiple files into one folder: { echo $BASE1; echo $BASE2; echo $BASE3; } | parallel cp -a {} $DEST Is there any way to use only one echo $BASE with brace ...
11
votes
3answers
2k views

Flattening a nested directory

This is probably very simple, but I can't figure it out. I have a directory structure like this (dir2 is inside dir1): /dir1 /dir2 | --- file1 | --- file2 What is ...
1
vote
3answers
863 views

Copy files with permission 200

I want to recursively copy a directory, preserving file attributes, which contains a directory tree including some files that have permission 200 (i.e. --w-------). The copy command cp -ar ...
10
votes
3answers
3k views

How does “cp” handle open files?

I'm having two separate directories. The user loads a file into the first. Theres a cronjob running in the background which copies the files every 5 minutes over to the second directory. What happens ...
4
votes
1answer
1k views

copying device nodes

I'm trying to transfer a working Linux installation to a new larger disk, so I've attached the new disk on a USB port, partitioned it and created filesystems. While copying all the files over I hit a ...
5
votes
1answer
406 views

Symbolic links with ls, mv: forcing the functions to utilize “logical” addresses (remembering the original path)

It seems that for many basic functions operating on symbolic links, the physical path is used by default. However, cd works fine. When moving into a symbolic link, cd remembers where I came from so it ...
11
votes
4answers
4k views

Copying a single file to multiple directories using cp

This question is a sequel of sorts to my earlier question, Creating numerous directories using mkdir. I am using the bash shell. I have created fifty directories, each starting with the prefix "s", ...
2
votes
2answers
570 views

How to copy a piped list of files contained spaces and apostrophes?

I have a list of files generated using find that I want to feed (pipe) to cp. My problem is that the files have spaces and apostrophes in them, leading cp to repeatedly complain that it "cannot stat". ...
2
votes
2answers
3k views

Create symbolic links with wildcards

I have multiple hard drives with the same directory hierarchy, for example: /media/sda/dir1 /media/sda/dir2 ... /media/sdb/dir1 /media/sdb/dir2 Two hard drives with similar names and similar ...
1
vote
1answer
144 views

Move some files on every dir to a different dir [duplicate]

Possible Duplicate: How can I move files by type recursively from a directory and its sub-directories to another directory? I'm quite new to Linux and specially to the shell and all of its ...
4
votes
2answers
3k views

Difference between cp -r and cp -a

Looking for the difference between cp -r and cp -a? What does recursive mean in terms of copying files from a folder?
4
votes
4answers
4k views

copying multiple files to multiple directories

I've a problem copying many files in different directories. Let me explain better: Let's say I have the following in a dir: $ ls file1 file2 file3 file4 file5 dir1 dir2 dir3 and I want to copy ...
1
vote
1answer
239 views

Switching source and destination (or undoing the mv, cp operation)

mv or cp commands both expect source and destination as arguments. In case you want to undo the change you made, or just change the source and destination you supplied before, what is the quickest ...
1
vote
2answers
131 views

How to copy a file and move it to a location using unix

I need a file to stay in the same location but also move it to a different location. What am I doing wrong? cp RubyTest.sublime-settings \ ~/Library/Application Support/Sublime\ Text\ ...
2
votes
2answers
130 views

debian dead when copy over 1GB

I have a Debian Squeeze system with an AMD64 processor. When I try copy over 1 GB, the computer dies (no reboot, completely down), and the logs don't contain anything useful. The temperature of the ...
1
vote
1answer
214 views

What happens if a cron script tries to copy a directory at the same time as another process is writing to it?

For example, if I have a java process that (once every 2 hours) takes a backup of a large file, like 500mb, and places it into folder A on HDD A, and I want to schedule a cron script to copy the ...
1
vote
2answers
4k views

Batch copying/moving files in unix?

Is there a way to batch copy/move files in unix? I thought it might be an option for cp/mv but I can't find any way to do it.
2
votes
2answers
153 views

Using cp, what is the difference between copying to DEST and DIRECTORY?

In the man page for cp, what is the difference between copying to DEST and DIRECTORY? cp copies a SOURCE to a DEST and SOURCES to a DIRECTORY. SYNOPSIS cp [OPTION]... [-T] SOURCE DEST cp ...
2
votes
3answers
223 views

Invoking cp from within BASH and using the -u option

Is there a way to have cp's --update option print files that did not copy because the source directory contained a newer version of the file?
5
votes
1answer
1k views

How to replace a symbolic link with a copy of a file it links to?

Having a (single, no batch filesystem processing needed) symlink, what a command line to use to replace it with a copy of the file it links to?
4
votes
2answers
2k views

Permission denied (even as root) on a mounted ISO image with Furius ISO Mount

I mounted a ISO image with Furius ISO Mount. I cd to the mounted directory and tried to copy a file with sudo cp file /dir but cp writes error message cp: cannot stat `file': Permission denied ...
4
votes
3answers
9k views

Copy first n files in a different directory [duplicate]

Possible Duplicate: How to move 100 files from a folder containing thousands? Is it possible to copy only the first 1000 files from a directory to another? Thanks in advance
7
votes
1answer
183 views

Strange behaviour in recursive copy

Could someone explain why this happens? Most specifically: Why is one 1's content copied to f? And why is f copied to g? $ tree . 0 directories, 0 files $ mkdir 1 $ mkdir 2 $ touch 1/a $ touch ...
2
votes
2answers
3k views

How can I selectively copy files from one directory to another directory?

On Linux, how do I selectively copy most – but not all – files from a directory (dir1) to another directory (dir2)? I do not want to copy *.c and *.txt files to dir2. The cp man page ...
1
vote
0answers
463 views

Can't make a copy of /var/lib/mysql/ibdata1

I have a RedHat Linux server and I'm trying to make a copy of /var/lib/mysql/ibdata1, but I'm receiving an error saying permission denied and the file cannot be opened. I'm logged in as root user and ...
2
votes
3answers
1k views

cp launched from code results in cannot stat '/tmp/somedir' works in shell

I'm working on making some scripts more elegant by implementing them in a real x application etc... At some point in the scripts we basically want to take everything from a mounted removable storage ...
4
votes
1answer
439 views

Only use mtime comparison with rsync?

Is it possible to sync files via rsync and let rsync only compare mtime informations? Or is there another tool for this job? That means that such a tool only copies src to destination if the src is ...
4
votes
2answers
3k views

Using regular expressions with cp

This is a simple question. I'm trying to copy all of the files in the current directory that start with "axis-2" and end with ".jar" into a target directory, let's say it's ~/MyDirectory. My first ...
3
votes
1answer
273 views

Copy files in different subdirectories that excludes a string

I'm trying to copy all files of a type in a given directory and subdirectories but excluding files of a different type. find /var/ftp/pub/bs -iname "*foo*.foo" -exec cp {} /var/ftp/pub/bs1 \; ...