Questions tagged [cp]

Questions relating to the Linux 'cp' command.

Filter by
Sorted by
Tagged with
14 votes
5 answers
59k views

Undo copy (cp) command action

I copied some file from source folder into destination folder by using bellow command line in terminal. sudo cp From_SOURCE/* To_DESTINATION/ Now I want to undo this command.
0 votes
0 answers
45 views

Why do cp, and nocache cp, clog up and slow down/freeze after 2-4 TB, but rsync is effective indefinitely?

Is there a setting I'm missing in CP and nocache CP that frees up resources after each file? I looked around, and read that cp and nocache cp are MUCH faster, and use more RAM instead of CPU, but not ...
0 votes
0 answers
64 views

preserve=timestamps is not permitted

I use --preserve=timestamps when I copy a file. This worked under Ubuntu 20.04, but running 22.04 I get: cp: preserving times for '/d/news/2024-01-04.COA DEMS - Mazars Report.pdf': Operation not ...
0 votes
0 answers
25 views

cp to a previous directory using the shortcut - [duplicate]

I am a beginner with Ubuntu and I tried searching for an answer for this but I can't find one that covers this and I am confused by the output I am getting. I know you can use cp to copy to a parent ...
112 votes
3 answers
172k 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?
76 votes
5 answers
217k 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?
0 votes
0 answers
235 views

Copy files from a list with spaces in the names to a new destination in Ubuntu

so i have an mp3 playlist (playlist.txt): /home/ME/music/These guys/The first dumb track.mp3 /home/ME/music/Band two/my fav track04.mp3 /home/ME/music/Some other weirdos/The third One.mp3 obviously ...
-1 votes
1 answer
489 views

How to copy ONLY parent folder with find and CP?

Why does the following command copy the DCIM folder and it's subfolders and files..I just want the DCIM folder to be copied. find ./"DCIM" -name "DCIM" -maxdepth 0 -type d -exec cp ...
0 votes
1 answer
81 views

Having trouble moving symlinks from backup to boot partition

The context I have a dual-boot Ubuntu (Jammy Jellfish)/Windows laptop (Dell XPS 9550). My /boot partition was too small to support an update, so I used GParted to attempt to resize it. However, I ...
0 votes
1 answer
161 views

How to fix this error in cp?

#!/bin/bash SrcDir=$1 DstDir=$2 #If DstDir is not exist, this creats it if ! [ -a $DstDir ]; then mkdir $DstDir fi #Formats Vformat=(mp4 avi 3gp mpeg mkv wmv mov) Iformat=(jpg jpeg png) Year(){...
1 vote
1 answer
2k views

How to best copy large folders?

I want to copy 1 TB of data from 1 HDD to another via Terminal. What is the best approach to this? So far, i've used the following, but I've no idea, whether it actually makes progress, or if it just ...
41 votes
5 answers
578k 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 . ...
15 votes
8 answers
10k views

Copy group of files (Filename*) to backup (Filename*.bak)

Background In Linux you can: List a group of files with ls Filename* Remove a group of files with rm Filename* Move a group of files with mv Filename* /New/Directory But you cannot copy a group of ...
100 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 ...
6 votes
5 answers
8k views

trying to CP a directory to /dev/null

What I'm really tring to do, it verify the the data on an external drive is still readable. I thought the simplest and surest way to do this would be to copy everything to /dev/null. It works great ...
3 votes
3 answers
5k views

Copy files and set owner/group to the owner/group of the destination directory

I have a script used in different environments. This scripts uses sudo cp to copy files (sudo otherwise it has no access). But sudo cp creates the files with the wrong owner. It cannot keep the owner ...
0 votes
2 answers
605 views

How can we copy a file to all subdirectories using cp and wildcard

Let's say I have 10 subdirectories in a main-directory named d1, d2, d3, ..., d10. How can I copy a file into all these subdirectories using cp? I'm looking for something like cp ./my_file.txt ./d*/
1 vote
1 answer
433 views

Having trouble copying conda environment folder containing same word (different case) files with symbolic links in terminfo subdirectory

I am using WSL1. I am trying to save a copy of my ~./miniconda/envs folder to the desktop using cp. I keep getting errors like cp: cannot create regular file './envs/py_env/share/terminfo/h/hp2621a':...
1 vote
1 answer
4k views

Anyway to undo overwriting file by mv or recover replaced file?

I accidentally mv a new file to an existing file and overwrote it. Is there anyway to undo mv or recover the replaced file?
-4 votes
1 answer
146 views

Copy some files from source directory A to directory B and some files to Directory C with non sequential order

I am looking for a script to copy files from a source directory to two destination directories with non sequential order. For instance I want to copy some files from source directory A/ to destination ...
0 votes
2 answers
39 views

Copying a downloaded file into my current terminal folder

I am compiling WRF on my HP Desktop. I'm in Ubuntu terminal and trying to use the cp command to copy from my D Drive, but it just won't work. Using cp D:\MyWRF/file.tar . All I get is cannot stat, ...
1 vote
1 answer
2k views

Resume cp that was interrupted

I was doing a huge cp command, copying 1TB and I had disconnected computer from network after 700GB. Files are still there but I can't anyhow to resume copying. I tried sudo rsync rsync --ignore-...
0 votes
1 answer
105 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 ...
0 votes
1 answer
1k views

Copying file with the same name from different directories to the directory before

I have a set of 120 files, all with the same name,contig.fa which are located in the hierarchy of Main Directory 1 Subdirectory 1 file.fa Main Directory 2 Subdirectory 2 file.fa I ...
7 votes
1 answer
2k views

Why does "cp" complain about identical files when chaining with "find"?

I have a find command as below that lists the matching files: $ find . -type f -name "*.txt" ./level2/file2.txt ./level2/level3/file3.txt ./level2/level3/level4/file4.txt ./level2/level3/...
0 votes
0 answers
559 views

cannot paste external files into a ntfs file system in Ubuntu 20.04.4

on Ubuntu 20.04.4 LTS I have an NTFS data partition. This is a dual boot system with Windows 10. The option "paste" is grayed out when I try to copy-paste into the NTFS partition any file ...
0 votes
1 answer
24 views

Link directory to another directory to ccopy files

I have a folder: /share/public I am working in the folder: /home/john/workingfolder It means that currently I am in the "workingfolder". I would like to send files to /share/public but ...
4 votes
2 answers
4k views

Make multiple copies of one file with different names

How can I create multiple file from one? Like, I have 1.json, but want to create 2.json + 3.json + 4.json out of it. Most obvious way is to just cp 1.json 2.json and so on; but does Linux provide some ...
1314 votes
8 answers
4.0m 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 ...
12 votes
3 answers
113k views

cp fails to copy with errors "cp: error reading 'file': Input/output error" and "cp: failed to extend 'file': Input/output error

I'm a user of Oracle Virtualbox on Ubuntu. And I used to copy vdi files as a kind of backup. Previously I did this (copying vdi file and then copying it back) many times without any problem. But ...
4 votes
2 answers
1k views

Copying directories in linux only if it contains the specified file

I need to make a copy of all the folders under /parent (into a new location) but only if it has 123.dat - in which case I need to copy the folder too, but none of the other files it contains. So that ...
6 votes
3 answers
21k views

Why does cp not copy files?

$ ls -la /tee/mysql total 28675 drwxrwxrwx 1 root root 448 Jun 25 13:52 . drwxrwxrwx 1 root root 2896 Jun 25 12:12 .. -rwxrwxrwx 1 root root 18874368 Jun 25 13:19 ibdata1 -rwxrwxrwx 1 root ...
0 votes
0 answers
626 views

unable to copy files from ssd to hdd in ubuntu 20.04

I'm trying to copy media files like .mp3,.mp4, .mkv etc. from my ssd to hdd as to save time complexity of ssd but unable to do so. Everytime I try to copy or move files it shows me this error "...
0 votes
1 answer
3k views

Why doesn't 'sudo cp' copy files in the /sys directory?

I want to make an exact copy of the /sys directory, and tried the following command: sudo cp -ra /sys ~/Documents/dir1 It does not work as I expected... I get a lot of error messages such as: cp: ...
1 vote
1 answer
200 views

How to automatically open a file that has a dynamic filename

I'm trying to make an automation process, my workflow generates a file automatically, this file is named based on a timestamp and a public key. Example of the file name : UTC--2022-03-07T10-53-08....
0 votes
1 answer
301 views

Is there an easy convertor between dpkg --print-architecture and uname -m for generic scp?

I want to copy files that relevant to my machines (x86_64 / aarch64) from remote machines. I want to use: scp user@host:*$(uname)* . to copy both wheels and .deb files, e.g.: name-x.y.z-cp36-cp36m-...
0 votes
2 answers
3k views

Copy all from a folder into the project root directory

I have a web project with the following structure: application/ dumps/ nginx/ logs/ .git/ docker-compose.yml Dockerfile README.md .gitignore For several reasons, I would like to dissolve the ...
8 votes
1 answer
76k views

What does "omitting directory" mean and how do I make it cp the directory rather than omit it

I am doing a data recovery for someone and enter the following command -Ubuntu:~# cp /media/Macintosh\ HD/Users/orlando/Desktop\ (original)/VIDEOS\ ESPANOL/ /media/\$G\$\ DATA/Orlando/Desktop/ And ...
63 votes
5 answers
196k views

Can I verbose output during a copy command processing?

Situation: If I entered a copy command like cp -rf /src/ /dsc/ then I am waiting several minutes for copy large directories. I forgot to put -v flag to verbose an output, Can I do it during copying?
0 votes
1 answer
86 views

How to move a matched id of mat files in different folder

I have Matlab (.mat) files in a particular folder. In a text document, I have some IDs list marked as 0 and 1. First I need to match the IDs and separate the mat files that are marked as '1'. For your ...
5 votes
4 answers
35k views

How can I copy the contents of a child folder to its parent folder using command line?

I have this directory structure: parent_folder/child_folder/ I want to copy the contents of the child folder to the parent folder, but I don't know how to do it with cp.
0 votes
1 answer
398 views

Accidentally used "cp /file /dev/sdb1"

I'm about to cry, in need of your help... I'm new to linux. I was trying to copy a Windows10 iso to my external HDD. I wanted to use cp command. I saw that my external HDD was sdb1. So I just used cp /...
0 votes
1 answer
1k views

How to copy multiple files to a new folder in a new path in one command?

[These are the files I want to copy over][1] Example command I have tried but does not work: cp permanent_waiver_* /existingpath/newfolder1/newfolder2 This would give me error like no such file or ...
15 votes
5 answers
87k 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/...
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 ...
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.
10 votes
2 answers
19k views

How do I copy a directory into itself?

I can copy a directory like so: ~$ cp -r ./Desktop/ /tmp/ Similarly, if I just wanted to copy the files from within a directory, I could do so: ~$ cp -r ./Desktop/. /tmp/ Things become a little ...
0 votes
2 answers
148 views

How to copy files into a new file

How to copy files from one file to another file that has contents I want to keep? In other words, I want the contents of file1 to go in file2 but the info in file1 to be added to the existing stuff in ...
0 votes
1 answer
1k views

I would like to maintain a mirror copy of many files and directories using cp, but I cannot get it to function (similar to MS XCOPY with switches)

I am trying to copy SOURCE to DESTINATION, so that DESTINATION is identical to SOURCE. Note that SOURCE is 89GB with 26k files and hundreds of folders, so it is not practical to do an entire copy when ...
1 vote
1 answer
274 views

Rename file names with a parent directory name

I want to rename my files recursively, ending with *.fna.gz with the parent directory two-step-up i.e. "Aspergillus_neoniger". You can see the subdirectories details in this image tree ...

1
2 3 4 5