Questions tagged [cp]

cp - Command-line tool to copy a file

Filter by
Sorted by
Tagged with
0 votes
1 answer
20 views

How to copy a file to a subdirectory path which is the same for multiple directories?

I wrote a git commit hook and tested it out in a repo called myrepo. I would now like to copy it to all the repos I have in my ~/repos folder. To do that I tried: $ cd ~/repos/myrepo/.git/hooks $ cp ...
user avatar
0 votes
0 answers
28 views

Is there a faster way to copy from terminal on macOS?

I just copied 1TB of files, zillions of them, from one external USB disk to another and it took 2 days over 5GBPS USB. I have used rsync. rsync seems to me to be serial, I mean, one file at a time. I ...
user avatar
  • 4,234
0 votes
1 answer
84 views

copying files from multiple specefic parent directories

I would like to copy files from the current directory which are divided into different subdirectories. The files I want to copy should only have True and False as their parents. True directory files ...
user avatar
0 votes
2 answers
27 views

Copy a file with its parent dirs to a destination directory

Source file : ~/SCRIPTS/script Destination directory : ~/TMP/LAB the command should be something like : <command> <option> ~/SCRIPTS/script ~/TMP/LAB Desired result after the command : ~/...
user avatar
  • 874
0 votes
1 answer
36 views

How to combine find and cp in linux to copy specific files

I am having the following problem in linux: I need to find specific files from a directory and copy those files (if they exist) into another directory this is the command (i need to find specific text ...
user avatar
  • 3
1 vote
1 answer
25 views

Automatic rollback to files copied with the backup argument

I'm making an update protocol for an embedded linux system, but I want to give users the option to roll back the update if it messes with their system, especially for alpha/beta releases. So I ...
user avatar
0 votes
1 answer
41 views

Is there a more reliable cp and mv which verifies the file and / or folder transferred to be identical? (such as by rsync?)

Is there a way to use cp and / or mv so that it verifies the files to be identical. This is especially true for mv, which would remove the original file, so if the destination file is corrupted, then ...
user avatar
1 vote
1 answer
111 views

Is cp faster than rsync during the first run?

I am currently using rsync to copy a 73GB file from a Samsung portable SSD T7 to an HPC cluster. rsync -avh path/to/dataset me@server.somewhere:/path/to/dest The following applies: My local machine (...
user avatar
  • 113
0 votes
1 answer
42 views

Do grep and cp treat "recursive" the same?

I'm having trouble with grep's manner of interpreting "recursive" searching compared to cp. Maybe it's just that I use them differently. In this, grep seems to interpret "recursive"...
user avatar
1 vote
0 answers
33 views

Can I use rsync to replace newer files with older files?

Assume the following: source: - foo 3/1/2021 - bar 2/1/2021 - foobar 1/1/2021 destination: - foo 1/1/2021 - bar 2/1/2021 - foobar 3/1/2021 Suppose I want rsync to replace newer files ...
user avatar
0 votes
0 answers
31 views

Copy all unique files from multiple directories into one. Rename duplicate names & preserve extension file.png, file (1).png

I'd like copy all unique files from multiple directories into one. Rename duplicate names & preserve extension file.png, file (1).png etc. At least I'd like to merge all files from all directories ...
user avatar
0 votes
1 answer
66 views

How can i get permission to copy files from one folder to another?

So i was trying to copy some files from one folder to another using the cp command, but when tried it gave me this error: debian@OCR-1:/mnt/rootfs/boot$ ls MLO omap3-overo-storm-arbor43c....
user avatar
0 votes
0 answers
55 views

Diff says that files differ after copying them with cp -a

I have a flash drive which I backed up onto a disk with the following command: cp -a /media/user/flashDrive /home/user/Documents/flashBackup Now I just wanted to quickly check if the files were ...
user avatar
-2 votes
3 answers
50 views

cp with matched pattern of parent directories

copy directory with a matched pattern of parent directories cp dir/group1/sub01/./././DCM dir/group2/sub01/././DCM to dir/Base/group1/sub01/Time1/ dir/Base/group2/sub01/Time1/ with matched group ...
user avatar
18 votes
2 answers
2k views

I've copied a directory with `cp -as` and now I'm terrified to `rm -rf` the created directory as it might delete the original

I've copied a directory with cp -as /media/user/dir symlinks and now I'm terrified to rm -rf symlinks as it might delete files in /media/user/dir What is the safe way to only delete the directory ...
user avatar
  • 299
0 votes
1 answer
88 views

Copy files to directory in the same structure without the parent folder

I have a few .html files that I need to copy from one place to another. The source folder has files other than .html, so I need to first find only the .html files and then copy them to the other ...
user avatar
6 votes
2 answers
1k views

How to copy a file by using its inode number?

This problem is related to Samba and inodes are not necessary. I have a problem handling a certain file that has some special characters in it. If I search it by its inode it will list the file: $ ...
user avatar
  • 295
0 votes
2 answers
550 views

"cp -f" is failing because "file already exists" [closed]

I have a postinstall script that runs cp -f ./foo/a.json ./node_modules/bar/a.json and it is failing with an error that the file already exists (which it does, but I'm trying to overwrite it with my ...
user avatar
  • 101
0 votes
0 answers
45 views

Unable to copy video to flash drive properly

I tried to copy a video file to flash drive but when I eject it and insert it again the 1.4gb video size comes down to 160mb, 320mb. I used cp and rsync command I also tried to unmount, safely eject ...
user avatar
0 votes
2 answers
214 views

copy file with different names in current directory shell script

My bash script echo -n "Round Name:" read round mkdir $round echo -n "File Names:" read $1 $2 $3 $4 $5 $6 cp ~/Documents/Library/Template.py $1.py $2.py $3.py $4.py $5.py $6.py . ...
user avatar
2 votes
2 answers
763 views

How to copy all files without a specific extension to another directory?

I have two directories dir1 and dir2. I want to copy all the files and folders in dir1 to dir2 except the files that have .txt extension. How I can do this?
user avatar
  • 232
0 votes
2 answers
237 views

What does the -a option do exactly with the cp command?

I am trying to understand what the -a option does exactly with the cp command? The man pages on my system does not give much information about this.
user avatar
  • 170
0 votes
1 answer
39 views

The destination location of command: cp -rf ../path/to/dir * [duplicate]

I accidentally used this command: cp -rf ../path/to/dir * rather than this: cp -rf ../path/to/dir . Now I wonder where the directory is actually copied to! Does anyone know?
user avatar
  • 1,315
0 votes
1 answer
104 views

Copy directory but exclude files with certain names

I'm not allowed to use rsync on the cluster I'm working on so I need to use things like cp or tar or find etc. I want to copy a large directory including all files and subfolders etc. while ignoring, ...
user avatar
0 votes
0 answers
27 views

Does `cp` leave unfinished file if interrupted? [duplicate]

Suppose I am copying a lot of files with cp and use Crtl-C to interrupt it. Can I safely assume all copied files in the destination are valid?
user avatar
0 votes
2 answers
3k views

cp: cannot stat permission denied

I have a file called fileArc.c and I was given instructions for an assignment that if I do the command cp fileArc.c /pc that this file would then be accessible in a created folder on my desktop. ...
user avatar
  • 1
0 votes
0 answers
47 views

Combining recursive find, numbered backup, & copy for multiple files with the same name in subdirectories and subdirectories of those subdirectories

r.xml are the files, and s is output directory. What I want is the s directory to contain r1.xml, r2.xml, etc.. $ ls -R s temp temp3 ./s: ./temp: r.xml temp2 ./temp/temp2: r.xml ./temp3: r....
user avatar
-1 votes
1 answer
84 views

Pattern matching not working with cp?

I have two files I want to copy; A.txt and B.txt. I also have a variable with an expression that should match those two files "*.txt". However running cp $var [destination] or cp "$var&...
user avatar
2 votes
0 answers
77 views

Are there any "richer" alternatives to cp and mv (like bat to cat and exa to ls)?

ls has exa. cat has bat. I don't know of a direct alternative to rm, but it also has rmtrash. All of these can usually work as drop-in alias replacements, retaining usual function and options of their ...
user avatar
12 votes
2 answers
816 views

cp command follows symbolic link at destination and clobbers link target instead of overwriting link

I have a symbolic link, sd/common.py -> actual_file, and I want to replace the link with a generated file. However, whenever I do cp /tmp/Star_Wrangler/common.py sd/common.py ... it copies from /...
user avatar
10 votes
1 answer
2k views

Why can't I copy all files in a directory to a USB storage device?

The sdc1 was mounted on /media/debian/Ventoy. debian@debian:~$ sudo blkid | grep Ventoy /dev/sdc1: LABEL="Ventoy" UUID="F82D-76BE" BLOCK_SIZE="512" TYPE="exfat" ...
user avatar
  • 85
0 votes
0 answers
15 views

batch copy multiples .txt with pathname on filename [duplicate]

I am trying to batch copy a lot of .txt files from various directories to Directory "all_txt" I am using fzf to find all text files. simple copy cp dir1/file1.txt dir1/file2.txt dir2/file3....
user avatar
  • 77
-1 votes
1 answer
91 views

copying files with same names

I have directories --dir1 image1 image2 image3 --dir2 image1 image2 image3 --dir3 image1 image2 image3 I want to copy all the files (that have the same names) from ...
user avatar
-1 votes
1 answer
41 views

How to: Copy Images from Gnome to public_html on same server

Hi there I am using CentOS7 as server + GUI. I want to move pictures from Gnome to a public_html directory. What is wrong with my command? cp -R ~orca/Documents/Tree\ of\ Knowledge/oceanahomes.com/...
user avatar
1 vote
1 answer
92 views

how to globally unalias rm cp mv in RHEL 7

from a clean instal of RHEL 7.9 x86_64, all users (including root) have a bash shell. And the commands mv and cp and rm are aliased to have the i option to them. Which I do not like; how does one ...
user avatar
  • 4,251
1 vote
0 answers
305 views

How to copy entire directory as is (failed to preserve ownership)

I am trying to prepare Raspberry Pi image to be netbooted. I have downloaded IMG file of raspbian (for ex 2017-07-05-raspbian-jessie) and mounted it locally to linux box. I got two partitions. Now I ...
user avatar
  • 2,617
1 vote
1 answer
73 views

(Almost-)Atomic way to merge 2 folders

I'm exploring the different ways to add some consistency to a file deployment operation. The current situation is : A current version folder which contains approximately 100K different files /current ...
user avatar
  • 113
0 votes
1 answer
20 views

Copy uppercase name file bug

Enviroment: Debian 11 and 10 I try to copy the whole folder "/lib/modules/5.12.10" in Debian to USB. But I found there are 8 files will confuse system which are: xt_dscp.ko xt_DSCP.ko xt_hl....
user avatar
  • 21
1 vote
1 answer
176 views

GNU cp: What's the difference between `--link` and `--reflink=always`?

What's the difference between --link and --reflink=always? I use the following command as an mv substitute, and I am wondering if using --reflink is a better choice. command gcp -r --link --archive --...
user avatar
  • 1,295
0 votes
2 answers
80 views

Does the speed of operations on a file (copy, move, remove) depend on permissions of that file?

Does the speed of operations on a file (copy, move, remove) depend on permissions of that file? If so, then how? Reason: need to constantly perform mentioned operations on many files. Will these ...
user avatar
  • 397
0 votes
1 answer
41 views

find -newerct filter on cp-copied files has different result compared to original files

I've migrated some 73k files from source/ to dest/ with cp -pR. Before I did that I checked with find source/ -type f -newerct $(date -d @1623247288 +"%Y-%m-%d") that I can grab new files. I ...
user avatar
1 vote
1 answer
291 views

cp vs. cp -r on symlinks

I recently experimented with the cp command, and noticed the following: Lets assume we have a folder foo, containing the file bar and the symbolic link l-bar: foo |-- bar |-- lbar -> bar When ...
user avatar
  • 125
0 votes
1 answer
77 views

AIX create directory when copying

What is the best way to create a directory that does not exist when copying files in AIX? Something like this: ssh server1 'cp -R ~user1/bin/log ~user2/bin/log' cp: /u/user2/bin/log: No such file or ...
user avatar
  • 1,021
-1 votes
1 answer
122 views

Why is this simple bash script destroying my computer?

Something weird is happening with a seemingly inoffensive script I have. I need to copy a series of files to some locations in the system and I have the following script to do so. #!/bin/bash # Get ...
user avatar
  • 166
2 votes
3 answers
94 views

Copying all files from a directory but not a specific file from a sub directory

I have a directory structure as below: source-dir--- |----- file-1 |----- file-2 |----- file-3 |----- folder-1 |---- file-4 ...
user avatar
  • 161
1 vote
0 answers
522 views

Moving sparse files

cp not only auto-detects sparse files but also has --sparse=always option. I wonder if mv works with the same mechanism or the safe way for moving sparse files is cp && rm Or is there any ...
user avatar
  • 1,723
0 votes
1 answer
35 views

copy files from multiple remote machines to local and create directories for remote machines

Have multiple vm machines that am using for studying, and have come up with this script for copying some files from vm's to my local machine: SG=rohos; date; for i in `cat /etc/hosts | grep "$SG-&...
user avatar
2 votes
1 answer
91 views

cp command doesn't overwrite, but creates new folder (second time, third, fourth, .. time it works) [duplicate]

I use the following command to copy a folder (named 'dist') containing a react project to my frontend folder: cd apps/react-app sudo cp -R dist ../server/frontend/client The first time I run the 'cp'-...
user avatar
  • 121
0 votes
1 answer
79 views

Copy all non-text files

I need to move all files not ending with the .txt, .cpp, and .h extensions in one folder to a seperate folder via the cp command. Is there a built in way to do this or do I need to make a script?
user avatar
0 votes
0 answers
37 views

Copying recursively

Why is it that when using cp -r or scp -r, if say you have a folder containing a large number of files but only byte-sized or a couple of kilobytes at most and you have another file the same size as ...
user avatar

1
2 3 4 5
15