Questions tagged [cp]

cp - Command-line tool to copy a file

Filter by
Sorted by
Tagged with
0 votes
1 answer
103 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 ...
anmac1789's user avatar
1 vote
1 answer
83 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 │   └── ...
anmac1789's user avatar
0 votes
1 answer
60 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 ...
anmac1789's user avatar
3 votes
1 answer
90 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 ...
norio's user avatar
  • 205
0 votes
1 answer
44 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 ...
Sharif Rezvani's user avatar
1 vote
1 answer
242 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 &&...
John Smith's user avatar
0 votes
2 answers
44 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/...
Dr. Spongebob's user avatar
0 votes
1 answer
45 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 ...
Qiu Yangfan's user avatar
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 ...
Andreas's user avatar
  • 511
0 votes
0 answers
32 views

Folder to a mounted media device issue: target is not a directory

I’m installing GitLab using this command sudo cp /var/cache/apt/archives/*.deb /path/to/mount and it is throwing this error: cp: target '/path/to/mount' is not a directory What is the problem?
chandru lovely's user avatar
0 votes
1 answer
52 views

How to copy a directory structure and rename a subdirectory in the destination

Given this directory structure $ lsd --tree ...
mrt181's user avatar
  • 111
3 votes
2 answers
665 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 ...
Andreas's user avatar
  • 511
0 votes
1 answer
59 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 ...
Wolfhart's user avatar
0 votes
1 answer
42 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 ...
Lars Nielsen's user avatar
1 vote
0 answers
50 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/, ...
phetherer's user avatar
0 votes
1 answer
65 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 ...
anmac1789's user avatar
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 ...
Brad's user avatar
  • 155
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 ...
achhainsan's user avatar
3 votes
4 answers
749 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] ...
Raghav Arora's user avatar
0 votes
1 answer
55 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 &...
pwrsheller's user avatar
0 votes
2 answers
48 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 ...
Eric B.'s user avatar
  • 645
0 votes
1 answer
85 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, ...
Debajyoti Kabiraj's user avatar
0 votes
0 answers
4k 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://...
dbadmin's user avatar
  • 23
5 votes
4 answers
659 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 ...
Sudoh's user avatar
  • 257
0 votes
1 answer
290 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&...
paradroid's user avatar
  • 1,183
0 votes
1 answer
53 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.
joe's user avatar
  • 13
0 votes
0 answers
116 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 ...
John Smith's user avatar
2 votes
2 answers
111 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 ...
GeneralTully's user avatar
1 vote
1 answer
54 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 ...
Poor Standard's user avatar
0 votes
0 answers
81 views

Delete parent folder while keeping contents

I have a structure that is as follow: parentdir/nesteddir/content/files within parentdir are hundreds of subdirectories with differnet names (I am just using an example of 'nesteddir' I will cd into ...
linuxuser24569's user avatar
5 votes
1 answer
2k 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 ...
Z0OM's user avatar
  • 2,979
1 vote
0 answers
36 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 ...
ron's user avatar
  • 6,122
2 votes
1 answer
207 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.$(...
John Smith's user avatar
0 votes
0 answers
47 views

migrate from rsync to cp

We are currently using "rsync" to copy a directory recursively. We are moving to a newer platform where "rsync" is not available and have been advised to use "cp" instead....
AnR's user avatar
  • 1
0 votes
1 answer
77 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 ...
thinksinbinary's user avatar
0 votes
1 answer
86 views

Copy files with different extensions to different basename with same extensions

I have 3 files Original.js Original.vue Original.css How can I easily copy them to Copy.js Copy.vue Copy.css Until now, i always just copied one by one, but if I could use something like copy ...
Jérôme Tremblay's user avatar
1 vote
1 answer
196 views

Copying/moving and renaming files from multiple subdirectories to parent directory

I have multiple directories, and each one of those directories contains an "example" directory which in turn contains images. What I want to do, is to add a textual suffix at the end of a ...
user5672's user avatar
-1 votes
1 answer
139 views

Find and mass copy

I have a script on macOS that will find files ending in .csv extension; then I am copying these files with a forced backup. However, the bash compiler complains find -E . -regex './.*csv' -type f -...
Emil11's user avatar
  • 11
5 votes
3 answers
506 views

Copy files using an input file to read file directions

I'm using grep to search through 1 TB of files. I want to grep filenames and put the names in a text file AND I want to cp all files with a match to the dir /home/user/matches. I want to both tasks ...
pwrsheller's user avatar
0 votes
0 answers
71 views

mv and cp with automatic diff

Is there a program out there like mv and cp, which upon conflict automatically shows a diff before asking whether to override the target file? This is such a basic feature in graphical file managers, ...
xeruf's user avatar
  • 531
1 vote
2 answers
831 views

One-way synchronize with cp and busybox

I need to one-way synchronize local folders using only cp and/or other tools available in the BusyBox 1.35 which has no rsync. I was hoping for something like: cp -auv /source/ /target, but it won't ...
rych's user avatar
  • 131
5 votes
2 answers
501 views

How to find out if the filesystem supports reflink copies?

I try to create a snapshot copy of a directory recursively, but it returns errors for every single file if the filesystem (custom shfs) does not support reflink copies: # cp -a --reflink=always /mnt/...
mgutt's user avatar
  • 407
1 vote
0 answers
1k views

Copying a file with cp is stuck (copying with Dolphin doesn't finish either)

I had a problem with copying files from my hard drive to an USB stick with the Dolphin file-manager in Debian11/KDE. Some were stuck near the middle and some were stuck after the full file-size was ...
mYnDstrEAm's user avatar
  • 4,167
1 vote
0 answers
86 views

why top command in linux shows high us and low wa while cp many large files simultaneously?

I am copying 10 large files(which may costs 1 hour) simultaneously, and I used top command to check the cpu usage, but I found out 100.0 us and 0.0 wa. shouldn't it be IO-bound instead of CPU-bound? I ...
cluuuuu's user avatar
  • 11
0 votes
1 answer
1k views

Copying a file from one directory to the next and changing the name

If I wanted to copy a file called myscript from, let's say "/home/myusername" to a directory called "/home/myusername/test" while also renaming it to myscript2... how would I do ...
Rene Rojo's user avatar
1 vote
2 answers
63 views

Why does copying file directly is not editable?

mkdir ~/.config/dunst sudo cp /etc/dunst/dunstrc ~/.config/dunst/dunstrc This makes the file not editable rm ~/.config/dunst/dunstrc touch ~/.config/dunst/dunstrc sudo cp /etc/dunst/dunstrc ~/....
nk2's user avatar
  • 51
0 votes
1 answer
26 views

Why when i copy file from a symlink directory one level up copy is created one level up from original directory?

user@DESKTOP-KK4CCE2:~$ mkdir -p ~/foo/bar/ user@DESKTOP-KK4CCE2:~$ touch ~/foo/bar/test.txt user@DESKTOP-KK4CCE2:~$ mkdir ~/baz/ user@DESKTOP-KK4CCE2:~$ ln -s ~/foo/bar/ ~/baz/bar user@DESKTOP-...
kotenok2000's user avatar
1 vote
2 answers
2k views

What is cp Command to copy all files + directory structure AND cp Command to skip copying files when they already exist

I need to copy all of the files in a directory while preserving the directory structure to a backup hard drive. Will this work: find . -name '*.*' -exec cp --parents \{\} /target \; Then I want to ...
Charlie's user avatar
  • 11
0 votes
0 answers
94 views

estimating cp -r time

For a /data type folder that has gigabytes and thousands of files and sub folders, I will often do tar -cf data.tar data {it was a 102gb tar file} rsync -P data.tar /some_new_location cd ...
ron's user avatar
  • 6,122
5 votes
1 answer
897 views

cp overrides my default permissions settings, when copying files with: cp -r --no-preserve=all

My default umask is 077. When I create a directory, it has permissions 700: mkdir AA $ stat -c'%A %n' AA/ drwx------ AA/ now I want to set default permissions recursively to 750: ...
Martin Vegter's user avatar

1
2 3 4 5
16