Questions tagged [cp]

cp - Command-line tool to copy a file

Filter by
Sorted by
Tagged with
5
votes
1answer
1k views

How to determine if cp -u actually copied the file?

I'm looking for a concise way to check if a file was copied using cp -u. I have a little shell script which updates quite a number of files. At the moment the script echoes a little message for each ...
1
vote
0answers
910 views

Can't make a copy of /var/lib/mysql/ibdata1

I have a RedHat Linux server and I'm trying to make a copy of /var/lib/mysql/ibdata1, but I'm receiving an error saying permission denied and the file cannot be opened. I'm logged in as root user and ...
1
vote
2answers
105 views

Compare existing file in two different directories, copy if not existent, else overwrite it

I'm trying to build a scrip that compare a file inside different 2 dir,then copy them from dir1 to dir2 is it's not exists in the dir2, or overwrite it if its already existed. I know that i can use ...
0
votes
3answers
148 views

Fix space in path from find command [duplicate]

I would like to copy many files with the below command. cp `find /Volumes/DATA/ -name "*.app" -depth 1 2> /dev/null` /Volumes/VMWare/img/ But that doesn't work because if it finds a space then ...
1
vote
1answer
4k views

Find last file in directory where the filename's end matches a string

I am writing a script to create/copy files to speed up workflow. In this instance a directory needs to be searched for files ending in a specific string, and if one or more is found the last one in ...
53
votes
6answers
75k views

Using rsync to move (not copy) files between directories?

I have been using rsync to copy files for some time. My understanding is that rsync is faster than cp when some of the files to transfer are already in the destination directory, transferring only the ...
0
votes
2answers
57 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 ...
25
votes
2answers
4k views

Purpose of cp -x (stay on file system)?

If I wanted to stay on the same file system, couldn't I just specify an output path for the same file system? Or is it to prevent accidentally leaving the current file system?
0
votes
2answers
267 views

Rename Files to Same Filename Without Extension with find Command

I'd like to rename a group of files to their same filename but without extension. They are scattered in my home directory and I don't know where they are located precisely, but I do know the extension ...
3
votes
3answers
424 views

How to use cp -u on a Solaris system which does not support the -u option?

I want to copy only when the SOURCE file is newer than the destination file or when the destination file is missing. As you know, this feature will work on Linux system on following command. cp -u /...
-4
votes
2answers
2k views

In Unix how would I copy /etc/passwd using relative path to a directory under my home directory? [closed]

I am required to copy the /etc/passwd to a directory, I have already created, with the new name my_passwd. I understand how to copy it with an absolute path: cp /etc/passwd /home/user/work/my_passwd. ...
31
votes
3answers
66k views

Better way to copy multiple directories to new directory

Is there a better way on the command line to essentially accomplish the following but with a single command cp -r css/ ar/ cp -r images/ ar/ cp -r js/ ar/ cp -r backups/ ar/ I've just been stringing ...
4
votes
3answers
1k views

Back up logs to a new directory

I need 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 20 MB ...
3
votes
2answers
701 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 ...
7
votes
5answers
25k views

How to copy and add prefix to file names in one step?

I want to copy and rename multiple c source files in a directory. I can copy like this: $ cp *.c $OTHERDIR But I want to give a prefix to all the file names: file.c --> old#file.c How can I do ...
-1
votes
1answer
10k views

How to solve error of missing destination file operand after '/sdcard/ngrok/ngrok ' in termux [closed]

I am using termux in my android but I get the following error when I want to copy some data from sdcard to $HOME IN TERMUX the following error shows up: missing destination file operand after '/sdcard/...
0
votes
1answer
58 views

Copy files according the filename containing a future date in a specific format

I have these files, for example: 20029181109173105_MAN_TDR.PLU 20029181109185001_MAN_TDR.PLU 20029181109185301_MAN_TDR.PLU 20029181109185601_MAN_TDR.PLU 20029181109185901_MAN_TDR.PLU I need to copy ...
1
vote
1answer
41 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 ...
4
votes
2answers
2k 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 ...
29
votes
6answers
8k 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
144 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
82 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
23 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
255 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
85 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
61 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
98 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 ...
32
votes
3answers
70k views

Copy first n files in a different directory [duplicate]

Possible Duplicate: How to move 100 files from a folder containing thousands? Is it possible to copy only the first 1000 files from a directory to another? Thanks in advance
1
vote
1answer
112 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 ...
49
votes
4answers
38k 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
2k views

What's the best way to copy files from an ext3 file system to a NTFS and maintain the ownership and permissions?

I need to transfer over 1 Tb of data from a share on an ext3 file system that our corporate office uses. The share contains files with different owners and groups and needs to be copied over ...
3
votes
1answer
170 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?
7
votes
4answers
23k views

Copy multiple files from filename X to filename Y?

What I want to do is to copy files within a lexicographic range. Example of files: -rw-r--r-- 1 root root 15276 Oct 5 2004 a2ps.cfg -rw-r--r-- 1 root root 2562 Oct 5 2004 a2ps-site.cfg -...
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
155 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 ...
3
votes
3answers
3k views

What does `cp -x` do?

I know in the man pages it puts it as -x, --one-file-system stay on this file system but can someone explain it to me like I'm five.
1
vote
2answers
3k views

Copy files that are created today without FIND command and SFTP to another server

I have a directory with 'n' number of files in it. I am trying to write a shell script which will list only the files created on the particular day the script is running, and will use sftp to move the ...
5
votes
2answers
6k views

issue with find -exec cp

Consider this example: touch test0 touch timestamp touch test1 sudo find /var/www/import -iname 'test*' -newer timestamp -exec cp {} new \; It actually copies file test1, but it returns the message: ...
0
votes
2answers
871 views

Copy files with different names from different directories

I am trying to copy multiple files with different names from different directories, to one same new directory. The names of the directories are the same as the beginning of each filename. For example ...
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 ...
2
votes
1answer
829 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
93 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
777 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
97 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
358 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
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....
1
vote
2answers
7k views

ls shows a directory but it is inaccessible

I was trying to copy one folder from one location to another. The folder is about 6.4 Gb. So I did cp -r source_folder level1/val after that, I went into the level1 folder and checked: level1$ ...
1
vote
3answers
2k 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 ...
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 ...
10
votes
2answers
3k 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 ...