cp - Command-line tool to copy a file

learn more… | top users | synonyms

-1
votes
1answer
37 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
34 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
67 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
83 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
36 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
96 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
46 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
48 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
236 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
517 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
47 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
145 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
507 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
301 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
39 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
73 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
75 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
209 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). ...
6
votes
1answer
341 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
512 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
90 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
1k 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
33 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
466 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
68 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
43 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 ...
4
votes
1answer
73 views

When do I use cp --attributes-only

Doing some study on basic Unix commands and trying to get an example when I want to use the following command line option --attributes-only for command cp here is from cp man page --attributes-only ...
0
votes
1answer
51 views

How to copy a file within its original directory, most easily? [duplicate]

What I want to do is basically cp long/directory/path/file long/directory/path/file-copy This or similar operations are pretty common. Typing out the whole path twice is obviously awkward, even ...
2
votes
3answers
114 views

Display what has been copied by `cp` (using `ksh`)

I'd like to get output showing what has been copied by cp. The only problem is how to do it when I cp many files at a time. For instance, cp ./sourceDir/* $destinationPath/.
0
votes
2answers
108 views

cp all files and subdirectories in a directory ksh

How can I do a cp to copy all files including all sub-directories in the current directory. I looked at the man page, but I can't figure out how to do it.
2
votes
1answer
336 views

KSH : cp only based on file size

I would like to write a small script copying from a directory A to directory B all the files with the .log extension. So in my directory A, I've : ls : a.log b.log c.log Here is the pseudo-code I ...
0
votes
1answer
69 views

Finding a specific file in several sub-directories

I've the following problem : I have to write something to copy a file contained in directory A. The file is unique, and has a specific extension (.jil). Only problem, directory A can contains a ...
1
vote
2answers
2k views

Copy only regular files from one directory to another

I'd like to copy a content of directory 1 to directory 2. However, I'd like to only copy files (and not directories) from my directory 1. How can I do that ? cp dir1/* dir2/* then I still have the ...
2
votes
2answers
1k views

ACL defaults not being obeyed on copy over NFS

I have an Arch Linux box that has a folder from an Ubuntu server mounted via NFS. I've set up an Access Control List on the folder on the server such that any new files should have their permissions ...
1
vote
1answer
137 views

Copying wallpaper images into a single folder

In my ubuntu 12.04 set-up, there are lots of wallpaper images in the directory /usr/share/wallpapers. For example, one might be usr/share/wallpapers/Leafs_Labyrinth/contents/images/1600x1200.jpg ...
5
votes
4answers
498 views

Copying specific subfolders with directory structure to a new folder

I am having a the following directory structure: Main_Dir | ----------------------------------- Subdir1 Subdir2 Subdir3 | | ...
0
votes
1answer
323 views

Trying to cp a path with spaces, fails when scripted but echoing and pasting succeeds? [closed]

I have a script that is trying to copy a directory from a path that includes backslash-escaped spaces and is stored in a string variable to a subdirectory of the working directory. When I run the ...
8
votes
3answers
362 views

rsync most recent x GB

I'm looking for a command/script to allow the most recently modified files (up to) 10GB be copied to another computer. So if there are 4 files 4 GB each, only 2 of them should be transferred by the ...
2
votes
2answers
121 views

Is there a --parents option for mv like for cp?

cp has a useful feature --parents that allows a file's directory structure to be copied to another directory: $ cp -v --parents source/directory/from target/ ‘source/directory/from’ -> ...
3
votes
5answers
630 views

How can a filesystem be copied exactly as is?

I have a file system for a device I am programming that I would like to make an exact copy of. Ideally I would like this copy to be identical to the folder that it was copied from. I have tried using ...
1
vote
5answers
2k views

How to append date to backup file

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? ...
2
votes
3answers
1k views

cp --no-target-directory explained

Question: I need a simple example of how to use cp --no-target-directory. I do experience some difficulties in understanding cp --no-target-directory. I do understand the explanation for mv ...
3
votes
2answers
202 views

cp -L vs. cp -H

Problem When copying files with cp -H or cp -L, I get the same results: $ ls -l fileA fileA -> fileB $ cp fileA somewhere/ -H $ ls -l somewhere/ fileA # fileA is a copy of fileB, only ...
5
votes
4answers
1k views

What is the purpose of the 'install' command?

I've seen the install command used in a lot of Makefiles, and its existence and usage are kind of confusing. From the manpages, it seems like a knockoff of cp with less features, but I assume it ...
2
votes
1answer
104 views

Why does copying from a script screw with my files?

I am at a loss here, trying to find out the reason why a shell script that is basically copying a couple of files and directories from one place to another will result in the content of two of the ...
4
votes
3answers
2k views

convert soft- to hardlinks with cp

The cp command's infopage offers on the option --preserve= the following: links Preserve in the destination files any links between corresponding source files. Note that with -L' ...
3
votes
1answer
110 views

cp --attributes-only documented but not working “now”?

PROBLEM: cp --attributes-only Source Target results in two files unchanged, where the attributes from Source should be copied to Target. Attempts to solve: As I have the 8.13 version of coreutils ...
4
votes
2answers
333 views

Copying large file causes excessive swap

On a mid-class CentOS 6.4/64 server with 32 GB RAM, 3 TB free disk space, operating as KVM hypervisor, I start copying a 200 GB file to a destination in the same local filesystem. In fact, this file ...
0
votes
2answers
62 views

How do I copy and paste seperately? [closed]

I know for the cp command you have to specify the source(s) and destination. But what if I have to copy say all folders under src folder, do some other operations, and then paste later on? In short, ...
3
votes
2answers
114 views

Shell-independent way to cp dotfiles from a folder to another [duplicate]

I have two existing directories : foo: directory with dotfiles in it foo2: empty directory I would like to have a solution to copy all dotfiles in foo to foo2. I would like a solution that is not ...