Questions tagged [cp]

cp is a UNIX command used to copy a file

Description

cp copies SOURCE to the destination DEST, or multiple SOURCE(s) to directory DIRECTORY.

Syntax

cp [OPTION]... [-T] SOURCE DEST

cp [OPTION]... SOURCE... DIRECTORY

cp [OPTION]... -t DIRECTORY SOURCE...

Related commands

824 questions
32
votes
1 answer

linux copy symbolic link

How do I copy a symbolic link from one directory to another? ls -ls file1.txt file2.txt files -> /mnt/iscsi-nfs-share/faulttracker-files what I'm looking to do is copy files symbolic link into another directory? cp files /var/copylinktohere/ the…
Robbo_UK
  • 11,351
  • 25
  • 81
  • 117
31
votes
2 answers

Linux cp command to copy a folder to current directory

I am wondering if there is an identical command for copying a folder to current directory like it did using the old MS-DOS. Let's say my current directory location is: /var/www/ I have folders and files…
user702300
  • 1,211
  • 5
  • 22
  • 32
30
votes
5 answers

How to avoid 'are the same file' warning message when using cp in Linux?

I'm trying to copy certain files from one directory to another. Using this command find "$HOME" -name '*.txt' -type f -print0 | xargs -0 cp -t $HOME/newdir I get an warning message saying cp: '/home/me/newdir/logfile.txt' and…
Matkrupp
  • 781
  • 5
  • 12
  • 17
24
votes
3 answers

Python Subprocess Error in using "cp"

I was trying to use subprocess calls to perform a copy operation (code below): import subprocess pr1 = subprocess.call(['cp','-r','./testdir1/*','./testdir2/'], shell = True) and I got an error saying: cp: missing file operand Try `cp --help' for…
Tapajit Dey
  • 1,327
  • 2
  • 13
  • 22
22
votes
4 answers

Copy every file of entire directory structure into base path of another

I have a directory-tree with a lot of files in it. I'd like to copy all of those files into one new directory, but with all files located in the base of the folder. So I have something like this: images ├── avatar.png ├── bg.jpg ├──…
csch
  • 4,496
  • 2
  • 19
  • 23
21
votes
3 answers

Why is my Bash script adding to the beginning of files?

I've written a script that cleans up .csv files, removing some bad commas and bad quotes (bad, means they break an in house program we use to transform these files) using sed: # remove all commas, and re-insert the good commas using…
SDGuero
  • 487
  • 1
  • 4
  • 12
20
votes
13 answers

How to resolve /var/www copy/write permission denied?

I am a newbie in php, mysql. I have written a hello.php script, which I am trying to copy into /var/www directory (and will later want to open it through web browser). The problem with the same is that I am not allowed to save/write any files in…
shubster
  • 825
  • 4
  • 13
  • 39
19
votes
4 answers

bash command to copy file from one computer to another

Wasn't quite sure how to word this but let's say I've used ssh to remote into my friends MacBook (macbook_b) from my MacBook (macbook_a). What command would I use to copy a file/directory to my MacBook (macbook_a) from my friends MacBook…
MorganR
  • 619
  • 3
  • 11
  • 22
18
votes
4 answers

OS X cp command in Terminal - No such file or directory

this might be one of those days my brain just does not work, or i'm incredibly dumb. i've been trying to copy files (which are actually directories .app, .bundle, etc.) but consistently get an error 'No such file or directory'. i've tried every…
Cocoa Puffs
  • 724
  • 2
  • 8
  • 16
16
votes
6 answers

How to copy multiple files from container to host using docker cp

I want to use wildcard to select multiple files from a directory in a container and use docker cp to copy these files from container to docker host. I couldn't find if support for using wildcard is available with docker cp yet or not. docker cp…
Lucky Tyagi
  • 199
  • 1
  • 3
  • 12
16
votes
1 answer

How to copy files found with grep

I am running this command to find all my files that contain (with help of regex)"someStrings" in a tree directory. grep -lir '^beginString' ./ -exec cp -r {} /home/user/DestinationFolder \; It found files like this: FOLDER a.txt -->SUBFOLDER …
user6372336
  • 163
  • 1
  • 1
  • 4
14
votes
3 answers

cpio VS tar and cp

I just learned that cpio has three modes: copy-out, copy-in and pass-through. I was wondering what are the advantages and disadvantages of cpio under copy-out and copy-in modes over tar. When is it better to use cpio and when to use tar? Similar…
Tim
  • 1
  • 141
  • 372
  • 590
14
votes
1 answer

how to output success or failure of cp command to file

I'm going to be running a shell script containing a CP command using a scheduled cron job. I would like to include in the script something to output to a log file whether the copy was successful or failed. Appreciate any advice in advance. Thanks
user2841861
  • 423
  • 2
  • 8
  • 22
13
votes
2 answers

How to copy files and give them permission of destination directory

I am copying files from source to location. The source is not owned by me and the permission for files at source is ----rwx---. The permission of files coped to destination directory which is owned by me is ----r-x---. The permission of destination…
Nasreddin
  • 1,509
  • 9
  • 31
  • 36
13
votes
1 answer

Using variable with cp in bash

The file returned will have spaces in the file name so I run the file name through sed to append quotes at the beginning and end. However, when I use $CF with cp it fails. If I manually echo $CF and use the resulting file in place of $CF it works…
Todd
  • 652
  • 2
  • 19
  • 37
1 2
3
54 55