Questions tagged [cp]

cp is the command of the Unix operating system that is used to copy files.

Filter by
Sorted by
Tagged with
4 votes
1 answer
18k views

Linux issues with cp: -r not specified; omitting directory

Can someone help me understand what that means? cp: -r not specified; omitting directory I am trying to use this command sudo cp /home/$USER/Documents/myfile.10 /home Error: cp: -r not specified; ...
James Collis's user avatar
4 votes
2 answers
3k views

Wildcard not working in cp command when using exec

I want to copy all the files in all the directories to the parent directory, but I get the error ./img/* is not a directory For example. Here is the command that I used. Is there a better way to do ...
m0meni's user avatar
  • 155
4 votes
1 answer
2k views

How can I avoid that cp freezes my OS?

I am using cp to copy data like so: cp -r from_here to_there When I do that, my computer freezes and unfreezes periodically. I have 4 CPUs installed and the HD is connected via SATA. from_here and ...
Woltan's user avatar
  • 43
4 votes
5 answers
5k views

Using cp command in linux shell, how do I copy a whole directory into another directory?

I have a directory, let's say, "work": ~/work/ This directory has some sub-folders (d1, d2...) in it and files in these sub-folders. I want to make a backup copy in the same folder, so it would be ...
Vilmar's user avatar
  • 141
4 votes
4 answers
542 views

Why does "cp -r a/. b" behave as it does?

I thought that a and a/. is the same path. However, I've found that cp and rsync copy directory content instead of directory itself when /. is added to the source path. I also tried a/inner/..; this ...
raacer's user avatar
  • 563
3 votes
2 answers
3k views

Unix copy for each line in file

I have a file, file_copy, which has: >cat file_copy file1 file2 file3 I want to copy file1, file2, file3 from /source to /dest. One way I know how to do this is to just do: for line in `cat ...
prelic's user avatar
  • 45
3 votes
2 answers
14k views

How to copy all files recursively excluding folders into one destination folder?

I have several folders like /music/1/a.mp3 and /music/2/b.mp3 All of the file names themselves are guaranteed to be different. Is there a way, probably using the Terminal, to copy these files to /...
samiles's user avatar
  • 131
3 votes
7 answers
2k views

How do I make "cp" in OS X not delete files?

Here's the best way to describe this: dirA dir1 file1.txt file3.txt dirB dir1 file1.txt file2.txt I want to copy the contents of dirB into dirA. cp -R dirB/* dirA ...
SkippyFlipjack's user avatar
3 votes
3 answers
3k views

How to copy one file into multiple subfolders at once on a Linux server?

I have a folder on a Linux server with 35+ subdirectories, along the lines of: aa.foo.bar.baz ab.foo.bar.baz .. bp.foo.bar.baz I have a file that I want to copy into each of those subdirectories. ...
Matt V.'s user avatar
  • 165
3 votes
4 answers
21k views

how to copy all files from one location to another in linux

I want to copy all the folders and files in the /var/www/ directory to another directory /media/magneto/ How do I do this? I tried this command cp -pRiv /var/www/ /media/magneto/ that didn't ...
Jason's user avatar
  • 1,899
3 votes
3 answers
11k views

cp - do not overwrite in makefile

In the makefile for my project, I want it to copy a config file only if the file does not already exist in the destination folder. At the moment I am using: cp -n However, recently someone has ...
SlappyTheFish's user avatar
3 votes
4 answers
7k views

cp verbose alternative

I want to list all of the files that are being copied by a cp command but the -v switch doesn't seem to exist on the servers here at work. I'm not sure exactly which OS this is. I think it might be ...
A Jackson's user avatar
  • 1,027
3 votes
1 answer
2k views

AWS S3 cp does not download 40 GB file

I just uploaded a 40GB backup file from my linux EC2 machine to an S3 bucket. However when I want to download it the aws command ends with no message and nothing was copied. Here is my command: ...
Jörg Rech's user avatar
3 votes
3 answers
4k views

"cp --parents" equivalent on Mac

The topic explains it -- basically I have a bash script used on a Linux system and a Windows system with Cygwin where the following command works perfectly: cp --parents However, running this same ...
udjamaflip's user avatar
3 votes
1 answer
1k views

copying a file to a hard link

I recently got bit by a misbehaving in a bash script of mine and was wondering: is this the expected system behavior, or is it a bug what are the ideal workarounds Essentially, the problem boiled ...
Evan Teran's user avatar
3 votes
1 answer
2k views

Optimal Linux copy command for large number of files

This is a topic I have not been able to find a definitive answer on, or at least one with a good explanation on why one solution is better than the other. Lets say I have two local drives, one with ...
sudosnake's user avatar
3 votes
2 answers
7k views

OS X - copy files issue - Resource busy

Calling all OS X experts. I copied two 1Tb drives (ex-Windows) onto a new 2Tb USB 3.0 drive using Finder on the Mac (OS X 10.9). The 2Tb drive is now about 90% full. I now want to duplicate that ...
Dave F's user avatar
  • 53
3 votes
1 answer
415 views

File dates copied with "cp -p" are set to "now"

I'm using my Mac to try to copy the content of a smartphone's SD card to a larger card. Because I don't want all the pictures to get new creation dates I used the --preserve option like this: cp -pr /...
Norbert's user avatar
  • 181
3 votes
2 answers
5k views

Are cp/rsync asynchronous?

We're running a backup script which first copies a file to a destination and then runs tar over it. DIR2BCK='/foo/bar' TMPDIR=$(mktemp -d) rsync -a ${DIR2BCK} ${TMPDIR}/ > /dev/null 2>&1 ...
nKn's user avatar
  • 5,667
2 votes
2 answers
11k views

Linux cp command is not silent

I know with a -f cp should be silent but it's not! I do cp -rf Functional Functionalssssssss and if Functional does not exist, it says cannot stat 'Functional'... but I just don't want to see the ...
Cher's user avatar
  • 191
2 votes
4 answers
5k views

cp command force

currently there's a xxx dir already in /home/yyy I'm trying to overwrite it cp -fr ../xxx /home/yyy/ doesn't work still prompts me to overwrite the individual files. how do I fix it?
user15586's user avatar
  • 657
2 votes
3 answers
954 views

Copied directory appears to become larger at destination

I have the following code as part of a shell script: while [ $(ps -ef | awk '{print $2}' | grep -F "$CPPID") ]; do sleep 10 awk -v "usbsize=$(/bin/df | grep -F $DEVICEMOUNTPOINTQ | awk '{...
Matthieu Cartier's user avatar
2 votes
1 answer
995 views

Unix command for recursively copying files

I need a unix command for the following: Directory Structure /project /images /products /cup.jpg /laptop.jpg /designs /alpha.jpg /...
ThomasReggi's user avatar
2 votes
1 answer
9k views

In Linux copy file and overwrite only if target is older [duplicate]

How in Linux using cp one can copy file to destination, but if destination exists, then overwrite only if destination is older than source? cp -f always overwrites, but overwrite is needed only if ...
vladon's user avatar
  • 351
2 votes
2 answers
2k views

How to make a copy of file in the same directory

This creates a file in the same directy as 'some.file.bak'. find /home/ -ipath "*/temp/some.file" -type f -exec cp {} {}.bak \; How to make a copy in another name such as 'another.file' in the ...
13th Matrix's user avatar
2 votes
1 answer
3k views

Linux: Copy files with dates in filename between two dates

I have a folder full of files where I from time to time need to copy a subset of these to somewhere else for processing. The files have the date they were created in the filename, i.e. ...
Henrik Nielsen's user avatar
2 votes
2 answers
149 views

I somehow made our linux box's "CP" command act differently than the default, how can I revert it back to default?

Title explains it; Somehow in installing the 'z' directory jumper, I made our linux machines CP command act strangely (for example: it no longer prompts for overwrites, it auto-forces it whether we ...
Samuel Stiles's user avatar
2 votes
2 answers
110 views

Running cp -r ~/.ipython ~/some/path/.ipython a second time creates ~/some/path/.ipython/.ipython. How to prevent that?

I am using a script to copy directories to a specified location. When I run cp -r ~/.ipython ~/some/path/.ipython the .ipython dir is copied as expected to the specified location. But when I run this ...
Bentley4's user avatar
  • 1,928
2 votes
1 answer
3k views

ssh Mac Unix: copy a file with special characters and spaces

I am remote logged into a Mac and trying to copy a music file from one directory to another, but I am getting an error. I think it's caused by spaces or special characters, but not sure. the file is:...
OWolf's user avatar
  • 135
2 votes
3 answers
466 views

In Power SHell set alias cp to cp -v

I have cp for power shell. But I want to use cp in verbose mode without writing -v. So cp should be aliased to "cp -v" command. How to alias cp to "cp -v" in power shell?
Narek's user avatar
  • 1,421
2 votes
1 answer
540 views

Why is midnight commander able to copy files so much faster than cp?

I discovered an interesting behavior of mc. When I copy files across devices (at least those that are smaller than free RAM) it seems that the copy is using writeback cache and is nearly instant (on ...
Petr's user avatar
  • 2,341
2 votes
2 answers
2k views

How to display filename only as an output of cp command?

I'm copying files from src folder to dest folder usign the command: cp -nv /src/* /dest/ > copy_result.txt The result of copied files is in the output file as shown below: « /src/test1.txt » -&...
Angelika's user avatar
2 votes
1 answer
1k views

Copy files and rename them by creation date

i have a few directories (1 level) that were added to my server in specific times. the problem is, they are named as a random hash. would it be possible to copy them somewhere and rename by the ...
user1916182's user avatar
2 votes
2 answers
6k views

cp --update still copies unchanged files

I'm trying to copy only changed files using 'cp -pu' under Linux (Red Hat 6.1, source/destination FS are GlusterFS mounted partitions) but I found that it still tries to copy file seemingly old and ...
teddy's user avatar
  • 121
2 votes
3 answers
5k views

Allow limited cp access to a sudo enabled user

We have several tier2 admins whom have very limited admin rights granted via sudo; As they have limited experience we really want to put them into a tight set of operations they can perform. One of ...
AJM's user avatar
  • 83
2 votes
2 answers
349 views

Why Can't I copy a folder to a disk that is larger than my folder?

I am using ubuntu 18.04-4 and want to move a large directory (yocto build directory for my project) from my ~/Desktop to an external drive (ext4 formatted). The external drive is a 512 GB empty drive. ...
Dis Play Name's user avatar
2 votes
1 answer
115 views

Copy everything in a subdirectory across to the relevant subdirectory elsewhere

At the moment I'm doing: for i in mdx/[0-9][0-9].png; do cp $i ../../d_s_c/images/mdx ; done But as well as the directory mdx, I also have other directories called ntt, etc. How can I say 'For ...
Richard's user avatar
  • 995
2 votes
0 answers
49 views

Copy symbolic link and its target subdir to new dir

I have a dir with a symbolic-linked subdirectory: greg:/testA> ls foo -> alice alice/ I need to copy the link "foo-> alice" (preserve it at destination) AND the subdirectory alice/ to a new ...
G. D'Seas's user avatar
2 votes
1 answer
2k views

Mac High Sierra cp command returns "Result too large"

Having a devil of a time figuring this out. I've got the latest MacOSX (10.13.2). I am trying to copy a file to an external drive for my backups. Ran into an error where cp returns "Result too ...
Mark Mumy's user avatar
2 votes
0 answers
691 views

How to preserve file mode attributes with cygwin cp command on Windows 10?

The same cygwin version 1.5.25 is installed on Windows 7 and Windows 10. With a perl script using the stat command, I see the source file mode is 666. The source file is a simple text file. After ...
Maxime Fortin's user avatar
2 votes
0 answers
154 views

Copying LibreOffice from DMG to local SSD takes 35 minutes - cp takes 3 minutes

Today I downloaded the latest version of LibreOffice for my Mac. After downloading, I opened the DMG file and copied the app-folder to the Applications. This took 35 minutes for a 700 MB folder. At ...
SPRBRN's user avatar
  • 7,752
2 votes
1 answer
190 views

Terminal: cp -r with directories with same name and different case

I'm trying to copy around ~250Gb from one drive to another. Catch is that the destination drive is formatted in NTFS or FAT or something and isn't case-sensitive, and I've got folders I need to copy ...
t56k's user avatar
  • 131
2 votes
0 answers
2k views

How can I copy files recursively without overwriting the directories

On linux, let's say I have some files like this: dir1/file1 dir2/file2 and I want to copy them to a destination that already have dir1 and dir2 and looks like: dir1/file1 dir1/file1a dir2/file2 ...
Bruce's user avatar
  • 161
2 votes
1 answer
791 views

Symlink all files but copy certain extensions

I'm wondering how I'd be able to symlink all the files in a dir structure and then also copy files of a certain extension in that dir. I'm basically symlinking all files within /foo/a,b,c to /bar/a,b,...
Mike's user avatar
  • 23
1 vote
3 answers
29k views

how to copy a directory (folder and its contents) to another directory?

Here is my file structure: - someDirA - folderOne - folderTwo - somefile.txt - someotherfile.txt - someDirB - somefolder What I want 'someDirB' to look like: - someDirB - ...
dave's user avatar
  • 703
1 vote
1 answer
71 views

Query on "cp" command

I have a directory say ~/MyWorks which contains the following files in it: a.c, b.c and c.c I want to copy the MyWorks directory to ~/MyAssignments such that only the directory MyWorks is copied and ...
LinuxPenseur's user avatar
1 vote
3 answers
10k views

Copy multiple files via cp from a string

I'm trying to copy multiple files to a directory from within a shellscript. These files contain all sorts of "ugly" characters, such as whitespaces, brackets and what not else. However, I'm stuck when ...
MechMK1's user avatar
  • 1,744
1 vote
3 answers
181 views

How do you distinguish a directory, and it's contents in linux?

Let's say you have this directory tree parent -----child1 -----file0 -----grandchild1 -----file1 -----file2 -----...
user893730's user avatar
  • 1,217
1 vote
2 answers
3k views

Move and rename files based on their parent's directory

I have a collection of directories that all contain a particular file that is named the same in all the directories. dir1/dirA/file.txt dir1/dirB/file.txt dir1/dirC/file.txt .... dir4/dirX/file.txt ...
dantiston's user avatar
  • 140
1 vote
2 answers
4k views

Get all files from a directory without read permissions?

In Linux/Unix, if I am inside a directory of another user, but cannot view the contents of the directory by typing "ls," how do I get a copy of all the files? Is the only way to guess what the file ...
Trevor Hickey's user avatar