Tagged Questions

cp - Command-line tool to copy a file

learn more… | top users | synonyms

3
votes
1answer
29 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
31 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
87 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
21 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
44 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
229 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
66 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
38 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
81 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
21 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
82 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 ...
2
votes
1answer
67 views

AIX question on cp command [closed]

I have come across an issue with cp command. We are using ksh and cp command goes like below cp -p $PATH/file_name_${VARIABLE}_???.dat $PATH/file_name_to.dat ??? - is for any three digit numbers. ...
3
votes
2answers
165 views

Using cp to replace a directory of the same name

How can I make cp replace a directory of the same name without removing the existing directory first? cp's default behaviour is to copy the source directory into the destination rather than replace ...
1
vote
2answers
58 views

How use minimum number of commands to copy all .txt files from all subdirectories to one directory?

I have more than 90 subdirectories and inside each one, there will be a number of .txt files. What I need to do is to copy all those txt files out to one single directory. How can I do that?
1
vote
1answer
95 views

copy filenames with special characters to an external ntfs volume

I'm trying to copy the Documents and Settings folder of a Windows XP system over to an NTFS external disk using a USB Live of Puppy Linux. I encountered am encoding problem for namefiles in which the ...
2
votes
1answer
39 views

rolling snapshot of pictures taken in the last half hour

I've taken this: find -maxdepth 1 -mtime +1 -type f -exec cp '{}' backup \; Which should copy all the regular files in the current directory more than 1 day old to the directory backup (assuming ...
3
votes
1answer
112 views

Move preserves ownership of source files not allowing writes

Kindly Consider: $ id # Me uid=100(user1) gid=200(group1) groups=200(group1) $ ls -l tnsnames.ora # So user1 has only read permission on below file. -rw-rw-r-- 1 oracle dba 411024 Jul 28 2010 ...
1
vote
1answer
107 views

How do I force move something when sudo mv -f doesn't work?

I need to move a 16 GB folder to my external drive, but moving it manually gives me an in use error. I have tried to start in safe mode and moved it but it was still in use. I have run these commands ...
2
votes
1answer
32 views

Installing a new OpenBSD kernel “safely”: why does `make install` go through these extra hoops?

After building a new OpenBSD kernel, the install target of the kernel Makefile does the following: rm -f /obsd ln /bsd /obsd cp bsd /nbsd mv /nbsd /bsd I understand that the first two lines remove ...
3
votes
1answer
56 views

Is there a difference between hardlinking with cp -l or ln?

I am implementing a backup scheme using rsync and hardlinks. I know I can use link-dest with rsync to do the hardlinks, but I saw mention of using "cp -l" before "link-dest" was implemented in rsync. ...
2
votes
1answer
73 views

Why does `cp -a . /dir` copy contents instead of directory?

I wanted to copy a directory that I was presently in. I tried cp -a . ~/xyz It copied the contents of the directory, yet this worked: cp -a "$(pwd)" ~/xyz [As desired, this copied the directory ...
3
votes
3answers
535 views

Copy a file and overwrite the existing file

I have two images (image1.png and image2.png) in the same folder on my server, I want to run a command that overwrites image2.png to image1.png. I prefer to overwrite the image instead of deleting it ...
2
votes
3answers
67 views

copying parallel directories Why does cp -r work this way?

The following works correctly (ie does what I want) cd /var/www/release/ mkdir wiki cp -rp ../html/wiki ./ However if I do (what seems more intuitive) cp -r ../html/wiki ./wiki it will ...
0
votes
2answers
93 views

Copy over existing files without confirmation?

I need to copy and over-write a large amount of files, I've used the following command: # cp -Rf * ../ But then whenever a file with the same name exists on the destination folder I get this ...
-1
votes
1answer
621 views

How do I properly allow user jenkins to write to a specific directory under user minecraft home directory?

I am using Jenkins, I want to copy a file from the Jenkins directory in to the minecraft user directory, but I am not sure how to go about this, as when I run cp build/versions/*.info ...
2
votes
1answer
57 views

Copy file from USB drive to a desktop loaded via a LiveCD

I have booted my computer using a LiveCD and want to copy a file from a USB drive to the LiveCD loaded desktop. I want to copy a file from the USB drive to the desktop environment in memory, which ...
2
votes
2answers
187 views

Use output from head to copy files with spaces

I have 11 files with spaces in its name in a folder and I want to copy the newest 10. I used ls -t | head -n 10 to get only the newest 10 files. When I want to use the expression in a cp statement I ...
1
vote
0answers
325 views

Copy files to parent directory using relative pathnames [closed]

If I'm in the current working directory of oxford. How would I copy outline.doc, and place it into the sample_dir directory using relative pathnames? I've tried cp outline.doc ../outline.doc
1
vote
3answers
41 views

Sharing a project tree between environments

To save space and time I copied a large project tree on a network drive as hard links, i.e. cp -a -r --link proj proj_B (background: it's huge, needs to be rebuilt from two incompatible ...
1
vote
1answer
268 views

Copy directory, but fail if file already exists at destination

cp -a foo/* bar/ will copy the contents of foo into bar, replacing any files that already exist. I can use the -n flag to make cp not overwrite existing files or -i to make it ask interactively ...
0
votes
1answer
70 views

How use `rsync -R` with multiple subdirs or install -D with multiple files?

Is possible with rsync to copy multiple files from a source directory to a dest directory with multiple subdirectories that don't exist? Or use install -D with multiples files to a directory that ...
0
votes
2answers
52 views

How can I cp different files to an alias that is changing

I would like to be able to replace cp x.x ~/some/long/directory/that/is/deeply/nested/ with cp x.x s1 where s1 is an alias that points to /some/long/directory/that/is/deeply/nested/ However the ...
6
votes
2answers
727 views

Copying one file to multiple directories

I have a file that I want to copy to another 60 directories. The best way I can think of doing this is by making a bash script that has instructions to every folder like this: cp script.sh ...
5
votes
7answers
526 views

Can I avoid enter key in cp -i?

I often need to selectively archive a long list of files using cp -iar, or similar, and to speed up the process I would like to press just one key instead of y or n followed by ENTER on every file. In ...
2
votes
3answers
73 views

How can I use an “alias” for the destination directory when copying?

I frequently edit startup files such as my .bashrc file Then I copy them to another direction such as ~/Dropnot/level1/setups/bash1 Is there any way I can cp such files to the above location with ...
5
votes
2answers
156 views

copying a directory+renaming it

I want to copy a directory from: path1/dir1 to path2/dir2 the first time I invoke cp -r path1/dir1 path2/dir2 there's no problem, dir2 is created under path2 ls path2/dir2 bu the 2nd time, ...
7
votes
5answers
542 views

copy smallest files first?

I have a large directory containing subdirectories and files that I wish to copy recursively. Is there any way to tell cp that it should perform the copy operation in order of file size, so that the ...
1
vote
2answers
1k views

cp and mv if the file named already exists

What happens when you give the following commands if the file named done already exists? $ cp to_do done $ mv to_do done
0
votes
2answers
46 views

Prompt when copying multiple files?

When copying multiple files from one directory to another is there a way to get bash to run through each file and ask for y/n? I vaguely remember adding something to the end of my command like 'ok?' ...
1
vote
2answers
134 views

moving files of certain formats from subdirectoris to directories with same folder names

I’ve got a weird situation. I have 100s of folders with flac and mp3 copies of the same tracks. I need to separate the mp3s from the flacs and put them into similarly named directories. for example: ...
1
vote
0answers
88 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 error like this: Error splicing file: Input/output error The problem is that it keeps the file in new location though ...
4
votes
3answers
451 views

Search for specified keywords in files and copy to a new filename based on the keyword

I'm trying to create an .sh script where if any keyword is found in a file then copy that file to the directory /pathtofolder/keywords/$thefirstkeywordfound (overwrite the file if it already exists). ...
5
votes
1answer
843 views

preserving extended attributes with cp/rsync

When copying with cp, the extended attributes are not preserved, even with explicit cp -a --preserve=all /source /dest or cp -a --preserve=xattr /source /dest The same is with rsync, i.e. ...
0
votes
2answers
2k 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 ...
1
vote
2answers
124 views

How can i keep the mtime of files and directories in bash when I use rsync or cp? For use in Backup/Incremental Backup

I have a new NAS box and after looking through numerous backup solutions I've found doing it manually through PuTTy to work the best. After logging in to the box through PuTTy as root, I first need ...
5
votes
1answer
2k views

cannot create regular file 'filename': File exists

I've been getting this strange error message in one of my build scripts - cp fails, returning the error "File exists". I've even tried using cp -f, which should overwrite the file if it exists, but ...
2
votes
1answer
40 views

Confusion on the cp command when creating a new directory

Let me explain my problem with a simpler scenario. We have these two directories: ~/Foo and ~/Bar. Foo contains the files test1.txt and test2.txt. If I run the command cp -R Foo Bar, the Bar directory ...
4
votes
2answers
2k views

CP: max source files number arguments for copy utility

Consider that there are countless number of files under /src/ cp /src/* /dst/ How many files cp will successfully process?
2
votes
2answers
83 views

Copying recursively files with spaces

At the moment I have a set of files of the form of: /dir one/a picture.jpg /dir two/some picture.jpg What I want to do is copy and change the end to -fanart.jpg to the filename to: /dir one/a ...
3
votes
1answer
46 views

**/ not working with a mounted volume

I'm trying to recursively extract a set of .jpgs from a mounted volume using SMB1, to a folder on my computer. Here's what I've got: cp -a **/97*.jpg /Users/.../All_Covers This works as long as my ...