Questions tagged [cp]

cp - Command-line tool to copy a file

Copy files.

External reference

cp specification (The Open Group Base Specifications Issue 7, 2018 edition)

763 questions
543
votes
12 answers

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 now owned by root:root. How can I have cp keep the…
Psachnodaimonia
  • 5,555
  • 3
  • 14
  • 8
505
votes
6 answers

How to copy a file from a remote server to a 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 can I do this? I tried scp table…
omega
  • 5,537
  • 5
  • 18
  • 14
336
votes
18 answers

Is it possible to see cp speed and percent copied?

I'm having problems when copying large files using nautilus (it gets stuck). I need to copy, using cp. I would like to know if there are any parameters that shows the % copied and also the transfer speed.
user27807
254
votes
3 answers

Difference between cp -r and cp -a

I'm looking for the difference between cp -r and cp -a. What does "recursive" mean in terms of copying files from a folder?
Randy
  • 2,649
  • 2
  • 14
  • 4
212
votes
7 answers

Copy specific file type keeping the folder structure

I have a folder structure with a bunch of *.csv files scattered across the folders. Now I want to copy all *.csv files to another destination keeping the folder structure. It works by doing: cp --parents *.csv /target cp --parents */*.csv"…
Mojo
110
votes
3 answers

How to copy files from the folder without the folder itself

I'm trying to copy files and subfolders from A folder without the A itself. For instance, A folder contains next: | file1.txt | file2.txt | subfolder1 Executing next command gives me wrong result: sudo cp -r /home/username/A/…
pushandpop
  • 1,336
  • 2
  • 10
  • 11
96
votes
2 answers

How do I copy a symbolic link?

I have a symbolic link to a file in one directory. I would like to have that same link in another directory. How do I copy a symbolic link? I tried to cp the symbolic link but this copies the file it points to instead of the symbolic link itself.
User
  • 2,197
  • 2
  • 20
  • 22
93
votes
6 answers

How to copy a directory recursively using hardlinks for each file

I want to create a "copy" of a directory tree where each file is a hardlink to the original file Example: I have a directory structure: dirA/ dirA/file1 dirA/x/ dirA/x/file2 dirA/y/ dirA/y/file3 Here is the expected result, a "copy" of the…
Gudmundur Orn
  • 1,981
  • 1
  • 11
  • 9
93
votes
5 answers

Difference between cp -r and cp -R (copy command)

cp -r is meant to copy files recursively, and cp -R for copying directories recursively. But I've checked, and both appear to copy both files and directories, the same thing. So, what's the difference actually?
its_me
  • 13,709
  • 23
  • 54
  • 52
82
votes
15 answers

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 what if forgot to do that, cp is running for a very…
Petr
  • 1,691
  • 4
  • 21
  • 31
82
votes
3 answers

Why doesn't cp have a progress bar like wget?

Please note that I don't ask how. I already know options like pv and rsync -P. I want to ask why doesn't cp implement a progress bar, at least as a flag ?
Lamnk
  • 1,450
  • 1
  • 11
  • 10
80
votes
9 answers

How to append date to backup filename

I need to make a backup of a file, and I would like to have a timestamp as part of the name to make it easier to differentiate. How would you inject the current date into a copy command? [root@mongo-test3 ~]# cp foo.txt {,.backup.`date`} cp:…
spuder
  • 17,643
  • 36
  • 91
  • 119
76
votes
6 answers

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 system creates a directory by default called…
ScoobaSteve
  • 861
  • 1
  • 6
  • 4
72
votes
3 answers

Why is my PC freezing while I'm copying a file to a pendrive?

I have a really strange situation here. My PC works fine, at least in most cases, but there's one thing that I can't deal with. When I try to copy a file from my pendrive, everything is ok -- I got 16-19M/s , it works pretty well. But when I try to…
Mikhail Morfikov
  • 10,309
  • 19
  • 69
  • 104
70
votes
6 answers

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 exists, then the clone created will be…
jakub.g
  • 3,153
  • 5
  • 20
  • 17
1
2 3
50 51