Questions tagged [cp]

cp - Command-line tool to copy a file

Filter by
Sorted by
Tagged with
0
votes
1answer
129 views

Unable to delete directories copied from elsewhere centos 6 [closed]

One of our users mistakenly copied some system directories (e.g., /lib) to her home directory, using command cp -r /lib ., and then she cannot delete these directories. Command rm -rf ./lib returns a ...
1
vote
2answers
173 views

how can I copy files which are stored in one variable

I have the following code. PF=opt/N*.properties Inside PF I have 2 values /OPT/NA.properties and /OPT/NA2.properties. How can I copy these 2 files to other location in shell script cp $PF /opt/...
1
vote
1answer
4k views

Find last file in directory where the filename's end matches a string

I am writing a script to create/copy files to speed up workflow. In this instance a directory needs to be searched for files ending in a specific string, and if one or more is found the last one in ...
3
votes
5answers
6k views

cp command does not overwrite existing files

I'm copying files from a git repository into a virtualhost folder, although none of the following commands do overwrite existing files: sudo cp -R /home/git/repo /var/www/website sudo cp -R -f /home/...
1
vote
3answers
113 views

Filter columns basing on the value of other column

I have a text file with two columns and more than 3,00,000 rows. Format is as below Filename1.txt Num1 Filename2.txt Num2 Filename3.txt Num3 I want to copy all the filenames for which the ...
6
votes
2answers
4k views

Why does cp --no-preserve=mode preserves the mode? Alternative tools available?

$ cp --no-preserve=mode --parents /sys/power/state /tmp/test/ $ cp --no-preserve=mode --parents /sys/bus/cpu/drivers_autoprobe /tmp/test/ The second of the two lines will fail with cp: cannot make ...
3
votes
2answers
95 views

How to imitate the output of a webcam by updating a jpg file?

I have a folder A in which every now and then new files appear. It may happen that there are no new files for an hour, but also that there are several new files each second. All files have a unique ...
2
votes
2answers
2k views

How To dd or cp Entire Disk On Debian Remote Machine To Local Machine?

I have read this post - How to dd a remote disk using SSH on local machine and save to a local disk However, the following code doesn't work: "dd if=/dev/sda | gzip -1 -" | dd of=image.gz As I do ...
4
votes
1answer
32 views

Set minus of two newline-terminated lists / generic blacklisting using common household items

Recently, I was backing up a directory tree using cp -r, when I ran out of space in the receiving drive. I had to carry on with the backup, but to a different destination. Normally, to resume a cp ...
-1
votes
1answer
106 views

Easy Way To Back Up Entire VPS Including WHM CPanel Settings

I understand how to automate backups of websites via WHM/Cpanel. However, let's say I want to completely copy an entire VPS, so that I can cancel it, then easily deploy it again after a month or so. (...
5
votes
6answers
9k views

Check command success in bash

I'm currently writing a small script to backup bulks of floppy disks and format them afterward for later use. I use dd to copy the disk's image and cp to copy all the files on the disk. Here are the ...
0
votes
2answers
1k views

How do I copy all the files containing “t_1” in the name to a different directory using one command?

How do I copy all the files with "t_1" in the name to a different directory using one command?
0
votes
3answers
117 views

How to extract certain files from a directory in shell?

I made a simple shell script that takes a command line directory and extracts all of its contents to the current directory the script is running in. #!/bin/bash cp -v -R $1/* . I want to extend on ...
0
votes
1answer
55 views

bash alias for creating .bup file copies of multiple files

I have my own custom .bashrc file. I practice my coding a lot so I use raw text and JDK. I use "shopt -s extglob". I need to create .bup copy of each file (non-recursively) and kill them after work ...
0
votes
3answers
2k views

Copying multiple types of files in one command

I want to copy several files from one directory to another, with different extensions So I would write something like: cp -r dir1/*.gif dir2 But I also want to copy all .jpg files in the same ...
1
vote
1answer
865 views

Sync two Directories without rsync

I know what you are thinking right now "Just use rsync" but unfortunately this system does not have rsync, and I would like to come up with another solution. The Setup: The source Server has a ...
1
vote
0answers
288 views

Centos 7 Random Panic / Oops

Finally after much configuration changes I got a complete a crash dump I could inspect: KERNEL: /usr/lib/debug/lib/modules/3.10.0-327.28.3.el7.x86_64/vmlinux DUMPFILE: vmcore [PARTIAL DUMP] ...
3
votes
3answers
4k views

Copying faster than cp?

I am currently copying a large number of directories and files recursively on the same disk using cp -r. Is there a way to do this more quickly? Would compressing the files first be better, or maybe ...
6
votes
1answer
884 views

In RHEL/CentOS 7, does mv actually do a cp & rm on the same filesystem?

In light of the answers to two previous questions, it seems that under RHEL/CentOS 7 mv even on the same filesystem is actually doing a cp then rm. In previous editions of CentOS/RHEL, a mv on the ...
0
votes
2answers
6k views

cp large file to /dev/null to reduce size to zero [closed]

I just came across the advice that if you want to get rid of a large file and a process has the file handle open you should copy it to /dev/null and its size will be reduce to zero. How does this ...
1
vote
1answer
247 views

advantages of hard-link of file over copy of the file

I have a Bourne shell script which accepts single argument(text-file usually few KB in size). Essentially this script is a wrapper for scp which copies this text-file to remote server. Script does not ...
3
votes
2answers
694 views

cp overwriting without overwriting hardlinks to destination

Say I have the following setup : $ cat fileA textA $ cat fileB textB $ ln fileA myLink $ cat myLink # as expected textA I do not understand the following behaviour : $ cp fileB fileA $ cat myLink #...
3
votes
3answers
2k views

How to copy using for loop? [duplicate]

I am using this for d in ./*/ ; do (cd "$d" && cp -R ../lib . ); done in a shell script to copy lib folder in all subfolder inside my parent directory . But the lib folder also getting ...
23
votes
6answers
3k views

How to cp remaining files after failed attempt

I'm trying to copy a large directory from one drive to another. I mistakenly logged out before it was finished so only about 80% of the files copied over. Is there away to copy the remaining files ...
0
votes
2answers
219 views

Copy a shell script into multiple destination directories and run it

I have multiple directories and sub-directories like C201201A/RA/, C201202A/RB etc. So I want to copy setphase.sh into all sub-directories and also run it. I have tried the below code #!/bin/bash ls -...
1
vote
2answers
987 views

Cp default timeout limit [closed]

I have a script that creates and copies a file to multiple machine on a network. Sometimes a machine or two may be down, which in turn causes the cp to take a really long time to timeout. My ...
0
votes
2answers
4k views

Copying files from one sub directory to another

I think I must be missing something obvious. I am in a directory called AmHist, with 2 subdirectories, Assign and Resources. I want to move 2 files from Assign to Resources. I try cp LinuxHist ...
8
votes
4answers
22k views

Grep word within a file then copy the file

I have a collection of files ( *.zip, *.txt, *.tar.gz, *.doc, ...etc ). These files reside within a path. I want to find all the files ( *.txt), then copy, only, the text files that contain specific ...
0
votes
1answer
41 views

Copy folders has specific part of name and it is content

I have a long list of folder as follow: 001_bat_3513 002_mon_3213 003_bat_3515 004_btt_3540 005_bat_4513 055_bpt_8523 056_bot_3513 058_bat_1513 . . From this list: How can I copy the folders ( and ...
6
votes
1answer
2k views

Override an existing folder with cp

Is it possible to override an existing folder with cp? Example: tux@linux:~ $ cd /tmp/test/ tux@linux:/tmp/test $ mkdir A tux@linux:/tmp/test $ cd A tux@linux:/tmp/test/A $ touch 1 2 3 4 tux@linux:/...
1
vote
1answer
8k views

copy a file to a destination with different names

I want to copy a text file to a directory with multiple names with curly braces: cp /path/to/file/a.txt /path/to/file/{b,c,d}.txt But it gives me the error: target '/path/to/directory/d.txt' is not ...
0
votes
1answer
2k views

cp directory with permissions but not recursively

I want to create an empty directory with some permissions and owned by user apache:apache. I could just mkdir it, chown it and chmod it, but in directory where I want to create it I have a directory ...
2
votes
0answers
487 views

On MAC OS X 10.11.4 - Loss of extended file attribute when copying a file

I have a file with a comment as extended attribute. This is how I can see the attribute from the Terminal: mdls -name kMDItemFinderComment path_to_file I get the answer kMDItemFinderComment = "...
0
votes
2answers
36 views

Search by pattern, and copy within the same folder but with a different name

This is the folder structure: /home/user/Pictures/Vacation/Italy/Rome/photo.front.001.jpg Within the folder Rome I have many other photos, but I'm only interested in the ones that have "front" in ...
1
vote
2answers
3k views

Copy files that are created today without FIND command and SFTP to another server

I have a directory with 'n' number of files in it. I am trying to write a shell script which will list only the files created on the particular day the script is running, and will use sftp to move the ...
25
votes
4answers
1k views

What is the added value of the -T option in GNU cp and mv?

Why do some GNU Coreutils commands have the -T/--no-target-directory option? It seems like everything that it does can be achieved using the semantics of the . (self dot) in a traditional Unix ...
1
vote
3answers
2k views

Copy command with command line arguments

I am writing a simple script which will take a keyword. Then, it will look for files in the directory which contain that keyword and copy them to another directory (name of directory = keyword). The ...
4
votes
1answer
1k views

Recursive move (`mv -rn`, like `cp -rn`), a move that will only move not present files

Context I have user uploaded content that needs to be backed up. The content is over 3 separate servers at /var/www/domain/media/ (on each server it is in the same place). The backup is a NFS ...
0
votes
1answer
59 views

How To Copy Lossless from OSX ext to FAT32 without Ownership/Permissions? [closed]

I sudo-copied documents from OSX extended filesystem to FAT32. Now, I see that two trees are different by size and by Stephen's command here vimdiff <(find /Volumes/fat32/ -printf "%P %u:%g %m\n" |...
2
votes
2answers
4k views

How can I copy a hidden directory recursively and preserving its permissions?

mkdir backupcache cp -rp .cache backupcache # or cp -rp \.cache backupcache does not work nothing gets copied and directory backupcache remains empty
1
vote
1answer
687 views

Why does size increase after I copy?

I'm copying a directory from one mount point to another, yet I see a size increase between the two and I'm wondering why that is. My first mount point is named /home/directory/mount1, and inside it ...
3
votes
2answers
82 views

How to copy just timestamps, or “I should have used cp -p”

I foolishly copied a very large amount of data using cp -r. Looking at it now, I've realized that this means I lost my file modification times. I should have used cp -rp. My directory structure and ...
2
votes
1answer
164 views

copy huge number of files into date structured directory order

I need to copy around 40.0000 files into date structured folders. example file: /var/public/voicelogging/quality_monitoring/20151209/bbbbbb_I_20151209-185841_xxxxxx_12434_89343.WAV Is one of the ...
0
votes
2answers
469 views

Copy and rename on collision

I'd like to merge the content of these folders with a command line. . ├── folder1 │ │ file.txt │ ├── folder2 │ │ file.txt │ └───folder3 │ file.txt How can I do this ?
1
vote
0answers
594 views

Copies to NFS server write to mount point, not to mounted drive

I have a drive mounted at /home/ftpuser/uploads, and the /home/ftpuser folder is also exported via NFS. FTP uploads to the uploads folder work as intended. If I unmount the drive, the files disappear, ...
2
votes
6answers
32k views

copy file from user to another in linux

I'm trying to copy a file from my home directory to another user's directory. I have a sudo access for the other user with no password. I tried doing something like: sudo secondUser cp /home/...
4
votes
1answer
6k views

cp vs. mv: which operation is more efficient?

I find myself moving reasonably large amount of data (20+ GB) from one directory tree to other. Often times they are on the same filesystem but sometimes they are on different ones. I do cp just to ...
0
votes
2answers
57 views

Command which that isn't in norm

I have this example cp `which mv` rename In instruction of my homework is, that this command isn't in norm and replace the command with different example that does do exactly the same. My question ...
1
vote
2answers
3k views

Does cp -a refresh existing files, overwrite or skip

If I use cp in archive mode e.g cp -a /my_old_directory/* /new_location/my_new_directory/ to replicate a directory structure and all that is in it. If I then run the same command again will any ...
0
votes
2answers
3k views

cp: cannot create directory 'ABC.DEF/G/H': Structure needs cleaning

What does it mean "Structure needs cleaning" ? I've never seen such error code before - and man cp is not that helpful. It has happened to me on ext4. I was trying to copy directory using: cp -arv ...