cp - Command-line tool to copy a file

learn more… | top users | synonyms

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
2k 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
2answers
686 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 ...
14
votes
3answers
4k 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
1k 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
522 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
5k 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
660 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". ...
1
vote
1answer
152 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
5k 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
5k 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
274 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
137 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
133 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
249 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 ...
2
votes
2answers
5k 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
181 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 ...
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 ...
5
votes
3answers
12k 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
192 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
521 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
510 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
4k 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
297 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 \; ...
5
votes
1answer
397 views

ACL mask does not work as expected

If I copy a file with a base ACL of: u::rw-,g::r--,o::r-- into a directory with a default ACL of: u::rwx,g::r-x,g:users:rwx,m::rwx,o::r-x I obtain a file with mask of m::r--. I would have ...
3
votes
3answers
346 views

Delete files in a directory which are also in another directory

I copied a directory using this: cp -r dir/ ../../ without thinking and realized that it copied the contents of dir instead of actually dir to the above directory. Now I have a mess of files I need ...
4
votes
3answers
3k views

How do I move some but not all files from one directory to another?

I need to move my files from one directory to other. But there is some issues. My file name pattern is like: apple.0, apple.<n>, n -> {0,1,2,3 ...~ } so mv apple.* will not work, because ...
2
votes
2answers
312 views

How to update a content management installation by overwriting existing files via ssh and shell?

I have installed a cms (modx) on a webserver running CentOS 5 and Apache 2.2. Now there is a new version and I would like to update it. The instructions in the modx-wiki suggest to overwrite the ...
6
votes
5answers
4k views

How to copy all html files from a directory tree to a single directory?

I want to copy all the .html files in myDir and its subdirectories to ~/otherDir. Here's what I tried (it doesn't work): $ find myDir -name *.html -print | xargs -0 cp ~/otherDir usage: cp [-R [-H | ...
1
vote
2answers
1k views

Is there a BASH command for copying all files from a directory tree and putting all the files in a single directory?

I have a ton of notes categorized into folders, but I think it might be better to put them all into one folder instead. Is there an easy way to do that?
2
votes
2answers
2k views

Copy multiple files and append to end of filename

Seems like I really shouldn't need to create a script for this. I'd like to do something cp /etc/*.conf $1.orig or cp /etc/{a.conf,b.conf} _firstarg_.orig Is there a quick and painless way of doing ...
4
votes
1answer
2k views

Batch copy and rename with regexp

I am wondering whether there is a way how to copy and rename a bunch of files without scripting. I have files with names like prefix_12345678901_12345678901_suffix.ext and I need to copy all of them ...
7
votes
4answers
15k views

Copy multiple files from filename X to filename Y?

I'm pretty noob when it comes to unix commands. What I want to do is to copy files within a lexicographic range. Example of files: -rw-r--r-- 1 root root 15276 Oct 5 2004 a2ps.cfg -rw-r--r-- ...
5
votes
2answers
1k views

Copy from linux to windows every minute

I currently quickly setup a way to copy files from my linux machine to a windows share that multiple people can access, but I'm looking for a better way. In Windows 7, I made a folder accessible to ...
0
votes
2answers
624 views

SSH Copy Limit?

So I have a small little Ubuntu server set up, with some rather large files that I've allowed a few people to copy from their putty window. Anyways 2 questions: Lets say a person on windows wants to ...
4
votes
4answers
1k views

Copy text from one terminal into another

I am logged into ssh to a university account from my home computer. Then I find a file that I want to copy onto my local system. So I open a new shell terminal and am about to use scp to copy that ...
0
votes
1answer
1k views

Why can I not copy a direcotry from *nix to a mounted smbfs share on Windows 7?

I've mounted a Windows 7 directory on my FreeBSD box via smbfs: mount ... //ROOT@BARYONYX/GVKV on /usr/home/gvkv/win (smbfs) but for some reason when I try to copy a directory: cp .vim /win I ...
10
votes
3answers
7k views

copy recursively except hidden directory

How do I copy recursively like cp -rf *, but excluding hidden directories (directories starting with .) and their contents?