cp - Command-line tool to copy a file

learn more… | top users | synonyms

2
votes
3answers
120 views

How to I copy the directory and subfolders but ignore certain files in the subfolder?

I believe the question is best asked with an example. /home test1.txt test2.txt /home/my-folder test3.txt test4.txt test1.txt, test2.txt and my-folder folder are inside /home. ...
-1
votes
1answer
10 views

Copy Month wise folders

Main_Dir | --------------------------------------------------------------------- Subdir1 ...
2
votes
1answer
36 views

Is `--reflink=auto` safe to set as default for cp?

I am currently a user of BTRFS and would like to take advantage of the CoW such that when files are copied on the same btrfs filesystem, they are automatically deduplicated by reusing the existing ...
0
votes
1answer
24 views

Copying files containing specific text preserving directory structure

Using the code in this answer, I can easily copy a file containing specific text from one folder to another. With the -r option I can also search inside directories recursively. The result is that ...
2
votes
2answers
39 views

Copy certain files from specified subdirectories into a separate subdirectory

I want to copy all .fastq files from every subdirectory that ends in '_CSF' into another already created subdirectory, dir1_CSF. I understand how to copy certain files but not from certain ...
0
votes
1answer
56 views

Are cp -r and cp -R the same? [duplicate]

A tutorial shows cp -r http://cli.learncodethehardway.org/book/ex10.html but http://ss64.com/osx/ only shows -R.
0
votes
0answers
19 views

What is the bash path difference if asterisk is inside doublequotes or outside doublequotes? [duplicate]

Task is to copy all the files (*). I have this command failed (no path found): cp -r "somedir with space/*" /tmp But this works fine: cp -r "somedir with space/"* /tmp So, what's wrong with path ...
8
votes
1answer
313 views

cp says it's removing files, but shouldn't be

Making a quick backup: root@guilmon:/mnt/backup/guilmon/home# cp -uvfrx --preserve=all /home/rena/ . The output is surprising - some files are said to be removed! removed ...
2
votes
2answers
37 views

Copy files with parent folder to a new directory

I want to copy some files and include their parent directory in the process. The current structure is similar to: /Module1/A/downloads/m13312/file.pdf /Module1/A/downloads/m17312/file.pdf ...
0
votes
1answer
40 views

cp options --no-clobber vs. --update

I want to copy a single file if (and only if) the destination does not exist. The source file changes rarely, maybe once a month. The destination almost never exists. Are there any differences ...
1
vote
3answers
68 views

How do I create a copy of a file in multiple directories?

I have a folder structure conf/ widget1/ env1.cfg env2.cfg widget2/ env1.cfg env2.cfg widget3/ env1.cfg env2.cfg widget4/ ...
0
votes
3answers
173 views

How do I copy the latest file from one directory to another?

I have 3 zip files in a directory. I want to copy the most recent version to a backup directory. My code works fine for .sh and other files, but not for .zip. Is there something else I have to do? ...
1
vote
1answer
109 views

cp: cannot stat error - when filename has Asian characters

I am simply trying to copy files using cp -r /home/user/source/ /home/user/destination/ but it throws me the cp: cannot stat /source/filename.xxx error for some of the files. When I searched for this ...
-1
votes
1answer
46 views

Copy files from find command [closed]

I am trying to copy all *file.log files found using find. The problem is all files are named the same and it is only copying over one file. I need to find a way to rename the files in the command or ...
1
vote
4answers
175 views

How do I suppress error messages from cp?

I am currently looking ways to suppress error command in Linux, in particular, the command cp. I do: root@ubuntu:~$ cp /srv/ftp/201*/wha*/*.jj ~/. cp: cannot stat `/srv/ftp/201*/wha*/*.jj': No ...
3
votes
1answer
139 views

scp command fails executing cp

I am trying to use scp command to copy the r0.res file from local machine to a remote machine. I entered the following command: scp -v /etc/drbd.d/r0.res root@192.168.1.104 and I obtain this error: ...
2
votes
2answers
56 views

copy files from the parent location when I am inside a symbolically linked folder

Suppose I have created two folders in /tmp called parent and child. child contains a file called test-child.txt and parent contains a file called test-parent.txt. Now lets go inside the parent and ...
0
votes
1answer
39 views

? appended to filename while copying from a ssh

I am using the command cp error.log error$HOSTNAME.log the command works properly while running it separately in a server, but if it is run as script which uses ssh I am getting a ? appended to the ...
2
votes
1answer
164 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 ...
0
votes
1answer
3k 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 ...
2
votes
2answers
151 views

How to test which files will be copied with the cp command?

I'm creating a simple script that copies all files from DIRECTORYA that do not exist in DIRECTORYB. I'm doing this through the use of the cp command: cp -u DIRECTORYA/* DIRECTORYB What I'd like to ...
-3
votes
1answer
39 views

How to copy a sub directory of one directory to another?

How can I copy a directory structure named function under Dept2 directory into Dept3 directory in one shot?
1
vote
1answer
86 views

cp with interactive don't prompt before overwrite

I observed a strange behavior cp. Exactly the point is that cp did not ask me for confirmation, even with the option interactive. A test case looks like this Existing files find * -type f ...
1
vote
3answers
61 views

Replace bunch of files maintaining path

I have directory A and B. Each of them contains another directory with item.json inside. Only item.json file is persistent in directories so I cant copy-paste the directories. A: ./path/Item ...
3
votes
2answers
331 views

Copy files in same folder and replace year in its name

How can I copy a lot of files in the same directory replacing the year in its name? I have this (can be different filename and extensions): filename1-2014.ext filename2-2014.ext filename3-2014.ext ...
1
vote
4answers
115 views

Create copies of files in same directory

Lets say I have a directory with the following files: 1.txt 2.txt 3.txt I want to copy these and basically paste in the same directory making new files eg: 1.txt 1(1).txt 2.txt 2(1).txt 3.txt ...
1
vote
1answer
58 views

How to emulate 'cp -a' on Solaris which does not have it?

How to do a cp -a on a Solaris system which does not support the -a option?
1
vote
3answers
541 views

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 ...
0
votes
0answers
42 views

POSIX description of cp -R

I just became really confused by the implementation of bash's cp -R command compared to how POSIX words what should happen Given the posix definition, I would expect cp -R srcDir existingDestDir to ...
3
votes
1answer
171 views

Mac OS X combine cp and cat to sequentially copy and rename files in list

I am using a MacBook Pro OS X 2013 model. I have a list of filenames in a text file named list.txt separated by line breaks list.txt exactly like this, but this list is going to be long e.jpeg ...
1
vote
1answer
130 views

how is cp -f different from cp --remove-destination?

in the cp manpage, it lists the -f/--force option as: if an existing destination file cannot be opened, remove it and try again for the --remove-destination option it says: remove each existing ...
1
vote
1answer
150 views

what is the purpose of cp -s?

as the answer to this question shows, Is there a difference between hardlinking with cp -l or ln? The purpose for creating the -l option for the cp command is to recursively hard-link (the contents ...
1
vote
2answers
302 views

do not show error if file doesn't exist on copy, without sending to dev null

I want to avoid my script posting an error if I try to cp a file that does not exist. However, I would like error messages to print out for any other error, such as insufficient permissions. This ...
1
vote
2answers
63 views

May cp override subdirectories with the same name?

I downloaded an Adobe flash plugin, It includes a .so file and a directory called usr. In this folder, it has sub-folders like bin, lib, lib64, share. In the readme file, it says I need to do the ...
1
vote
2answers
5k views

cp: cannot stat : No such file or directory

I am getting an error when I try to copy a file from my local computer to a remote server with ssh. I get the same error whether I use cp or scp. Here is my input at the resulting error: ...
0
votes
1answer
62 views

Syntactic differences in cp -r and how to overcome them

Let's say we are in a blank directory. Then, the following commands: mkdir dir1 cp -r dir1 dir2 Yield two (blank) directories, dir1 and dir2, where dir2 has been created as a copy of dir1. ...
1
vote
1answer
262 views

“wget --restrict-file-names=windows” seems to fail converting links for NTFS

I've downloaded a website from the net using the wget command-line tool with --restrict-file-names=windows so that once the download is complete I could copy the downloaded files to a mounted Windows ...
1
vote
2answers
187 views

The command 'cp' can only used on block device?

According to my last question I think we can't use 'cp' to copy file to the tape device or device like '/dev/lp0'.But I still don't understand why. To make this question simple enough,just tell me if ...
4
votes
3answers
2k views

Multithreaded cp on linux? [duplicate]

Is there a multi-threaded cp command on Linux? I know how to do this on Windows, but I don't know how this is approached in a Linux environment.
3
votes
1answer
144 views

cp and set new user

I configure linux servers with some regularty. And then copy with ssh-copy-id my public key to the root user (/root/.ssh) and edit authorized-keys. If I install additional services, sometimes ...
1
vote
1answer
136 views

Linux command to copy as hard links, while deleting unwanted files?

I'm looking for a command that behaves both like cp -al in only creating hard links rather than copying file contents, and rsync -a --delete in removing files from the destination that are not ...
1
vote
2answers
340 views

How can I copy a file from another directory to the current one?

I have this problem as part of a school assignment: NOTE: In case it's hard to read in the image above, here's the directory tree: $ tree . `-- sample_dir1 `-- sample_dir |-- admin ...
1
vote
1answer
50 views

How to copy with wildcard in directory name?

I would like to copy the html directory inside a directory like cms_drupal_PROJ-1-2 to /var/www. The last digit in the working directory is dynamic so at any given time all I know is ...
0
votes
2answers
469 views

Different sizes after copy [duplicate]

I would like to copy for backup porposes a Linux user home directory with several GBs of data and the usual configuration files. The source directory and the backup directory should exactly have the ...
4
votes
1answer
450 views

How to determine if cp -u actually copied the file?

As the title says, I'm looking for a concise way to check if a file was copied using cp -u. I have a little shell script which updates quite a number of files. At the moment the script echoes a ...
2
votes
1answer
232 views

Copy multiple files and create the target directories at the same time?

I read How can I copy a file and create the target directories at the same time? But the solution there only works if you want to copy one file. How would I copy multiple files into a directory, ...
1
vote
1answer
135 views

Replace cp function by rsync [duplicate]

I'm trying to replace my cp function by an rsync function My cp function is the following find /home/odroid/USBHD/Movies/ -iname "*.mkv" -mtime '-1' -exec cp -n {} /home/odroid/NASVD/Movies \; do ...
0
votes
1answer
1k views

Copying files with multiple extensions

I would like to copy files with multiple extensions to a single destination directory. For example, I can use the following command to copy all .txt files in the working directory to a directory ...
0
votes
0answers
25 views

How to be certain “cp -n -r /dir/ /des/” does not overwrite files.. and is doing its job ? verbose mode?

I run the command cp -n -r /dir/ /backup/ but there is no way to tell what it is doing.. if it is skipping files that already exists.. if it is doing anything.. I tried adding -v option to ...
5
votes
2answers
252 views

Is there a better way than cp to copy millions of files while preserving hard links?

So in this story on the GNU coreutils ML, someone used cp to copy 430 million files and needed to preserve hard links, and just barely got it to finish after 10 days. The big problem was that, in ...