The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Questions tagged [cp]

cp - Command-line tool to copy a file

Filter by
Sorted by
Tagged with
6
votes
2answers
3k views

Info on cp --preserve=links

I'm trying to understand what cp --preserve=links does when used by itself, from my tests it seems that it copies a normal file normally and dereferences symlinks, but it seems like it just has the ...
0
votes
1answer
983 views

Do cp and tar create temporary files and then do an atomic mv ?

I'm using Java's Files.walkFileTree to scan a particular directory periodically for *.csv files and then reading them. I know that mv is atomic ( at least within the same device ) so 'mv'ing a file ...
7
votes
5answers
1k views

make scp behave like it is supposed to (remote file copy program) [closed]

I want to copy local file to a remote server using scp. scp -rp local-file my.server.com:/tmp/ Sometimes I forget to specify where on the remote server the file should be copied to: scp -rp local-...
4
votes
3answers
769 views

Remove lines of text that end in “/”

I am using rsync to generate a list of files that have changed and then using that list to upload the files to s3: rsync -av somefiles/ someotherfiles/ > list.txt while read F ; do echo $...
1
vote
2answers
1k views

find and copy files using input list and partial file paths

I have a list of filenames names.list which contains names only. These files are scattered throughout my system in various sub folders but the structure is generally uniquename/uniquename2/spades/...
4
votes
3answers
20k views

How to copy directories via ssh

I am connected with ssh and I want to copy a directory from my local to our remote server; how can I do that? I have read several post using scp but that doesn't worked for me. Some posts suggested ...
1
vote
1answer
177 views

How to copy same named files from one location to another location number of times using linux command?

I have the following tree struture. sl_top | |-- Pinmux_Formal_checklist | | |-- Pinmux_Formal_checklist.config | | |-- Pinmux_Formal_checklist.html | | `-- rev1 | ...
7
votes
1answer
9k views

cp: cannot create regular file: Invalid argument

sudo cp -r "/home/fleamour/Music/Mum's Music" /run/media/fleamour/3732-6531 cp: cannot create regular file '/run/media/fleamour/3732-6531/Mum'\''s Music/Louis Armstrong - At His Very Best/13 - Louis ...
2
votes
2answers
2k views

Why does cp not set source attributes and fail with -p?

I have these files: -rw-rw-r-- 1 root adm 0 Jun 22 11:25 a -rw-rw-r-- 1 wilmes wilmes 0 Jun 22 11:23 b When I cp b over to a as user wilmes why does it keep the original owner of a (root)? I ...
2
votes
1answer
636 views

cp -al not creating hard links

I want to create snapshots/hard links for my backups, using the cp -al command. While cp -al does create hardlinks when using it on my main system (Mint 18.1), where the parent directory size stays ...
-3
votes
1answer
59 views

How to create copies of a directory with sequential numbers

I have a template directory containing sub-directories and MS-Windows links. This directory needs to be sequentially reproduced at the same folder level. The range needs to be from one to twenty. So, ...
2
votes
1answer
535 views

cp: prevent error when source and destination are the same

Can you tell cp (GNU coreutils) to prevent reporting an error on: $ echo 1 > foo $ cp foo foo Currently, this reports: cp: 'foo' and 'foo' are the same file That's very sensible, but it's not ...
1
vote
1answer
571 views

Excluding specific folders while copying stuffs from one directory to another

I have to copy contents of some code from one folder called aim-db-dir to another called aim-db-dir_nosvn. aim-db-dir contains .svn folders in all the directories (and subdirectories) and these .svn ...
1
vote
1answer
106 views

How to copy a certain amount of sorted files? (e.g. 11 GB)

I'd like to copy a total of 11 GB of files (all of the type .mp3 for the sake of this question) from folder ~/ABC/ to ~/DEF/. And I like to do that for the files sorted descending by date last edited/...
1
vote
1answer
2k views

cp: ‘x’ and ‘y’ are the same file

This is really weird. I am trying to copy a file. I do cp config.yaml config-test.yaml. However, I get cp: ‘config.yaml’ and ‘config-test.yaml’ are the same file. ls -l config*.yaml gives May 30 16:...
0
votes
1answer
488 views

cp from different directory to one directory certain files

I want to do the following. I want to copy from a remote FTP server every day certain files. This FTP directory is mounted. Every day a directory is created and within that directory I need 3 files ...
0
votes
1answer
546 views

Hard disk usage 100 % without any read or write activity

I started a big file transfer and it's taken a long time. I checked the disk activity with nmon and it says the (NTFS) disk is being 100 % busy and read and write speeds are at zero. I used cp -r ...
2
votes
1answer
62 views

Why did `cp -uav` of a git repo show “removed” for some files?

I used cp -uav to update a copy of a git repo, including uncommitted files. Why did it say it's removing files? It looks like this: $ cp -uav repos copy removed 'copy/repos/h/.git/objects/e6/...
0
votes
1answer
88 views

Why “.” is required copying a file from one directory to another directory?

While reviewing someone's bash script, I ran into following command. My question is why "." is required for copying a file from one location to another? To me it seems unnecessary. cp source/foo.xml ...
6
votes
1answer
480 views

why linux cp command don't consume disk IO?

os: centos7 test file: a.txt 1.2G monitor command: iostat -xdm 1 The first scene: cp a.txt b.txt #b.txt is not exist The second scene: cp a.txt b.txt #b.txt is exist Why the first ...
2
votes
1answer
83 views

cp error message uses different quoting on Ubuntu 12.04(?) and Fedora 24

I develop on F24 and my tests pass, but when I try them in Travis CI, they fail. AFAIK, they (Travis CI) use Ubuntu 12.04 VMs. The test compares the output of a run with previously gathered "gold" ...
2
votes
1answer
411 views

Copy file and replace string

I am trying to write a script that copies the file log_REPLACE, and replaces the string REPLACE in the name of the file, and within the file with the letter A and B. So I want to create log_A, and ...
3
votes
1answer
3k views

How does copying the Debian iso directly to a USB drive work?

I downloaded a Debian DVD and following the docs mounted a USB and simply did this: cp /dev/sdb mydebiandvd.iso sync After running these commands I ran lsblk and found the sdb thumb drive said it ...
3
votes
2answers
373 views

How to check progress of cp when target is a whole-device

To create a debian install stick, one copies the iso to the device: cp debian-testing-amd64-DVD-1.iso /dev/sdb per this page: https://www.debian.org/releases/jessie/amd64/ch04s03.html.en according ...
0
votes
1answer
82 views

Understanding Copy command

I have one copy cp command related question: In my home directory, there is a folder which is known as WebDev, Inside WebDev folder, there is a target folder which contains WebDev.rar. Now, I am ...
0
votes
1answer
162 views

cp/rsync both grind to a halt when copying to USB/Micro SD

I'm trying to transfer about 20GB of music from my Arch Linux laptop to a Micro SD card, via a USB reader. The process starts off fine; the first ~50 songs take a combined one second, although from ...
1
vote
2answers
1k views

Working with /dev/null with cat or cp vs touch

In a tutorial about public key infrastructure the author sets up a database to work with when setting up a Root Certificate Authority: cp /dev/null ca/root-ca/db/root-ca.db cp /dev/null ca/root-ca/db/...
1
vote
2answers
3k views

How to copy contents of a folder without affecting the permissions of destination folder?

I want to copy all files and folders from one directory to another without changing the permissions of the destination directory. Where origin folder is 555 and destination folder is 775. If I use ...
1
vote
1answer
41 views

How to treat cp -r always as directory?

I have to copy some files and I have a field where I write the destination path. But if I do not write "/" at the end, it takes the last word and creates a file with that name. How can treat ...
1
vote
0answers
61 views

Why isn't tee outputting to stdout? [duplicate]

I'm using tmux and cueing up a very large copy: /bin/cp -aRv /mnt/src/folder/. /mnt/dest/folder/ 2>&1 | tee /log/big_copy_log When I run without tee, I see output on the terminal just fine. ...
1
vote
2answers
209 views

How to find and copy files based on extension?

I have a photorec folder from a data recovery process that has 2481 folders with the recovered files. The folder names are in the sequence recup_dir.1, recup_dir.2 ... recup_dir.2481 I got a list of ...
0
votes
2answers
1k views

Appending one file to another [closed]

Simple question. I'm trying to append one file to another. I've tried this: cp temp1 >> temp2 temp3 But, it doesn't seem to work. Thanks.
1
vote
1answer
48 views

cp the only files when permission is granted in the a directory

I would like to cp the whole directory, however inside that directory, it has some files which I don't permission to cp over. Is there any flag I can use in this case. Or are there any other command I ...
2
votes
2answers
157 views

Copy file to destination based on ini file

I have a few thousand subdirectories in a directory, each containing one config.ini file and one JPEG image. The ini file contains (including but not limited to) a section that encodes the time, when ...
3
votes
3answers
2k views

Copying newer files only

I have a simple shell script. What i'd like to do, is copy the files in /home/imp/imp/msgs/ to /home/imp/imp/msgs/bak/, but only if they are newer in the source directory than the destination ...
4
votes
3answers
14k views

How to copy “just files” recursively

Suppose I have this structure for folder0 and subfolders and files in it. folder0 subfolder01 file011 file012 subfolder02 file021 file01 file02 I ...
0
votes
2answers
1k views

source and destination path for the copy command in single file then how to copy?

I have a single file which contains source file paths and destination file paths. example $ cat test.txt /home/data/source.txt /home/code/destination.txt /home/abc/def.txt /home/mnp/xyz.txt ...
7
votes
2answers
17k views

cp after xargs not working

I run debian jessie on Host 64-bit and in virtualbox 32-bit. To spare traffic I try to cp the i386 packages from host to the shared folder, for using them in virualbox. My Hostname/var/cache/apt/...
1
vote
1answer
59 views

Rsync , cp or any utility add specific filtered data back from original file to analyzed file [closed]

I have mistakenly deleted some useful data from my backup file but the problem is I have so far analyzed huge amount of backup file and now i cannot take a another backup and start analyzing from ...
1
vote
3answers
2k views

How to override all folders with cp?

I have two folders, and I would like to do: cp -R folder1/ folder2/ So that I all the sub folders missing in folder2 will be created, and there files copied. And all the folders in folder2 that are ...
0
votes
1answer
173 views

rsync and cp producing different results

I was upgrading ModX today and tried to merge the new installation with the existing copy on my server. On their site ModX says to "merge directories", which I assume means to recursively copy every ...
7
votes
1answer
1k views

Copy nested directory structure ignoring all directories of a certain name

Say I have a big nested directory projects/ and I want to recursively copy the entire directory excluding any sub-directory with the name node_modules/ or env/. I don't know how many node_modules/ or ...
1
vote
2answers
9k views

cp says “same file” for two different directories

I have directory A with subdirectory B and am trying to copy everything from B to A. Within A, I run cp -ar B/ ~/A, and get the message that "cp: âB/â and â/u/username/A/Bâ are the same file" ...
0
votes
1answer
859 views

Why does “find / -name '*.txt' | cp /junk” not work?

If I want to find any files with .txt in the name, and for every match that is found copy it into the /junk folder the following could be considered to work; find / -name "*.txt" | cp /junk but ...
2
votes
1answer
735 views

Unexpected behavior of cp -a on symbolic links

When copying symbolic links from incremental backups, unexpected behavior can occur. For example: # mkdir 0 1 2 # touch 0/a # ln 0/a 0/b # touch 1/a # ln 1/b 1/a So directory 0 looks like a b->a ...
4
votes
1answer
11k views

What is the difference between `dd`, `cp` and `rsync`? [closed]

Besides the explanations from the man pages and --help information, in which way do the commands dd, cp and rsync differ when used to copy files? In which context is each of these superior to the ...
5
votes
3answers
1k views

create empty files with same directory structure as reference directory

I have a Dir1 with multiple subdir and files inside it. I intend to copy the Dir1 to Dir2 so that all the files in it will be just empty files but with same file name as Dir1. Then I intend to push ...
2
votes
3answers
1k views

move files in a loop

I have files named file_1_supply.csv file_2_supply.csv file_3_supply.csv ....... file_30_supply.csv I want to copy these files from one folder to another in Linux. The problem is there are also many ...
0
votes
2answers
299 views

Copying files in bash

I want to copy all files (included sub-folders) from $HOME directory to Desktop in bash. And as you know the Desktop is in $HOME. So, when I copy all files I get the message like this: cannot copy ...
3
votes
1answer
364 views

Alternative to cp command since cp throws warnings and returns with error code while used with NFS

I was using the following copy command to take backup of my datastore cp -pr $src $dest Which gives me the following warning while using with NFS and returns an error code but the files are actually ...