Questions tagged [cp]

cp - Command-line tool to copy a file

Filter by
Sorted by
Tagged with
0
votes
1answer
59 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
4k 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
44 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
18 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 ...
-1
votes
1answer
65 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,...
2
votes
1answer
987 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
33 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
49 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
79 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
41 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
1k 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
44 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
157 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
29 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
81 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
7
votes
2answers
21k 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
85 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 ...
359
votes
8answers
612k 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
3k 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
77 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
60 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
42 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
35k 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
72 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
46 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
33 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 ...
246
votes
16answers
332k 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 ...
52
votes
5answers
19k views

How to copy a directory recursively using hardlinks for each file

I want to create a "copy" of a directory tree where each file is a hardlink to the original file Example: I have a directory structure: dirA/ dirA/file1 dirA/x/ dirA/x/file2 dirA/y/ dirA/y/file3 ...
0
votes
0answers
34 views

Can I specify a size space while using mount command?

I mount a *.img file, and want to copy some new files into it. But there is not enough space for me to place new files. Can I specify more size space while I use mount. ./Image: No space left on ...
0
votes
2answers
25 views

Recursively copying a folder to an empty subfolder

How to copy all the content of the folder /foo/bar, which contains the file /foo/bar/a to an empty subfolder /foo/bar/subfolder without ending up with the file /foo/bar/subfolder/subfolder/a. Doing cp ...
52
votes
13answers
123k views

How to check progress of running cp?

Is it possible to check the progress of running cp process? Some processes respond to various KILL signals so that you can check what is their status. I know that I can run cp with parameter -v but ...
5
votes
1answer
498 views

systemd and copy (/bin/cp): no such file or directory

While manually copying the file the following works, as below: userx@x:~$ cp -rv /opt/test-bak/* /opt/test/ '/opt/test-bak/file1' -> '/opt/test/file1' '/opt/test-bak/file2' -> '/opt/test/file2' ...
1
vote
1answer
53 views

cp multiple files do not work in bash script

I would like to run the below command in a bash script but, it doesn't work. command: cp /tmp/first/{abc.conf,xyz.conf} /tmp/backup/ bash script: firstDir=/tmp/first #secondDir=/tmp/second ...
4
votes
3answers
10k views

Randomly copy certain amount of certain file type from one directory into another

Sometimes I have a folder full of jpg's and I need to randomly choose 8 or so of them. How could I automate this so my account randomly chooses 8 jpg's from the folder and copies them to another ...
2
votes
4answers
2k views

Use find + sed + cp to find files and copy them to a directory with a different name

I'm trying to copy a bunch of files named folder.jpg into a folder. The problem is because all the files are named the same thing, I need to rename them in the process. I know I can probably do it ...
1
vote
1answer
102 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
3answers
252 views

Replace bunch of files maintaining path

I have directory A and B. Each of them contains another directory with item.json inside. Only item.json file is persistent in directories so I can't copy-paste the directories. A: ./path/Item A/item....
0
votes
1answer
87 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 ...
2
votes
1answer
157 views

“cp: target '…’ is not a directory” during while loop

I have a directory of files whose names I want to shorten: (3) andrew@andrew Learning_Plans $ ls -al total 580 drwxr-xr-x 2 andrew andrew 4096 Apr 10 21:40 . drwxr-xr-x 7 andrew andrew 4096 Apr 10 ...
1
vote
2answers
114 views

How do I get commands in a bash script to complete? (files get truncated with cp)

I have a server that receives backupname.tar.gz files in /home/my_user/drop directory every hour. I installed incron utility and use incrontab -e entry to run a script whenever a new file shows up in /...