Questions tagged [cp]

cp - Command-line tool to copy a file

Filter by
Sorted by
Tagged with
1
vote
2answers
82 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: $ ...
0
votes
2answers
71 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 ...
0
votes
0answers
43 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 ...
0
votes
2answers
90 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 . ...
2
votes
2answers
336 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?
0
votes
2answers
40 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.
0
votes
1answer
29 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?
0
votes
1answer
46 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, ...
0
votes
0answers
26 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?
0
votes
2answers
590 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. ...
0
votes
0answers
19 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....
-1
votes
1answer
42 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&...
2
votes
0answers
53 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 ...
11
votes
2answers
672 views

cp command follows symlink at target and obliterates file instead of overwriting symlink

I have a symlink sd/common.py -> actual_file I would like to replace the symlink with a generated file, but when I do: cp /tmp/Star_Wrangler/common.py sd/common.py It copies from common.py and ...
10
votes
1answer
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" ...
0
votes
0answers
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....
-1
votes
1answer
71 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 ...
-1
votes
1answer
37 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/...
1
vote
1answer
54 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 ...
1
vote
0answers
159 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 ...
1
vote
1answer
47 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 ...
0
votes
1answer
16 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....
1
vote
1answer
72 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 --...
0
votes
2answers
58 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 ...
0
votes
1answer
27 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 ...
1
vote
1answer
105 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 ...
0
votes
1answer
52 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 ...
-1
votes
1answer
116 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 ...
2
votes
3answers
80 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 ...
1
vote
0answers
317 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 ...
0
votes
1answer
32 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-&...
2
votes
1answer
43 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'-...
0
votes
1answer
39 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?
0
votes
0answers
36 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 ...
1
vote
1answer
54 views

How do I duplicate file n times and then create a function in .zshrc?

This may be a duplicate of Duplicate file x times in command shell and is definitely a duplicate of How to duplicate a file a number of times while embedding an index in each file but the person who ...
0
votes
2answers
53 views

How to copy target files using symlinks and a list of file names

I would like to copy many files. I have their location as a set of symbolic links whose names are stored as lines in a txt file. So I am using cp and need to combine the readlink and cat/pipe ...
1
vote
1answer
198 views

Does cp (copy) pre-allocate space with fallocate()?

When copying large files (1-2 GB per file) between file systems, file fragmentation can happen if the destination file system is nearly full. Our C++ application code uses fallocate() to pre-allocate ...
0
votes
1answer
675 views

How to copy files with multiple extensions in a Dockerfile?

This syntax of copying files with multiple extensions (per Copying files with multiple extensions) works fine in a regular desktop environment: $ mkdir /tmp/baz && cd /tmp/baz $ touch /tmp/...
7
votes
3answers
1k views

Retaining permissions when copying a folder [duplicate]

I am having an issue where I have Parent folder that has full permissions.. I can create a new folder and that folder also has full permissions. However when I copy a folder over to this parent ...
0
votes
0answers
29 views

Copy specific file type keeping the folder structure from remote server [duplicate]

Similarly to Copy specific file type keeping the folder structure I am looking to copy over only specific file types (or files with names containing specific strings) preserving the folder structure. ...
0
votes
1answer
415 views

How can I copy multiple files inside a bash script [duplicate]

I want to know how can I copy or shell copy multiple files within a bash script. What I mean is that cp /path/to/source/{file1,file2,file3} /path/to/dest and scp /path/to/source/{file1,file2,file3} ...
1
vote
2answers
95 views

cp command based on parent directory

I have several folders within a parent folder, which all have the structure below, and am struggling to create a specific loop. parentfolder/folder01/subfolder/map.png parentfolder/folder02/subfolder/...
0
votes
1answer
72 views

find & copy command is not copying same number of files

I'm trying to use find & copy on some files but the problem is if i only run find command and check wc it shows some result, after copying these files to some other directories it shows some other ...
-1
votes
1answer
44 views

copy files from the folder on one disk to the folder on another disk

how to copy files from the folder on one disk to the folder on another disk use cp command? (from the current directory on sda2 to folder on /dev/sdb3?)
0
votes
1answer
73 views

Need cp -ax alternate for Solaris

On my Linux host; this cp command helps copy files and folders both while preserving the timestamp and permissions cp -ax <source file/folder> <destination> Need similar command for SunOS ...
1
vote
2answers
113 views

Shell script on Raspberry Pi fails to copy files from usb0 to directory

I am trying to write a shell script to copy specific files from an archive USB thumb drive to my Rasberry Pi 4b. The script is, in my opinion, brain dead simple. cp /media/usb0/archive/file1.zip /home/...
0
votes
4answers
201 views

cp files with pattern with middle directory variable

I have a directory l ── 10020 │   ├── live │   │   ├── 211231.jpg │   │   ├── 211231_BB.txt │   │   ├── 448378.jpg │   │   ├── 448378_BB.txt │   │   ├── 460830.jpg │   │   └── 460830_BB.txt │   └── ...
0
votes
0answers
128 views

how does the cp - f work in Unix? [duplicate]

I was reading about the cp command in unix and one of the options is: cp -f : force copy by removing the destination file if needed so I wanted to test this to see how it works, I did the following: ...
0
votes
2answers
153 views

Using xargs to copy directories

I'm trying to write a script to copy a set of directories that were created today to another directory. I'm currently using: find /test/downloads/ -mindepth 1 -maxdepth 1 -type d -mtime -1 -printf '%f\...
5
votes
2answers
199 views

If cp's destination path turns out to be a directory, how do I avoid mistakenly creating files inside that directory?

My understanding of cp src dest is: If src is a file and dest doesn't exist, but its parent directory does, dest is created. If src is a file and dest is a file, dest is overwritten with the contents ...

1
2 3 4 5
15