cp - Command-line tool to copy a file

learn more… | top users | synonyms

1
vote
1answer
38 views

Is it possible to overwrite a directory with a file in linux

Can someone please help me with a possible case of accidental deletion on a linux box? I ran the following command: cp file1 /newdir1/folder1 What I intended to do was to copy file1 to the pre-...
2
votes
2answers
54 views

Is it possible to display a running timer in a shell script while copying a directory?

So I have a shell script that basicly backs up one server to another server. In the process I have to cp a very large directory (140GB) to another location, in the shell script I would love to have ...
2
votes
0answers
155 views

Copy file if no error was encountered, else delete copied portion

I am copying a folder in Linux with plenty of files. Some of the files give me errors like this: Error splicing file: Input/output error The problem is that it keeps the file in the new location ...
7
votes
3answers
72 views

How to prevent cp from merging two identically-named directories?

I have two identically-named directories: $ ls mydir file1 file2 $ ls other/mydir file3 file4 If I copy mydir to other, the two mydirs get merged: $ cp -r mydir other $ ls other/mydir file1 ...
10
votes
1answer
147 views

How to duplicate a file without copying its data with btrfs?

I have no experience with btrfs, but it's advertised to be able to de-duplicate files. In my application, I'd need to duplicate whole directory trees. From what I learned, btrfs only de-duplicates ...
27
votes
2answers
60k 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?
0
votes
1answer
372 views

Cp with full renamed path in execl c program

I need to copy file and rename it in execl function so i did: if ( fileExists(new_dest) ){ /*function in which i rename the file by gtk dialog*/ renameDialog(fileName); printf("%s\n",...
3
votes
5answers
125 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?
30
votes
11answers
41k views

Is there a faster alternative to cp for copying large files (~20 GB)?

I am a graduate student, and the group in which I work maintains a Linux cluster. Each node of the cluster has its own local disk, but these local disks are relatively small and are not equipped with ...
0
votes
1answer
87 views

Cron to find exec cp and redirect output with time / date per line?

I try to setup a cron task to run a set of basic shell commands. I need to look to any files created on the last day, then copy to another folder and generate a log stating, line by line, the date ...
2
votes
1answer
147 views

How to copy recursively all files not older than 1 day?

How to copy recursively all files not older than 1 day? I first tried find . -amin -1440 | xargs cp /dest But it doesn't work because the items given to xargs should be positionned before the /...
1
vote
2answers
116 views

Combine xargs -I with sed

I want to use find to find certain files and then use xargs with cp and sed to move these files to another folder and rename them. I know how to do this in a loop, but that is not what I am looking ...
2
votes
3answers
2k views

How to copy and add prefix to file names in one step?

I want to copy and rename multiple c source files in a directory. I can copy like this: $ cp *.c $OTHERDIR But I want to give a prefix to all the file names: file.c --> old#file.c How can I ...
1
vote
0answers
71 views

Live OS freezes while copying files

I was trying to backup many files (~10,000) from a hard drive on an OS-less notebook to an external 500 GB HDD, so I booted up the Fedora 22 Live XFCE spin using a USB, started the copy and after 5 ...
13
votes
3answers
664 views

How is install different from cp?

How is install different from a simple copy, cp or dd? I just compiled a little utility and want to add it to /usr/sbin so it becomes available via my PATH variable. Why use one vs the other?
0
votes
0answers
39 views

`cp -iprv` from UFS to NTFS panics FreeBSD and reboots

My nas4free OS seems to be dead, so I mounted its 2GB UFS data partition on my FreeBSD machine, and my 1TB external USB NTFS HDD (using ntfs-3g /source /mnt/dest). I tried the casual cp -iprv /SOURCE /...
3
votes
1answer
43 views

cp command which partially resolves symlinks

Is there an easy way to copy a directory recursively where symlinks to external files/directories are resolved (target file is copied), but internal symlinks (pointing to files inside the copied tree) ...
1
vote
3answers
219 views

What is the output of “du” command during a long copy?

Recently, I launched the cp command to create a backup of a big directory. So, I used a command like this: cp -rv big_directory new_location Because the files are big, it took a long time to ...
3
votes
1answer
58 views

OpenBSD: Move directories larger than X to new directory

I'm accessing OpenBSD via SSH and I'm wanting to create a command to find directories larger than 20MB and copy them to a new directory, keeping all folder structure. So far I have this: find /...
157
votes
7answers
259k views

How do I copy a folder keeping owners and permissions intact?

So I was going to back up my home folder by copying it to an external drive as follows: sudo cp -r /home/my_home /media/backup/my_home With the result that all folders on the external drives are ...
0
votes
2answers
252 views

Copy a full folder to another location on the same server

I would like to make a backup of a WordPress uploads folder from a a master site to a development site. I thought I would give this code a try: cp -urp /home/my_site/public_html/wp-content/uploads/* ...
0
votes
1answer
43 views

FreeBSD 9.3 and OSX color tags

I am using nas4Free 9.3.2 and FreeBSD 9.3-RELEASE-p22. I noticed after using cp, that my moved files no longer had the color coded labels I had applied in OSX. Share mounted in AFP. To test this, I ...
3
votes
2answers
4k views

How to view progress with sshpass and scp in linux?

In my Linux terminal, I am using this command sshpass -p "pass" scp -r me8@host.ca:/cmshome/me/file /home/me/Desktop to download a file with a password in it. Without the sshpass, I can see the ...
4
votes
1answer
55 views

How to ensure proper file permissions when running installer bash as sudo?

I am making a installer bash, playing with it a little too. But I just came across a serious problem: As I run the bash with sudo ./install.sh, all the files it copies are owned by root and therefore ...
0
votes
1answer
330 views

Copy all files matching criteria on find command with -exec

Below are my attempts at copying all files except .out and .class files into a subdirectory titled homework21/. Note homework21 is a subdirectory of the folder in which I am working in. me@ice4:~/...
18
votes
2answers
2k views

What is the difference between * and *.* while copying?

What is the difference between following 2 commands? cp -rp /dir1/*.* /dir2/ cp -rp /dir1/* /dir2/
-2
votes
3answers
541 views

Understanding permissions properly for cp [duplicate]

I am trying to understand the permission usage for the cp command in unix. What are the permissions required for copying a file into a directory What are the permissions required for copying out of ...
37
votes
3answers
31k views

Why unix mv program doesn't need -R (recursive) option for directories but cp does need it?

This is a kind of "wtf?" question, so I'm sorry if I will disturb someone's vision of how things should be or if I will just annoy you with the "stupid" question. I always get messed up when need to ...
2
votes
2answers
15k views

copy files modified after specific date using cp switches

When I execute the command find . -mtime -60 I get the list of files modified within the last 60 days. So when I execute find . -mtime -60 -exec cp {} /tmp/1 \; I can copy these files to a new ...
29
votes
6answers
1k views

How to copy a folder recursively in an idempotent way using cp?

When I use cp -R inputFolder outputFolder the result is context-dependent: if outputFolder does not exist, it will be created, and the cloned folder path will be outputFolder. if outputFolder ...
-2
votes
1answer
89 views

Error while trying to copy file to many files using cp [closed]

Error when running this command, I think the command is clear to get the idea. cp file.txt /folder/*/*/*/file.txt I found out cp dosen't support *, so how can I do the same thing in bash or command-...
6
votes
2answers
18k views

faster alternative to cp -a

For a simple transfer of /home to another disk i use cp -a that seems to me an extremely slow way. Should like know a more efficient way to complete the task. I have /home mounted as logical volume, ...
1
vote
1answer
621 views

Text file busy when I copy some files

I have this error when I want to copy some files My command: cp -rf /sasech/xgedff/pur/liv/v15h30050-DLIV0177521/dmesa/bin/* /applis/rgedff/pur/bin Results: cp: /applis/rgedff/pur/bin/../bin/lib/...
17
votes
5answers
2k views

Why use diff/patch when it is easier to just use cp

diff -u file1.txt file2.txt > patchfile creates a patch file which consists of instruction for patch to convert file1.txt to be exactly like file2.txt As the title says, Can't this be done using ...
2
votes
0answers
28 views

Files appear in a different timezone after transferring to another computer (even though both computers have same timezone) [closed]

I copied some files from an Archlinux computer to an Ubuntu one, but the time on the files after being moved showed as exactly 2 hours earlier than on the computer they were originally. (2 hours I'm ...
2
votes
1answer
30 views

Copying directories unrelated file names

Apologies for the dumb question. I'm trying to copy directories of data sets that pertain to the a certain case but the data sets are currently stored in different directories and with different (non ...
20
votes
4answers
1k views

Surprised by behavior of cp with hardlinks

I understand the notion of hardlinks very well, and have read the man pages for basic tools like cp --- and even the recent POSIX specs --- a number of times. Still I was surprised to observe the ...
-1
votes
2answers
60 views

Is there a variant of the “cp -a” command that avoids copying from other filesystems?

Let's say I have a directory /data/something with the following subdirs: /data/something/iowa /data/something/wyoming /data/something/burkinafaso /data/something/slovenia All four subdirs have ...
1
vote
1answer
102 views

Folder permissions with cp --parents doesn't allow to copy another file

Scenario: with a script run by a normal user I want to copy several files, and replicate the dir structure. For example: cp --parents /lib/libacl.so /tmp/my_root/ cp --parents /lib/libc.so.6 /tmp/...
1
vote
2answers
186 views

What command should I use to move these particular elements?

Here is my initial situation: In a folder named for example Father, are stored some files in the following way: Father contains 24 children folders (let's call them Child1, Child2, ...), and each one ...
0
votes
1answer
166 views

How to backup all the files that I'm copying before being overwritten?

I have a folder like this: ./folder-a/index.html ./folder-b/index.html ./folder-c/subdir/index.html ./new-content/folder-a/index.html ./new-content/folder-b/index.html ./new-content/folder-c/subdir/...
0
votes
1answer
248 views

Argument list too long with just 5000 files [duplicate]

I have a folder with 5000 files that I want to copy somewhere else. When I do cp ../folder* ., I get the following error: -bash: /bin/cp: Argument list too long However, getconf ARG_MAX returns ...
0
votes
2answers
3k views

How to use cp command in bash script to copy files with spaces ans $ characters in it? [duplicate]

I am trying to copy some files with spaces and $, @ symbols in their file names in a bash script but the script fails to copy the files stating it cannot find the file. I can see that it is treating ...
0
votes
1answer
33 views

Folder organization

I have several folders ("amazon", "niger", "rhine",...). Inside each of them I have several subfolders ("gfdl", "hadgem", "ipsl",...). Each subfolders is composed by 5 subfolders (e.g. in "amazon", ...
7
votes
1answer
857 views

Why does “cp -R --reflink=always” perform a standard copy on a btrfs filesystem?

Btrfs support Copy-On-Write. I tried to use that feature to clone a directory: cp -R --reflink=always foo_directory foo_directory.mirror I expected the command to finish almost instantly (like a ...
0
votes
0answers
11 views

csp where both source and destination are local or how to make cp show a progress bar [duplicate]

csp shows a nice progress bar when copying a file to/from a remote host. Since cp doesn't have such a nicety, it ocurred to me that I could use scp to copy files in the same machine (no remote host), ...
1
vote
2answers
139 views

Randomly copy certain amount of certain file type from one directory into another

Sometimes I have a folder full of jpg's and I need to randomly choose 8 or so of them. How could I automate this so my account randomly chooses 8 jpg's from the folder and copies them to another ...
4
votes
3answers
441 views

How to copy recursively and change file names to be unique

I have a large tree containing a lot of photos on an external drive that was formatted with one of the linux filesystem types (don't remember which one). It's mounted on my mac and I'm trying to copy ...
5
votes
2answers
199 views

`sudo cp -a` changes ownership to root (instead of preserving the original user)

I was trying to backup some directories and some of the copies made by sudo cp -av resulted in being owned by root while others preserved their attributes. Is this a known issue or am I missing ...
1
vote
1answer
189 views

What is the actual process name when nautilus is copying files?

I am copying some files from an external drive to my desktop running Ubuntu. I can see the "File Operations" dialog which shows copying process. How do I find this particular process in ps aux | grep ...