cp - Command-line tool to copy a file

learn more… | top users | synonyms

10
votes
1answer
13k views

Unzip file contents, but without creating archive folder

I have a file myarchive.zip that contains many directories, files, etc. Let's say this myarchive.zip file lives in a directory called "b". Well, when I use the "unzip myarchive.zip" command, the ...
0
votes
0answers
21 views

cp error “usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file target_file” [closed]

Whenever I do cp -Rf /Users/gideonmorrow/Public /Users/gideonmorrow/Google Drive/Computer Backup/Users/gideonmorrow/Public/ it gives a error saying usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] ...
0
votes
0answers
19 views

Will exiting SSH session cancel CP? [duplicate]

I have SSHed onto a CentOS server and initiated a CP from one directory on the server, to another directory on the server. If I exit my session, will the CP cancel? If so, is there a way to exit the ...
3
votes
2answers
86 views

How to use cp -u on a Solaris system which does not support the -u option?

I am new in here. I am facing problem in Solaris system.I want to copy only when the SOURCE file is newer than the destination file or when the destination file is missing. As you know, this feature ...
-2
votes
1answer
33 views

What does the -p option do exactly with the cp command?

So I am trying to understand what is the significance of the -p option for the cp command. I opened the manual of the cp command and it says -p same as --preserve=mode,ownership,time stamps. But ...
-2
votes
3answers
71 views

What does `cp -x` do?

I know in the man pages it puts it as -x, --one-file-system stay on this file system but can someone explain it to me like I'm five.
4
votes
2answers
274 views

How to wait for the copying process (cp) to finish?

I want my RPi 2 (with MiniBian (a minimal version of Debian-based Raspbian OS) as its OS) to execute a script when it detects a USB flash memory is inserted. So this is what I have done: I created ...
1
vote
1answer
62 views

Why can't I copy symbolic links?

cp: cannot create symbolic link ‘/xyz/pdq’: Operation not permitted So, I'm trying to copy one directory to a Veracrypt encrypted USB stick. Command I used was: cp -aL /source /destination I've ...
1
vote
1answer
35 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 ...
3
votes
3answers
28k views

Copy only regular files from one directory to another

I'd like to copy a content of directory 1 to directory 2. However, I'd like to only copy files (and not directories) from my directory 1. How can I do that ? cp dir1/* dir2/* then I still have the ...
2
votes
2answers
38 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
144 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
66 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 ...
8
votes
1answer
81 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 ...
17
votes
2answers
42k 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?
5
votes
2answers
34k views

How to copy a file from remote server to local machine?

In my terminal shell, I ssh'ed into a remote server, and I cd to the directory I want. Now in this directory, there is a file called table that I want to copy to my local machine /home/me/Desktop. How ...
0
votes
1answer
105 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); ...
3
votes
5answers
121 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
34k 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
55 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
115 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
59 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 ...
28
votes
10answers
48k views

How to check progress of running cp?

Is it possible to check the progress of running cp process? Some processes respond to various KILL signals so that you can check what is their status. I know that I can run cp with parameter -v but ...
2
votes
3answers
935 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
39 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
602 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
31 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
32 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) ...
82
votes
8answers
94k views

Is it possible to see cp speed and % copied?

I'm having problems when copy large files using nautilus (it gets stuck) so I need to copy using cp. I would like to know if there is any parameter that shows the % copied and also the transfer ...
1
vote
3answers
107 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
41 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 ...
128
votes
7answers
216k 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
70 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
41 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 ...
2
votes
2answers
2k 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 ...
3
votes
1answer
44 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
129 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. ...
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
117 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 ...
34
votes
3answers
26k 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
11k 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 ...
27
votes
6answers
988 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
57 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 ...
5
votes
2answers
16k 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
123 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: ...
17
votes
5answers
1k 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
25 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
28 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
989 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 ...