Questions tagged [cp]
cp - Command-line tool to copy a file
778
questions
0
votes
2
answers
212
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
1
answer
134
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
1
answer
2k
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
1
answer
190
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
1
answer
196
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
3
answers
402
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
0
answers
1k
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
1
answer
72
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
1
answer
603
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
1
answer
227
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
0
answers
38
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
1
answer
251
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
2
answers
222
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 ...
2
votes
1
answer
798
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
1
answer
3k
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
3
answers
4k
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
0
answers
35
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
1
answer
3k
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
2
answers
673
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
1
answer
177
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
1
answer
1k
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
1
answer
214
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
2
answers
311
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
4
answers
585
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
0
answers
1k
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
2
answers
1k
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
2
answers
2k
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 ...
0
votes
1
answer
98
views
How do I copy variously named files with the same extension to all have a standard file name?
I have variously named files such as in different subdirectories e.g.:
a/apple.txt
b/orange.txt
c/pear.txt
How do I copy them to have a uniform name (fruit.txt) in their respective directories so the ...
0
votes
2
answers
604
views
Copy file in multiple (variable) folders
I want to copy files in multiple subfolders with variable subfolder names.
Example:
mkdir rootdir
mkdir rootdir/dir1
mkdir rootdir/dir2
mkdir rootdir/dir3
touch rootdir/dir1/foo.txt
touch rootdir/dir2/...
0
votes
1
answer
458
views
Restore ENTIRE system ROOT / (CLARIFICATION)
I recently had to restore the disk with borg. So via live linux, I entered my disk file system, deleted everything (root /), and restored a backup of a specific date. Now I ask myself: do you need to ...
2
votes
1
answer
5k
views
Copy and rename files recursively using part of folder name for new name
I'm trying to recursively copy a folder of files containing .csv extensions and rename them while copying them into a single folder.
I'm close except for the file renaming which eludes me.
Can anyone ...
0
votes
1
answer
7k
views
Make sure that the "cp" command is executed properly
I make a backup copy of my files with cp command as described in this topic (Copy files in Linux, avoid the copy if files do exist in destination): https://superuser.com/a/1377730/1008457
Command is:
...
0
votes
1
answer
2k
views
Does the 'cp' command continue to copy all files if it has a permissions problem with one file or folder?
In OS X Mojave / bash, I am in my home directory copying all files using the cp command from the directory ~/Pictures/ to ~/Dropbox/Pictures/ and as often happens when copying without sudo on *nix, I ...
0
votes
1
answer
251
views
Copying to external device messes up special characters in NixOS
I have a DAP (like an mp3 player) and I am trying to sync up the contents of one of the folders on my pc to the DAP. This does work almost as intended, but something weird is happening to the ...
0
votes
1
answer
175
views
Storing find results in variable then passing to cp?
I have a need where I must work with a set of files based on time elapsed (as I do not have control over when new files are added to the remote directory).
I must do several operations with this set ...
0
votes
0
answers
1k
views
I get this error when copying some files with rsync: "rysnc: read errors mapping “…” input/output error" - I can open and watch the file in VLC
I am using rsync to clone hundreds of video files to another hard drive. There were 3 files which had the exact error as below:
rsync: read errors mapping "/var/run/importcopy/tmpdir/dev/da1s1/...
1
vote
1
answer
965
views
How to copy a file and change destination file permission in one step?
I am writing a shell script to do some complex task which is repetitive in nature.
To simplify the problem statement, the last step in my complex task is to copy a file from a particular path (which ...
0
votes
0
answers
24
views
Can someone please explain in lay-mans terms what cp -arxpf does?
I'm inept at understanding the manual apparently. I read 'sudo cp -arxpf...'
Can someone please explain to an idiot (me) what the -arxpf options do in the copying?
Thanks in advance,
Rob
1
vote
3
answers
992
views
How do I copy a file without pasting immediately from terminal? [duplicate]
When using the command "cp", I need to know where exactly I want to paste my file. Often, I have to copy a file but without having to paste immediately or sometimes I do not know where I ...
1
vote
1
answer
308
views
cp -r: trigger "No such file or directory" error instead of creating "dst"
Case 1: If dst does not exist, then cp -vr src dst creates dst and copies all the content from src to dst:
$ cp -vr src dst
'src' -> 'dst'
'src/t0.c' -> 'dst/t0.c'
Case 2: If dst does exist, ...
0
votes
2
answers
3k
views
Disc quota exceeded, cannot create, copy, or move files... is there another way?
I'm sshing into a remote server to complete some work. I tried to edit a file in nano, but realized, after saving and exiting, the file (quite a lot of work) was empty. Apparently, my disc quota has ...
2
votes
1
answer
2k
views
Simple cp command not working (inside shell script and submitted using sbatch on a cluster)
I am working on a cluster running RHEL and I submit jobs using the following command.
sbatch MyScript.sh
The content of the MyScript.sh are as below.
#!/bin/sh
# ....
# Other SBATCH related commands ...
1
vote
0
answers
93
views
Diskless root filesystem starts to break when copied to a new location
I am pxe booting using nfs to get a diskless cluster. When doing testing I wanted to make a copy of the directory used by the nodes to mount the linux root filesystem. But after copying the file over ...
0
votes
2
answers
61
views
I copied a file into my VM, but the folder is a regular file
I'm new to Linux, and I'm trying to untar the following file, so I moved from GCS to the Virtual Machine with the following command
gsutil cp gs://ghtorrent_datadump/mysql-2020-07-17.tar home/...
0
votes
2
answers
2k
views
copy a directory into another directory and create intermediate directories
I would like to copy the whole /usr/share/zoneinfo/ directory into /var/www/clients/client1/web5/./usr/share/zoneinfo/. (The /./ is added for clarity and formatting purposes)
The directory /var/www/...
7
votes
3
answers
2k
views
Effect of 'cp /dev/zero a' when file a exists
If a exists and I type
cp /dev/zero a
can I be sure the old contents of a will be overwritten, or will
I simply get the equivalent of
rm a
cp /dev/zero a
PS. I am not suggesting that this is the ...
1
vote
2
answers
539
views
Copy file recursively to all deepest subdirectories
I'm trying to copy a single file to all of the deepest subdirectories in a tree structure. Imagine it looks like this:
bar
dir1
| |
| +--dir2
| |
| +--dir3
| +--dir4
| |
| +--...
1
vote
1
answer
265
views
How can I copy directory itself with attributes?
I would like to copy only attributes of a directory to existing directory.
for example...
# mkdir /var/tmp/target-dir
# ls -ald /var/mail
drwxrwsr-x 2 root mail 4096 4月 27 2018 /var/mail
my image ...
0
votes
0
answers
69
views
cp copies from hard drive to USB 3.0 stick with transfer speed below 1.7MB/s!
Aspire One Cloudbook 14 (A01-431-C8G8)
Linux kernel 4.19
Debian 10
Hi: I have a USB 3.0 pendrive (stick) plugged into a USB 3.0 slot in the laptop. I copied (cp) all files in one of the laptop ...
4
votes
0
answers
243
views
What should 'cp -r srcpath/.. dstpath' do?
Consider the following:
/tmp$ mkdir -p src/{a,b} dst/dstsub; touch src/{a,b}/hello
/tmp$ tree src/ dst/
src/
├── a
│ └── hello
└── b
└── hello
dst/
└── dstsub
Now run
/tmp$ cp -r src/a/.. dst/...