Questions tagged [cp]

Questions relating to the Linux 'cp' command.

Filter by
Sorted by
Tagged with
1312 votes
8 answers
3.9m views

How can I copy the contents of a folder to another folder in a different directory using terminal?

I am trying to copy the contents of a folder to another folder in a different directory using terminal. Would somebody be able to provide me an example of the command line syntax required to achieve ...
pandisvezia's user avatar
  • 13.3k
15 votes
5 answers
86k views

Recursively copy files from one directory to another

I have all my music in a folder /media/kalenpw/MyBook/Music/ABunchOfOtherFoldersWithFilesInside. I want to copy all of the mp3s to /media/kalenpw/HDD/Music so I used: cp -R /media/kalenpw/MyBook/...
kalenpw's user avatar
  • 744
99 votes
10 answers
164k views

How to copy a file to multiple folders using the command line?

I have tried to copy a file test.txt to multiple directories with one command: cp ~/test.txt ~/folder1 ~/folder2 But I didn't succeed. Is there a way to do that in one command so I can copy a file ...
nux's user avatar
  • 37.9k
76 votes
5 answers
216k views

cp command to exclude certain files from being copied

Is there a way to use the cp command to copy a directory and exclude certain files/sub-directories within it?
Stephen Jacob's user avatar
3 votes
1 answer
5k views

How can I recursively copy files by file extension? [duplicate]

I would like to copy all files with a certain extension that are in sub directories to a different folder. I don't want to maintain the directory structure, I just want to copy all files found to a ...
lunchboy's user avatar
112 votes
3 answers
170k views

Copy a file and keep the same timestamp of the original file

I need to a copy file and after that I need to change the timestamp attributes as the original file. How can I do it with the terminal or any other way?
user avatar
23 votes
2 answers
60k views

Is there any way to create backup copy of a file, without type its name twice? [duplicate]

Often when I'm editing some system file first I create a backup copy. For example: sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak Is there any simple 'shortcut' such as: sudo cp /etc/ssh/...
pa4080's user avatar
  • 29.8k
41 votes
5 answers
576k views

cp - cannot create regular file : permission denied

I want copy to /lib/udev but gives error cp -f /tmp/ok_pcscd_hotplug.sh /lib/udev cp:cannot create regular file /lib/udev/ok_pcscd_hotplug : Permission denied I am root , but I can't understand . ...
user278122's user avatar
24 votes
2 answers
55k views

force cp to copy on dangling symlinks

Is there any way to force cp (Bash 4.2.5, Ubuntu 12.04) to copy onto a dangling symlink? cp a-file path/to/danling/symlink/a-file cp: not writing through dangling symlink `path/to/danling/symlink/a-...
Marcus Junius Brutus's user avatar
21 votes
2 answers
42k views

What's the difference between ` cp ` and ` rsync `? [closed]

They seem similar to me. I want to know how to use them. What's the difference in structure?
Thái Siu Nhưn's user avatar
2 votes
2 answers
381 views

Move all JPGs and rename them into one directory

.Hi. I have a bunch of jpgs in 100s of subfolders , I know I can move them all with this command find -type f -iname "*.jpg" -exec mv -av {} /home/root/private/pics/ \; But my all my jpgs ...
1014Noob's user avatar
2 votes
3 answers
2k views

Copy over a large number of files with new names

I have a large number of files (tens of thousands) I need to copy over from /dir1 to /dir2 but the name of the file must change as such: OLD NAME ---> NEW NAME filename.txt ---> bob_filename_1253....
Javier's user avatar
  • 21
1 vote
3 answers
4k views

Why does cp not copy a specified folder

let's say that I have a following file structure: ~/DIR1 -fileA -DIR2 --fileB Then, being in ~, I run this script: cp DIR1 NEWDIR2 And just an error happens: cp: omitting directory ‘DIR1’ I ...
Petrroll's user avatar
  • 113
18 votes
2 answers
108k views

Ubuntu copying file problem (cannot stat file)

I've faced a problem when copying a file with the commands, cp ~/Downloads/sample.pdf ~/Desktop/ But the terminal gives me a message, cp: cannot stat 'sample.pdf': No such file or directory.
Herks's user avatar
  • 833
10 votes
4 answers
8k views

How to copy into with cp if destination folder already exists?

Example... This is what I want. /tmp $ cp -f -R --verbose /tmp/a /tmp/b `/tmp/a' -> `/tmp/b' `/tmp/a/file2' -> `/tmp/b/file2' `/tmp/a/file1' -> `/tmp/b/file1' This is what I do not want. /...
James Mitch's user avatar
8 votes
2 answers
4k views

cp recursive with specific file extension

I am trying to copy all .odt files including those in subdirectories. cp -r ~/Documents/* ~/copies # works as expected cp -r ~/Documents/*.odt ~/copies # does not work as expected The first line ...
Insideup's user avatar
  • 115
4 votes
2 answers
6k views

What happens when you force quit a `mv` directory operation between two disks?

Another way to word the question is... What happens when you mv a directory between two disks? Does it move one file after the other, or does it copy all files to destination, then then delete ...
Nathan J.B.'s user avatar
  • 2,620
4 votes
1 answer
26k views

getting razercfg to work using systemd - systemctl: command not found

My goal is to change my mouse DPI. So any less frustrating solution is also welcome. I'm trying to get this program to work and i'm following it's README file: http://bues.ch/cms/hacking/razercfg....
user3776022's user avatar
1 vote
3 answers
44k views

Copy file to External Hard Disk

My UBUNTU (desktop part) does not boot completely because of low disk space; I logged in to terminal using my username and password, try to copy some file from /home/UserName/Desktop to my external ...
Hesam Esfahlani's user avatar
0 votes
1 answer
102 views

How do I copy a local home dir to an iscsi mounted home directory

I have various Ubuntu images on this machine, each with their own home dir. I am trying to consolidate them on a redundant iscsi NAS. This seems like it should be straight forward. It eventually locks ...
Walt Corey's user avatar
0 votes
2 answers
1k views

Copy files based on date with structure of directories

I have commend: find /source/ -type f -newermt '18 dec 2020' -exec cp -t /target/ {} + This commend copy only files, without structure of dirs, but i need files with his parent dir. Second thing is ...
mechmati's user avatar