Questions tagged [cp]

cp - Command-line tool to copy a file

Filter by
Sorted by
Tagged with
-1
votes
2answers
104 views

cp -a doesn't work to copy all files inside a directory

I desire to copy all files inside a directory which has only these files (all are regular files - there are no directories, symlinks, etc, inside that directory) to another pre-existing directory. The ...
-7
votes
1answer
76 views

What is -a argument for GNU cp? [on hold]

The manual for GNU cp says -a, --archive same as -dR --preserve=all What is the meaning of "archive" here (which I assume radically different than with tar or zip)? Edit: I should have read -...
4
votes
4answers
320 views

Just one file echoed from an array of files

I try to copy 2 or more files from one directory to another with cp using an array. I executed: files=( LocalSettings.php robots.txt .htaccess ${domain}.png googlec69e044fede13fdc....
0
votes
2answers
83 views

cp in multi line fashion

In CentOS with Bash 3.2.52(2) I have to copy many files (not all) from one directory to another. I can create a long one liner such as cp /"$HOME"/dir1/{file1,fil2} ... /"$HOME"/dir2 but because ...
1
vote
1answer
962 views

How to copy directory and ignore errors

I have a root Linux shell open on my Android device, and while using cp to copy a directory, I get an error. I think I know where the error is coming from, so that is not my question. I want to find ...
2
votes
1answer
802 views

AIX question on cp command [closed]

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

Difference between cp -r and cp -a

I'm looking for the difference between cp -r and cp -a. What does "recursive" mean in terms of copying files from a folder?
-1
votes
2answers
137 views

How to copy files one by one to different folders?

In a directory I have files with the names: 01.txt 02.txt 03.txt In the same directory are folders with the names: 01.abc 02.def 03.ghi I need a command to copy the files to the folders one by one,...
0
votes
0answers
30 views

cp from locally mounted sshfs corrupting .gz files

I have used sshfs to locally mount a SFTP server's filesystem. I am trying to copy .gz files from the sshfs mount (/mnt/mysftp/) to /tmp and noticed when the file is large (~10MB+), it will copy over ...
7
votes
6answers
10k views

How to copy all HTML files from a directory tree to a single directory

I want to copy all the .html files from myDir and its subdirectories to ~/otherDir. Here's what I tried, but it doesn't work: $ find myDir -name *.html -print | xargs -0 cp ~/otherDir usage: cp [-R [-...
1
vote
1answer
903 views

Sync two Directories without rsync

I know what you are thinking right now "Just use rsync" but unfortunately this system does not have rsync, and I would like to come up with another solution. The Setup: The source Server has a ...
9
votes
5answers
1k views

How to copy a file transactionally?

I want to copy a file from A to B, which may be on different filesystems. There are some additional requirements: The copy is all or nothing, no partial or corrupt file B left in place on crash; Do ...
-1
votes
2answers
28 views

bash: why can't I copy 3 files into 3 directories that share a name with the files?

So if I can do this: $ mkdir ./blah_{007,011,090} And end up with three directories... Why can't I do this... cp ../blah_{007,011,090}.swf ./blah_{007,011,090}_src And copy the files into 3 ...
1
vote
1answer
897 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 app/file....
0
votes
1answer
65 views

Copy files from remote machine to folder on remote machine

Why do we get the following error about "No such file or directory" when we copy files from remote folder to another remote folder? ssh -n -o ConnectTimeout=50 -o StrictHostKeyChecking=no -xaq $IP ...
13
votes
5answers
8k views

cp hidden files with glob patterns

Situation : $ mkdir foo && touch foo/.test $ cp foo/* . zsh: no matches found: foo/* (or bash : cp: cannot stat ‘foo/*’: No such file or directory) I have a directory full of hidden folders ...
0
votes
3answers
5k views

Copying files from one disk to another disk

I want to copy all contents from one disk to another HDD. I thought the cp command might do the trick. cp -aR /dev/nvme0n1p1/* /dev/sda1/ /dev/nvme01np1 is the old disk that I want its content to be ...
2
votes
0answers
49 views

Using cp to copy ~/.config to an external drive but getting “cannot create regular file…File exists” errors

The command is simple enough, executed while in a subdirectory of /mnt/e, an external drive: cp -r ~/.config .. Every time, every time I run it, the same set of files refuse to copy properly: cp: ...
1
vote
1answer
19 views

Copy file with changed content

I'm writing bash script where I need to store some files as a .bak files and change it content at the beginning(using sed for that). I'm looking for better way to write it down for my bash script. cp ...
2
votes
1answer
991 views

Can I get the backup option of cp and mv to work with directories?

--backup[=CONTROL] make a backup of each existing destination file The man page does say that it works on file. It doesn't seem to have any effect on directories. Is there anyway to make this ...
0
votes
1answer
36 views

Shell script cp command to a folder that will constantly change name

I have a script that downloads a folder. The folder has a fixed name with an ever changing number as a suffix, e.g. fixed_name_450. Each time I run to script the downloaded folder will have a new ...
0
votes
1answer
126 views

Missing destination file operand

I am beginner as far as Linux is concerned and therfore ran into trouble with the following command. $ cp VRP/share/ViennaRNA/bin/*. The error I got is as follows: cp: missing destination file ...
1
vote
0answers
40 views

cp - Does not recognizning accent characters [duplicate]

I have written a simple script, to copy some files, and change there name: #!/bin/bash for directory in ./../old_files/*; do DIR_NAME=$(basename $directory) for file in $directory/*; do ...
0
votes
3answers
90 views

Copying a list of files

I have a directory which has plenty of files which need to be copied over to another directory. Remember, not all files need to be copied, only some of them. Is there a way I can come up with a script ...
0
votes
1answer
42 views

How to select a path in a find […] -exec cp {} dest_dir \; command?

I'm having a hard time trying to limit the path with find. I have this command find ${DIR_PATH} -type f -name ".py" -exec cp --parent {} ${DEST_DIR} \; Which give me this output : ${DIR_PATH}/a/...
0
votes
2answers
2k views

How do I copy all the files containing “t_1” in the name to a different directory using one command?

How do I copy all the files with "t_1" in the name to a different directory using one command?
1
vote
3answers
47 views

Copy files from one path to another except .zip files [closed]

I need to copy all files from one UNIX path to another within the same server. However, there are some .zip files I want to exclude while copying. How can I achieve this using the cp command options?
1
vote
1answer
709 views

COPY failed: stat /mnt/sda1/var/lib/docker/tmp/docker-builder006125699/src: no such file or directory

When I run this command docker build -t hello-world . I got this kind of error...what should I do...How to copy file to /var/www/html/ Sending build context to Docker daemon 2.048kB Step 1/3 : ...
0
votes
3answers
2k views

Copying multiple types of files in one command

I want to copy several files from one directory to another, with different extensions So I would write something like: cp -r dir1/*.gif dir2 But I also want to copy all .jpg files in the same ...
0
votes
2answers
31 views

Copying diff results files

I have two folders - Folder A and Folder B. I compared the files from both folders using diff command. Now after finding that certain files are only available in Folder A and Certain files in Folder ...
1
vote
2answers
86 views

How to avoid copying “..” while using cp command in terminal? [duplicate]

I am using CentOS7 and when I use command cp /root/test/.* /root/test1 it also copies .. which copies all the files and folder in the parent directory of the source. How to avoid copying . and ..?
-1
votes
1answer
1k views

Copy hidden files in a directory to a directory without permission issue?

I'm trying to copy all of the hidden files to a directory. The problem is I can't copy it into a new folder. I get Permission denied error. How do I fix this? I used: cp -rf /usr/include /cse220-p01
8
votes
2answers
22k views

How can I copy a directory and rename it in the same command?

Currently, I'm running these two commands to create a quick backup of the directory. Is there a way to combine the two commands into one, so that I am copying and renaming the new directory in one ...
8
votes
4answers
15k views

cp or rsync, is cp really worth it?

I hope this does not count as a question without a real answer, as I can't seem to find a good reason to use cp(1) over rsync(1) in virtually all circumstances. Should one typically favour rsync over ...
4
votes
1answer
88 views

Move/copy millions of images from Macos to external drive to ubuntu server

I have created a dataset of millions (>15M, so far) of images for a machine-learning project, taking up over 500GB of storage. I created them on my Macbook Pro but want to get them to our DGX1 (GPU ...
362
votes
8answers
621k views

How do I copy a folder keeping owners and permissions intact?

So I was going to back up my home folder by copying it to an external drive as follows: sudo cp -r /home/my_home /media/backup/my_home With the result that all folders on the external drives are now ...
1
vote
2answers
39 views

Overwrite or don't copy?

I'm trying to copy a file only if it already exists, not if it doesn't, basically overwrite only on Linux. Does anyone know a solution? I basically need to "look" for a folder then if a file exists, ...
0
votes
2answers
4k views

copy files from multiple sub-directories to the same destination directory

I have something a directory like this Main Directory SubDirectory SubsubDirectory1 xx.jpg xx,jpg SubsubDirectory2 xx.jpg xx,jpg ...
1
vote
1answer
2k 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 ...
1
vote
1answer
129 views

cp runs from command line but file not found from script [duplicate]

I have a script to reorganize my directory structure that contains: files=./*"$pattern"I{"$ifirst".."$ilast"}.ext cp ${files} ../"$pattern"/"$i"/ When I run the script, I get an error: ./*S6I{001.....
1
vote
1answer
58 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 ...
0
votes
2answers
61 views

Copy every 10 files from source into a target directory using cp

I have 110 large files inside a directory. But I cannot copy them at once since the system gets timed out after 50 min. I want to copy files 1 to 10, next 11 to 20, next 21 to 30, and so on. The order ...
1
vote
0answers
32 views

I have a directory of 110 large files. I want to copy them in the batch of n (e.g., 10) to aws s3 [closed]

I have 110 large files inside a directory. But I cannot copy them at once since the system gets timed out after 50 min. I want to copy files 1 to 10, next 11 to 20, next 21 to 30, and so on. The order ...
2
votes
1answer
43 views

How to write a script to move files with a specific name from folder “A” to folder “B” in my Google drive?

How can I write a script that moves files with a certain name from a certain folder to another certain folder in my Google drive? Example: I have a folder named 'A' with three files named 'X', 'Y', ...
67
votes
6answers
36k views

Flattening a nested directory

This is probably very simple, but I can't figure it out. I have a directory structure like this (dir2 is inside dir1): /dir1 /dir2 | --- file1 | --- file2 What is ...
-6
votes
1answer
74 views

What is the meaning of -r and -R in copy command?

I read that they stand for recursively in the man page. However, I am not sure what their role is in the command. When I tried to copy some empty directory into another directory with, $ cp EMPDIR ...
0
votes
1answer
54 views

What happens when you copy a hardlink?

Imagine I have a file something/a.txt, which I hardlink from b.txt. Now, if I cp b.txt c.txt, is c.txt a hard link to a.txt, or is it a copy of the contents of a.txt?
18
votes
5answers
2k views

Why use diff/patch when it is easier to just use cp

diff -u file1.txt file2.txt > patchfile creates a patch file which consists of instruction for patch to convert file1.txt to be exactly like file2.txt Can't this be done using cp command instead? ...
1
vote
1answer
37 views

Attempting to only copy files that have changed within the last day while maintaining folder structure

I'm attempting to find and copy files that have been modified within the last day. While doing that I'm trying maintain folder structures under dir1. There are many subdirectories under dir1 and data ...
248
votes
16answers
339k views

Is it possible to see cp speed and percent copied?

I'm having problems when copying large files using nautilus (it gets stuck). I need to copy, using cp. I would like to know if there are any parameters that shows the % copied and also the transfer ...