Questions tagged [cp]

cp - Command-line tool to copy a file

Filter by
Sorted by
Tagged with
0
votes
2answers
52 views

How could I copy the same directory multiple times but with a different name?

I have a directory called 400K that has some files in it, I want to copy this directory multiple times but with different names. I want something like: cp -r 400K 500K 600K 700K I was considering ...
29
votes
6answers
7k views

Why was `cp` designed to silently overwrite existing files? [closed]

I tested cp with the following commands: $ ls first.html second.html third.html $ cat first.html first $ cat second.html second $ cat third.html third Then I copy first.html to second.html: $ ...
0
votes
1answer
89 views

copy directory into another directory multiple times

I'm on a Mac and trying to script out a few things from our build for Xcode. There are dSYM that are directories that you can inspect with Show package contents. In my script that gets run after Xcode ...
2
votes
2answers
77 views

Copy a file a number of times with names that come from a list

I have a list of names and I have a binary file. I want to copy that binary file so that there is one copy for each member of the list. The list is a text file with one name in each row. I keep ...
0
votes
1answer
22 views

Copy a directory structure to ennumerated folders

My folder structure is like this: ej-1/index.html ej-1/js/scripts.js ej-2/index.html ej-2/js/scripts.js ... ej-12/index.html ej-12/js/scripts.js Sometimes I need to re-structure the other ...
1
vote
1answer
234 views

Fedora: cp: Invalid argument while coping a file named with Chinese characters to a vfat filesystem

I want to use cp to copy a file named with Chinese characters to my fat32 usb stick. This is done using a script, so using nautilus is not a solution for me. I do not want to rename the files, too. I ...
0
votes
1answer
78 views

How to find files dynamically and copy them to a directory in linux

Trying to find these files and copy them to a directory (test_dir); abc-1.0.zip kncb-1.0.zip jenk-1.1.zip I would like to find all these files dynamically and copy them to a directory. I have tried ...
0
votes
1answer
51 views

Copying a source directory using the command cp -rsf when target directory exists

On Centos 7, when I use the command: cp -rsf /path/of/source /path/of/target When the target directory exists, files would go to /path/of/target/source. How can I avoid that? EDIT: source and ...
0
votes
1answer
93 views

cp -Tr overwrite behavior

I'm using GNU coreutils I have a directory foo containing a file file1 and a directory bar containing file2. If I now do a cp -rT foo bar, bar will contain both files instead of getting overwriten ...
1
vote
1answer
13k views

cp: cannot create regular file: Permission denied

I am running a PHP script on my Apache server and from the script I need to copy some files (to run a Bash script that copies files). I can copy to a directory /tmp with no problems, but when I want ...
3
votes
1answer
156 views

Can rsync pick up where an interrupted cp left off?

If I use cp to copy a very large file over the course of several hours and decide to stop the operation, can rsync be used to complete the operation at a later point without needeing to re-write data?
1
vote
1answer
40 views

find files with particular attributes, rename them to their directory name, copy them elsewhere

It won't look like it, but I've spent 3+ hours trying to figure this out... I am trying to identify files in all subdirectories of a parent directory with particular attributes (name and size) then ...
2
votes
1answer
148 views

Overwrite symlink with original file

I have a directory with some symlink file, for example: /home/user/symlink/$(*symlink_file_name1*).mkv /home/user/symlink/$(*symlink_file_name2*).mkv And I have another directory with the original ...
7
votes
6answers
2k views

sh recursive copy (cp -r) - How to exclude subfolder

I need to run a remote script using ssh via Ruby (net/ssh) to recursively copy a folder and exclude a subfolder. I am looking for the fastest way to do it so rsync is not good. Also, I understand that ...
2
votes
1answer
750 views

Use rsync to only copy files that have changed

Right now I have these commands: my_dir="$HOME/foo/bar"; rm -rf "$my_dir/WebstormProjects/"; rsync -r --exclude=".git" --exclude="node_modules" "$HOME/WebstormProjects/" "$my_dir/WebstormProjects/" ...
-2
votes
1answer
92 views

cp -r <Folder Name> .<Folder Name>

I run the command cp -r <Folder Name> .<Folder Name>. It have done something, but I cannot find it. Example: cp -r Agent .Agent.old # (There is a dot symbol on the 2nd folder name)
0
votes
1answer
726 views

error: cp: cannot stat ‘release\\-1.0.0\r.jar’: No such file or directory

I have a file "release-1.0.0.jar" in the current working directory, and I'm trying to copy it to a directory "release_dir". export t_version="1.0.0" mkdir -p release_dir cp release-${t_version}....
1
vote
1answer
86 views

Copying files based on input list, special characters in file names

This is based on the question here. Problem: I have a .txt file listing file names I want to copy to the folder newfolder in the shell (Mac Terminal). Approach, where filelist.txt contains file ...
1
vote
2answers
315 views

How to copy a folder by overwriting an existing folder and delete all the old content in Linux?

I can use rm to delete the old folder, then use cp to copy the new folder. But how to do it in one go?
1
vote
3answers
2k views

Linux 'cp' copies symlink instead of target file

In my directory I have 2 files: a text file and a symbolic link to that text file. base_v21.txt -> base_v001.txt base_v001.txt When I try to copy base_v001.txt using the following command: # cp ...
-1
votes
2answers
4k views

COPY file from one server to another [closed]

I have to get some files from production to DEV server. SCP command gives the timeout. I do not have ip and I connect to the server using ssh command as below. ssh komz-admin@pxxxxxxx04.corp.xxx....
0
votes
2answers
66 views

answering command automatically - performing cp operation between answers [closed]

The idea is that I want to execute a command, then it asks for a file name to process, and after it is done with processing, it outputs an image with the name prediction.png, it asks for the next ...
2
votes
1answer
43 views

Why does cp need -r while mv doesn't? [duplicate]

To copy a directory and its contents cp requires a -r switch. To move a directory and its contents mv does not require a -r switch. What is the reason for this? EDIT: Don't worry. Despite searching,...
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 ...
16
votes
2answers
8k views

Why is mv so much faster than cp? How do I recover from an incorrect mv command?

I drag and drop a folder into another by mistake in FileZilla. ~/big_folder ~/some_other_folder The folder got moved is a very huge one. It includes hundreds of thousands of files (node_modules, ...
1
vote
4answers
91 views

Copy files adding the path into the filename

I want to copy mp3 files from a directory to a flash drive. They are stored in a directory structure such as this: Artist/Album/Track.mp3. Since my car's mp3 player sucks, I want to have all my mp3 ...
4
votes
2answers
1k views

Making alias of rm command [duplicate]

Making alias of rm command so that when rm command is executed it will first copy file to /tmp/recycle_bin and then remove the file. But I'm getting issue in the process. Steps performed by me: I ...
2
votes
1answer
324 views

AIX 6.1 copying files with non-standard characters in file names [closed]

I have a big problem with some non-standard characters while trying to copy (for the sake of backup) some files in AIX 6.1. What I need to do is have the backup archive with exactly same file names in ...
2
votes
1answer
406 views

Can't copy files into directory which has enough group permissions

I would like to do this: XXXX:xxxadm 53> cp /user/uz408217/transporty/K900730.ZAT /usr/sap/trans/cofiles But end up with this error: cp: cannot create regular file `/usr/sap/trans/cofiles/...
5
votes
5answers
670 views

How to move content of a folder to current folder?

I have this folder structure: foo `----> bar How can I extract the content of bar into foo? I tried mv -f bar/* . from within foo. -f, --force | dont't ask before overwrite but I get "could ...
1
vote
3answers
1k views

copy the file and keep full path

I need to copy the file to destination folder with it's full path. I can do it on Linux (Red Hat/Centos) easily like this: cp --parents /some/path/to/file /newdir Then I get, in destination ...
1
vote
2answers
54 views

How can I copy a file and paste it as a different name?

I have a file test.txt in directory A/B. I want to copy test.txt to A/C and rename it newtest.txt. I know I can use the cp and mv commands to do this, but the issue is that there already is a test....
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 ...
3
votes
3answers
47 views

Copy files under modified name

I have to find all files in a directory ending by number (this part is OK) and copy them under a modified name (I don't know how to do this part). Typically: find $folder -maxdepth 1 -type f -name '*-...
0
votes
1answer
40 views

bash4: cp command cannot see files when enclosing file path inside a double quote

consider the following terminal output (inside a .sh file) kagura@mylaptop1 : ~ => sudo cp -a "$_source/*.txt" $_destination/Other/ Password: cp: /home/myuser/*.txt: No such file or directory 08:...
2
votes
1answer
59 views

Symlink some file of a tree to another folder and conserve folder structure

Assuming this tree (top-X & tX-sub-X are folders, and all sub-folder containing a .csv and various other file extensions.) Base ├── top-1 │ ├── t1_sub-1 │ ├── t1_sub-2 │ └── t1_sub-3 │ └─...
1
vote
1answer
22 views

How to copy several not-subfolders in one shot?

Assume my current path is /home/inp/Documents/Folder I would like to copy folders /home/inp/Test1/randomName1 and /home/inp/Test1/randomName2 from my current path. Currently, I use the following ...
0
votes
2answers
137 views

How to copy desired log file content when logs are frequently being rotated in Linux [closed]

Suppose some logs is being rotated by size 50MB each . I did grep some string and my string is present in a log file, log_3 and I want to copy the content of log_3 before it gets rotated(renamed) to ...
1
vote
1answer
123 views

What is the closest for `cp` to `rsync -a`?

From manpage of rsync, -a, --archive This is equivalent to -rlptgoD. It is a quick way of saying you want recursion and want to preserve almost everything (with -H being a notable omission)...
0
votes
1answer
1k views

Recover an overwritten file with cp

I have just copied a file main.tex from /path_1/ to /path_2/: cp path_1/main.tex /path_2 path_2 already contained main.tex, so it has been overwritten. Is there a way to recover the original main....
0
votes
1answer
119 views

Problems using cp -r command

I have a series of data with format data*.csv where the first data is data658000.csv and last data is data2040000.csv. The data is every 2000 counts. I want to filter the data every 90000 counts so I ...
5
votes
3answers
777 views

How to copy a file with unique name without navigating to directory?

Let's say I have a file with a unique name (e.g.Screenshot20180509143013.png) that I wish to copy to /media/SD256. The file /media/drive1/Users/name/Pictures/Screenshots/Screenshot20180509143013.png ...
0
votes
1answer
126 views

bash script to find files thinks the file name should be an integer

I am writing a script to obtain a list of file names from a text file, so that it can find the files and copy them to a specific folder. When I run the script, I get the following error: ./...
0
votes
1answer
67 views

`cp` behaves differently after `mvn clean`

So, I am working on a build script for a Java project, and I don't to run mvn clean during local development. So I have created a flag for developers -k which sets the variable $DEV_BUILD to 1. ...
1
vote
0answers
72 views

`cp` fails writing to file / directory while `cat >` and `echo` work fine

On a RHEL 7.2 based system I try to copy files to a smb mounted location: cd /target cp /tmp/foo . This fails with this error message: cp: cannot create regular file ‘./foo’: Operation not ...
0
votes
2answers
2k views

Append the current date and time to the file name

What can I add to this command to append the current date and time to the file name? find . -maxdepth 1 -type f ! -name "*.*" -exec cp -p -t /new/location {} \+
1
vote
1answer
64 views

cp command recursively writes directories

I have a standard .ssh directory in my user home dir. I have this command: cp -rf "$HOME/.ssh" "ssh/prod" I get this situation: does anyone know why it's recursively writing out subfolders in the ...
4
votes
5answers
292 views

Move folder structure across multiple directories [duplicate]

I am trying to move one a bunch of files at once, one directory up. This is what I tried, but did not work: mv ./*/__test__/index.js ./*/data.js . ├── alpha │ ├── __test__ │ │ └── index.js │...
1
vote
1answer
100 views

Why can't a project compile with symbol link

I'm working in a team, which develops a c++ (ROS) project. For some reason, we haven't a good git management. We have several git branches. To compile the project, I have to git clone the codes from ...
0
votes
2answers
245 views

Recursively move specific files in nested directories to a name derived from the path

I have some files in different nested directories. All the files are named Analysis.mzXML. I would like to have them all in one place, while changing the name of each one to something different, ...