cp - Command-line tool to copy a file

learn more… | top users | synonyms

0
votes
2answers
3k 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
145 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 ...
7
votes
1answer
3k 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
42 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
93 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
49 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
154 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
73 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
172 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
390 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
710 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
124 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
8k 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
2k 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
161 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
2k 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
925 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
624 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
232 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’ -> ...
4
votes
5answers
3k 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 ...
3
votes
5answers
8k 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
3k 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
993 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 ...
7
votes
4answers
4k 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
109 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
3k 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
205 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
499 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
74 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
137 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 ...
14
votes
4answers
996 views

Why not always use rsync?

I wanted to ask is there any reason not to use rsync for everything and abandon cp? I wasn't aware of rsync and now I don't know why cp is ever needed.
7
votes
3answers
745 views

cp or mv files to same directory they are already in when I am in another?

If I am in ~/blob and I have a file in ~/blob/a_long_directory_name/c/x.x I can type mv blob/a_long_directory_name/c/x.x blob/a_long_directory_name/even_more/y.y Is there any shortcut whereby I ...
2
votes
1answer
78 views

Why don't I see a file being copied right away with ls?

Is it due to the buffering in memory? I did cp /network/large_file . & and I kept doing ls -lh to monitor progress, but the file didn't appear until it was about 400MB. Linux 2.6 kernel, Bash 4, ...
8
votes
5answers
4k views

cp with a single argument containing wildcards [duplicate]

If I have the following 2 files and 1 folder: someuser@computer:~/Desktop/test$ ls -l total 340 -rw-r--r-- 1 someuser someuser 45082 ago 5 09:56 file1.pdf -rw-r--r-- 1 someuser someuser 291836 ago ...
3
votes
3answers
117 views

cp SOMEFILE .. copies to a different directory after cd'ing via a symbolic link

Consider the following setup: ~/Desktop/Public/subdir ~/Desktop/subdir --> ~/Desktop/Public/subdir (symbolic link) Now I do: cd ~/Desktop/subdir Which leads me into the linked directory. If ...
9
votes
5answers
9k views

Copy specific file type keeping the folder structure

I have a folder structure with a bunch of *.csv files scattered across the folders. Now I want to copy all *.csv files to another destination keeping the folder structure. It works by doing: cp ...
2
votes
4answers
6k views

How to copy or move files without being asked to overwrite?

What I've tried: root@host [/home1]# cp -f hello /home3 cp: omitting directory `hello' root@host [/home1]# cp -rf hello /home3 cp: overwrite `/home3/hello/.buildpath'? y cp: overwrite ...
0
votes
0answers
22 views

file modified while doing scp/cp [duplicate]

I'm doing scp to a database while it's active. Its not very critical but I would like to know what will happen to a file when it is modified in the middle of a cp process? Does it get corrupted or it ...
4
votes
2answers
362 views

When wouldn't one want `cp` to be recursive?

Under what conditions might one wish to use the cp command on a directory yet have it not be recursive? Consider: $ tree . └── old └── inner └── a.txt 2 directories, 1 file $ cp ...
3
votes
3answers
71 views

Can I forbid the creation of files with certain permissions?

I have a directory with a certain group ID, and I only want files with the same ID to be in that directory. So I set the SGID bit on that directory, so that everytime a file is created inside it, it ...
22
votes
10answers
15k views

Is there a faster alternative to cp for copying large files (~20 GB)?

I am a graduate student, and the group in which I work maintains a Linux cluster. Each node of the cluster has its own local disk, but these local disks are relatively small and are not equipped with ...
1
vote
1answer
381 views

Symlink Copy a Directory Non-recursively

So I want to symlink copy all the files and folders in one directory to another directory. When I use cp -s though without the -r option I get a bunch of "omitting directory" warnings, and I don't ...
2
votes
1answer
77 views

How can I make multiple copies of one folder without merging?

When two or more identically named folders are to be copied into or moved to the same location, the default option either in the GUI file manager, or using in a terminal cp -r --backup=numbered or ...
5
votes
3answers
467 views

How to alias cp with cp -i by default

Is there a good way to alias the command cp file1 file2 to cp -i file1 file2? Apologies if this is a dumb question, I'm a Unix novice.
4
votes
3answers
198 views

Back up logs to a new directory

I need help to write a script to copy log files. There are two format of logs: System_<date_timestamp>.log trace_<date_timestamp>.log New files are generated when trace log reaches ...
5
votes
1answer
522 views

What is causing this Copy command to enter sleep state?

I am trying to recursively copy a huge directory of installables over 25G and want to preserve the owner and group id, permission modes and so on. So I ran the below commands: bash-3.2$ date; cp ...
0
votes
1answer
320 views

Simple bash script taking too long to execute

I wrote the following function in my .bashrc for use instead of rm * : function re() { cp . -R /home/glset/ritwik/trash/ rm * } It works .. but it is very slow. Even for small files it takes too ...
1
vote
3answers
9k views

`cp` permission denied when copy a file owned by `root`

I have a folder udp_folder2 d------r-T 41 root root 4096 Apr 26 21:17 udp_folder2 when I'm with user other than root, I can't cp -r it into a new folder it says: Permission denied ...
2
votes
1answer
105 views

exec cp failes from script, yet works when issued directly

I have a script that copies SQL backups to a windows server. Here's the line from /etc/fstab: //my.win.box/share$ /winshare cifs ...