Questions tagged [cp]
cp - Command-line tool to copy a file
788
questions
0
votes
0
answers
26
views
Rsync - Sync two directories without changing mode and ownership of either
Let's say I start with following a/ and b/ directories,
ls -l a/ b/ ...
0
votes
0
answers
33
views
To copy using cp non-recursively if the '-a' option is already used
BSD cp:
-a Archive mode. Same as -RpP options. Preserves structure and
attributes of files but not directory structure.
-P No symbolic links are followed. This is the ...
0
votes
1
answer
87
views
To move files only; To copy folders only
Tested in Bash and Zsh:
copy nondot files | cp ~/dir1/* ~/dir2/
copy dot files | cp ~/dir1/.* ~/dir2/
copy both nondot and dot files | cp ~/dir1/{.,}* ~/dir2/
...
0
votes
0
answers
47
views
Weird cp behaviour when script is executed from systemd
I have a script that behaves weirdly when executed from systemd if I use cp instead of cat.
My script:
#!/bin/bash
steamcmd +login anonymous +app_info_update 1 +app_info_print 3017300 +quit | grep -Po ...
-1
votes
2
answers
61
views
Why is the -n option not working for my cp command?
When I typ
cp file1 file2
it works perfectly, but of course, it overwrites the second file.
When I tried using -n or --no-clobber, there was no error message, I simply cat the files or opened them in ...
0
votes
1
answer
85
views
What is the difference between "cp /tmp/a ./" and "cp /tmp/a ."
What is the difference between cp /tmp/a ./ and cp /tmp/a . (i.e. with and without the trailing slash in destination)?
They both mean copying /tmp/a to current directory, but I see some people insist ...
0
votes
0
answers
41
views
what the `cp --reflink=always` will do if I try to copy directory that contains reflink to a diffrent disk?
I have a folder root1 on disk partition sda1 which contain reflink/mnt/sda1/root1/a->/mnt/sda1/root1/raw/a
I have another folder root1 on disk partition sdb1, that has reflink /mnt/sdb1/root1/a->...
4
votes
1
answer
334
views
How to use cp's --update=none-fail option
I have cp (GNU coreutils) 9.5 on Arch Linux. The help seems to claim it has a --update=none-fail option, which will fail if a destination file already exists:
$ cp --help | grep '\--update\[=' -A1
--...
3
votes
1
answer
463
views
cp -P * vs. cp *(.) vs. cp *(-.)
According to man cp, using cp -P * foo/ means that no symbolic links will be followed:
-P: No symbolic links are followed. This is the default if the -R option is specified.
But how to copy files in ...
0
votes
1
answer
150
views
Understanding the '-a' option of the 'cp' command
From man cp, abridged:
-a: Archive mode. Same as -RpP options. Preserves structure and attributes of files but not directory structure.
-R: If source_file designates a directory, cp copies the ...
0
votes
3
answers
66
views
Keeping owners in a folder copy
I'm trying to copy a folder (SRC) containing some files and subfolders.
The content and SRC itself have setgid bit enabled (that is the s in place of the x in the group triplet). Furthermore, the ...
0
votes
1
answer
25
views
Inherit permissions not working with crontab copy
I have a copy script that runs in a crontab
and I need the folder and files that are copied
to inherit the permissions of the destination directory.
This is the destination folder:
drwxrwxr-x 10 usr1 ...
3
votes
1
answer
240
views
cp, trailing slash, and copying to the same vs. to another directory
To copy a directory to another directory, the first directory should be written without the trailing slash:
# example 1
# this command will copy dir1 to dir2
# (dir2 is preexisting)
cp -Rip dir1 dir2/
...
0
votes
1
answer
43
views
Difference between cp and cp -rf on a Mac
Could anybody explain is there any difference between cp some-file.txt some-folder and cp -rf some-file.txt some-folder on a Mac?
I was told that cp -rf forces cp to overwrite existing files, but it ...
0
votes
0
answers
275
views
error in copying a file: 'cp: cannot lseek'
I'm on a Debian derivative (RPi OS/bookworm). I am trying to copy a rather large image file (.img), approximately 9-10 GB from the Synology NAS (btrfs filesystem) to a local folder (ext4 filesystem). ...
1
vote
0
answers
86
views
Incorrect folder name created when using cp command in bash [closed]
I would like to copy a file from one location to another. When I use the cp command in a terminal it works well, for example I use the following command:
cp -r projects/Test/ projects/Personal/
This ...
0
votes
0
answers
30
views
Unable to force copy multiple files using single command non-interactively
I wish to force copy a set of files having either the same or different names to a single destination on the same host with a single command onn Solaris.
Note: the copy should be forced overrite and ...
0
votes
0
answers
160
views
cp command not copying file content?
I'm trying to copy a folder with files from a mounted volume to another mounted volume with a simple cp command.
The source folder Test only contains one 20MB .mp4 file.
cp -v -r -a /media/Online/...
0
votes
1
answer
139
views
Any command to exclude all types of files only? [duplicate]
Does rsync or cp have a command to exclude any type of file besides manually excluding extensions such as *.txt, *.pdf, *.jpg OR setting -maxdepth or using --exclude=dir/* (used with rsync which ...
1
vote
1
answer
241
views
How to exclude different levels of subdirectories with cp?
This is a follow-up question to my original post: find & cp command doesn't copy 1st level directory
I have a directory structure like this:
test folders
├── 1
│ ├── 1-1
│ ├── 1-2
│ └── ...
0
votes
1
answer
151
views
find & cp command doesn't copy 1st level directory
I have a directory structure like this:
test folders
├── 1
│ ├── 1-1
│ ├── 1-2
│ └── 1-3
├── 2
│ ├── 2-1
│ ├── 2-2
│ └── 2-3
├── 3
│ ├── 3-1
│ ├── 3-2
│ └── 3-3
└── 4
├── 4-1
...
3
votes
1
answer
124
views
Hard link as destination of cp and rsync
Where do I find documentation of behavior of cp and rsync commands when the destination path shares the inode with another path? In other words, when I do
$ cp [options] src dest
$ rsync [options] src ...
0
votes
1
answer
176
views
How do I escape opening and closing brackets [] to use with cp command?
I have a script that finds some directories and then copies their content to another directory.
now the problem is that some of the found directories need to have brackets in their naming and they ...
1
vote
1
answer
252
views
Why is this script treating the files with the same names as the same files?
#!/usr/bin/bash
install_wm() {
echo "$(dirname "$0")"
cd "$(dirname "$0")" && pwd
mkdir -p /root/.config && cd /root/.config &&...
0
votes
2
answers
49
views
Copy (Rsync) only files from subirectories
I'd be really happy about some help. Lets imagine a snapshot of a directory structure:
../test1/test6/test62.txt
../test1/test6/test65.txt
../test1/test6/test67.txt
../test1/test6/test69.txt
../test1/...
0
votes
1
answer
80
views
What's the difference between 'cp -rvf /bin/ ./rmlater/' and 'cp -rvf /bin ./rmlater/'?
Say I'd like to copy the whole /bin into my ./rmlater folder
cp -rvf /bin/ ./rmalter works as what I want
But I just found, without the trailing slash of source, cp -rvf /bin ./rmalter gives only an ...
6
votes
1
answer
2k
views
Why does `ls` in Linux and macOS show different owners (uid) for the same file?
I copied some files to HFS+, using macOS, ensuring that it was copied exactly. On macOS these copied files have 501 as owner according to ls -han.
I then plug in the HFS+ usb stick into Ubuntu, and ...
0
votes
1
answer
62
views
How to copy a directory structure and rename a subdirectory in the destination
Given this directory structure
$ lsd --tree ...
3
votes
2
answers
1k
views
Why does this use of `cp -a` not preserve creation time?
I copy some directories with -a in order to preserve=all which I understood would include creation times:
cp -a ./* /mnt/destination/
When inspecting the resulting directories in the destination they ...
0
votes
1
answer
106
views
how to copy symlinks without dereferening them from an external hard drive (NTFS)?
I am moving my files from one computer to another via an external hard drive formatted with NTFS. I have a folder called "library" with many PDFs. This folder contains quite a few symlinks ...
0
votes
1
answer
69
views
cp -r does not copy specific folder only its content
I have a folder structure that is something like this:
a/
|b/
| f1
| f2
|c/
| f3
| f4
|d/
| f5
| f6
Where b, c, and d can contain main files and sub directories. Then I have a ...
1
vote
0
answers
91
views
Copy recursively complete content of a directory [duplicate]
I am a bit embarassed that, as a long-time linux user, I don't have an answer to this:
+- root-dir
+- dest
If I run cp -r root-dir dest/, then the complete content of root-dir is copied to dest/, ...
0
votes
1
answer
100
views
cp AND rsync exclude all files of all types from all subdirectories, only keep directories [duplicate]
when using find . -type d it excludes all files whether in parent directory or in subfolders from the search. I want to extend this into a -exec cp -p or rsync "{}" destination \; so that ...
4
votes
2
answers
1k
views
cp some/path/**/*.h is not including .h files at all depths
I'm trying to copy all .h files in a directory and all subdirectories into another folder using the copy command:
cp --parents -r tensorflow/lite/**/*.h libtensorflowlite-2.13.0-linux/include
The ...
4
votes
4
answers
1k
views
How to take selective backup?
Say there is a folder called domains in glassfish. It has domain1, domain2...domainN.
I want to take everything from domain1 except the logs directory and save them to /home/user/backup directory.
I ...
3
votes
4
answers
1k
views
I want to copy files that do not have a number in their name
I want to use cp command using file globing to copy all those files that do not have a numeric value.
The copied files should not include 12a, ghf3 and s2d.
I tried using cp [!0-9] *[!0-9] *[!0-9] ...
0
votes
1
answer
71
views
How to find a file and copy its directory without copying the other files in that same directory?
I have a lot of different folders with pdf files and other extensions. I want to copy all the pdf files to another destination. But if I do that with find like this:
"${SEARCHDIR}" -iname &...
0
votes
2
answers
96
views
Unable to maintain createTime with rsync (but cp -p works)
I'm running into a strange issue with timestamps when trying to copy/backup files from my Mac to a shared drive on TrueNas.
My drive is defined in TrueNAS as a Home Share and mounted in MacOS via the ...
0
votes
1
answer
155
views
How to copy files from a list without extension to a different folder?
I have a text file that contains a list of ids of files without any extension now I need to copy those files mentioned in the list
head 01cBC.txt
EE87786
EE87787
EE87788
EE87789
EE87790
EE87791
Now, ...
0
votes
0
answers
6k
views
aws s3 copy failing with fatal error: An error occurred (403) when calling the HeadObject operation: Forbidden
Copying a file from S3 bucket to EC2 Instance.EC2 Instance is in the same region us-east-2 as S3 Bucket in.S3 Bucket is ACL disabled and Allowed for public access.
# /usr/local/bin/aws s3 cp s3://...
5
votes
4
answers
723
views
Copy the n-largest files from a certain directory to the current one
I am trying to copy five largest files from a certain directory to my pwd. Using cp specific/directory$(ls -S specific/directory | head -n) ./ copies the first file and then proceeds to produce cannot ...
0
votes
1
answer
1k
views
cp command asking for confirmation of overwrite even with -f switch (zsh)
I have the following in a file which is sourced from ~/.zshrc:
# Starship prompt
cp -f ~/.config/starship.toml ~/.config/starship-zsh.toml
export STARSHIP_CONFIG="$HOME/.config/starship-zsh.toml&...
0
votes
1
answer
81
views
What is the default behavior of GNU cp when copying from a symbolic link?
Can someone elaborate on this description in the official docs?
When copying from a symbolic link, cp normally follows the link only when not copying recursively or when --link (-l) is used.
0
votes
0
answers
403
views
How to cp all files within /var/log without using sudo
This is in shell script. I want to create a directory copy of /var/log while preserving directory structure (so not tar).
I do this by making a directory and using cp -R /var/log cpdir However, some ...
3
votes
2
answers
162
views
How can I copy directories recursively with hardlinks with variables in bash?
The operation I'm trying to do is take directory 1:
Dir1
Dir A
File A
Dir B
File B
Then use the find command to check every file in Dir 1 for whether or not they have an ...
1
vote
1
answer
58
views
Why is my entire home backed up?
I wish to back up some of the files located in my home dir.
That is
simple files at the root of my home
and some directories in my home, listed in ~/worthsaving.txt
Sample worthsaving.txt:
cloud
...
5
votes
1
answer
4k
views
Use the 'cp' command in a Bash script and exclude a specific directory
I need to run this command in a shell script to copy source > destination and exclude a folder.
No rsync, tar, find, mv, etc.
Exactly this command:
cp -var test/!(test2) testbkp
In the shell it ...
1
vote
0
answers
50
views
cp .iso /dev/sdd usb memory device full
I was informed, from here, the best (easiest) way in linux to put a bootable iso file to a usb stick and have it be bootable to do an install is simply via cp rhel-8.5-x86_64-dvd.iso /dev/sdd where ...
2
votes
1
answer
243
views
Why doesn't this script succeed from crontab as it does when manually run?
This script works when executed with doas ./backup_cron_root.sh
#!/usr/bin/bash
/usr/bin/crontab -l> "/tmp/cron.$(whoami).$(hostname)" && /bin/date>>"/tmp/cron.$(...
0
votes
1
answer
161
views
I'm wondering why using cp in this way takes over 4 seconds [duplicate]
time cp /usr/local/bin/* /media/username/flash-drive-label
real 0m4.142s
user 0m0.007s
sys 0m0.007s
Normally using cp with wildcard (even when there are hundreds of files) like that never ...