Questions tagged [cp]

cp - Command-line tool to copy a file

Filter by
Sorted by
Tagged with
2
votes
4answers
801 views

Bash script copy file to user's (wildcard) home dir

I need to copy /root/nbu/file1.sh to every user's home directory if user's id is even number. Trying to execute following script: #!/bin/bash cat /etc/passwd | while read LINE do username=$(awk -...
1
vote
0answers
227 views

See the overall percentage completion of a recursive cp command

Is it a simple way to track the completion of a large cp -r command? To get something like: copying 10% ... copying 20% Maybe using a pipe to another command? cp -rvv orig dest | show_as_percent ...
3
votes
2answers
176 views

Rsync and cp command to copy “.txt” files to single directory (only if already exists)

I have a directory structure with multiple .txt files with multiple directories. I want to copy all these .txt files into one particular directory. I have given below my directory structure: Dir_1 ...
-4
votes
2answers
2k views

In Unix how would I copy /etc/passwd using relative path to a directory under my home directory? [closed]

I am required to copy the /etc/passwd to a directory, I have already created, with the new name my_passwd. I understand how to copy it with an absolute path: cp /etc/passwd /home/user/work/my_passwd. ...
2
votes
3answers
100 views

How to copy just certain words from a file into a new file

I have a homework assignment where I have a file that is a large list of words. I have to copy into a new file all the words starting with c and name it cwords. I can see a list of the words by ...
-1
votes
1answer
146 views

progress bar while copying a file from hdd to usb drive (no rsync)

I used to rsync and xfr#1, to-chk=0/1, what do they mean? but with the recent rsync bug https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=862899 I don't know the solution. Does anybody of any ...
0
votes
1answer
309 views

How do I use `cp -R` to copy all files to a subfolder without copying the subfolder as well?

I have an image folder which I am trying to copy into a subfolder of itself, so I can resize the images there. It looks something like this: Sephs-MacBook-Pro:photos seph$ ls 100x100 ...
2
votes
0answers
54 views

Simple method for copying a file and preserving it's path? [duplicate]

I want to copy a file from drive A to drive B, preserving the file's path. For instance /A/x/y/z/file.txt to /B/x/y/z/file.txt However, you cannot cp a file to a directory that doesn't already ...
0
votes
3answers
87 views

Sort and copy files from several directories

I have a directory containing several sub-directories, containing files. I would like to sort the files in each of these directories by name alphabetically and copy the first file from each ...
7
votes
2answers
20k views

How can I copy a directory and rename it in the same command?

Currently, I'm running these two commands to create a quick backup of the directory. Is there a way to combine the two commands into one, so that I am copying and renaming the new directory in one ...
1
vote
1answer
360 views

How do I make a duplicate of a directory tree with symlinks duplicated relatively?

I want to duplicate directory 'foo' and all its subdirectories to 'foo_copy'. 1) I don't want 'foo_copy' to have several copies of some files or directories with one copy for each symlink to the file ...
13
votes
2answers
3k views

cp behaves weirdly when . (dot) or .. (dot dot) are the source directory

This answer reveals that one can copy all files - including hidden ones - from directory src into directory dest like so: mkdir dest cp -r src/. dest There is no explanation in the answer or its ...
1
vote
1answer
287 views

Why 'cp --preserve=links' doesn't work? [duplicate]

Why cp --preserve=links doesn't work? I want to copy some symbolic links.From man page: --preserve[=ATTR_LIST] preserve the specified attributes (default: mode,ownership,timestamps), if ...
1
vote
1answer
41 views

centos 6.3 bug command[cp] [closed]

echo "aaa" >abc.1.txt echo "bbb" >abc.2.txt cp abc* linux no error bug same command [ cp abc.1.txt abc.2.txt] cp abc.* = cp abc.1.txt abc.2.txt why?
4
votes
1answer
513 views

How to force Fedora 27 to write to USB flash drive immediately?

My Fedora 27 writes actual data to USB on umount. Before umount it works only with links or something like that. So, for example, when I transfer a big file of 5 GB cp /home/iam/bigFile /run/mnt/iam/...
2
votes
1answer
707 views

Copy files listed by the find command and rename it with the path

I'm doing a find of all files with certain extension and then I copy them to a certain folder, but most of them are overwritten because they have the same name. How can I, with a Linux command, get ...
0
votes
1answer
138 views

Define target directory with flag in `scp` or `rsync` (like `cp -t`)

Since I'm often copying a varying number of specific files to a (rather convoluted) destination directory over the network, my life would be so much easier if I could use cp's -t flag: With it, you ...
6
votes
2answers
3k views

cp losing file's metadata

I have an Asustor NAS that runs on Linux; I don't know what distro they use. I'm able to log in it using SSH and use all Shell commands. Internal Volume uses ext2, and external USB HDs use NTFS. ...
1
vote
3answers
203 views

How to batch cp files and rename by adding prefix in current directory in one command-line without using for loop?

Example: . ├── f1.md ├── f2.md ├── f3.md ├── f4.txt ├── f5.csv ├── f6.doc ├── s1 ├── s2 ├── s3 └── s4 4 directories, 6 files I want to copy f1.md/f2.md/f3.md in current directory, and the results ...
2
votes
1answer
206 views

How to copy and add prefix to file names in one step from another directory?

I want to copy and rename multiple files from one directory to another. Particularly, I want something like this: /tmp/tmp.XXX/aaa.original.txt /tmp/tmp.XXX/bb5.original.txt /tmp/tmp.XXX/x2x.original....
2
votes
1answer
124 views

Is it possible to “clone” with rsync a folder to another by creating only symbolic links

Is it possible to use rsync to "clone" a folder to a new folder but create the new folder tree structure as a symbolic link to the SOURCE. cp -as SOURCE DEST -s, --symbolic-link make ...
0
votes
2answers
185 views

make copy of file and place in new directory using relative path [duplicate]

i have been stuck on this question for my lab for linux class
1
vote
0answers
55 views

what is the best approach to move /var?

we have linux red hat 7 we want to keep the /var on other volume so the plan is to: mkdir /var_copy cp -rp /var/* /var_copy umount /dev/mapper/vg-a-var /var rm -rf /var mkdir /var mount /dev/...
8
votes
2answers
2k views

cp: invalid option — 'o'

I'm following an installation script on GitHub and one of the steps is: cp sources/openssl/1.0.1p/Android.mk -o sources/openssl/$OPENSSL_VERSION/Android.mk But my terminal threw an error cp: invalid ...
2
votes
1answer
65 views

Place ht access file in webroot of each directory bash script

I'm trying to write a script that will descend into each subdirectory in /home and find the public_html folder within. Then it will check if an .htaccess already exists, if it does write that to a ...
1
vote
2answers
102 views

Compare existing file in two different directories, copy if not existent, else overwrite it

I'm trying to build a scrip that compare a file inside different 2 dir,then copy them from dir1 to dir2 is it's not exists in the dir2, or overwrite it if its already existed. I know that i can use ...
1
vote
0answers
421 views

cp on nfs share claims to fail but actually succeeds

I am dealing with an nfs share where I have read/write permissions. Everything seems to work fine, except when I copy files to subdirectories. Then the cp command complains that file creation was ...
0
votes
1answer
238 views

Copying a folder using xargs

A command gives me the path of a folder. I want to copy the content of this folder to the current working directory. What I tried so far is bundle show minima | xargs -I{} cp -r {} ./ where ...
9
votes
1answer
2k views

Are there any disadvantages of `cp --sparse=always`?

Is there any reason not to use use --sparse=always with every invocation to cp? info cp says: ‘--sparse=WHEN’ A “sparse file” contains “holes”—a sequence of zero bytes that does not occupy ...
0
votes
1answer
63 views

How to copy matching files from directory/subdirectory to a another directory

I am having following folder structure. applications (main directory) - 1 (sub directory) application_1.pdf - 2 application_2.pdf - 3 application_3.pdf I wanted to copy all the ...
1
vote
2answers
7k views

ls shows a directory but it is inaccessible

I was trying to copy one folder from one location to another. The folder is about 6.4 Gb. So I did cp -r source_folder level1/val after that, I went into the level1 folder and checked: level1$ ...
0
votes
2answers
372 views

Find and copy with xargs doesn't work in a script

I need to find three files from a huge directory and copy them to another directory. This is what I have done: find $adir -type f \( -name "a1*" -o -name "a2*" -o -name "a3*" \) -mtime -8 | xargs cp ...
0
votes
1answer
67 views

specific copy of files

I have files and directories that have same suffix ( from 0 t0 310). and I want to copy file(0) to directory(0), file(10) to directory(10) and go on till file(310) to directory(310). Is there any way ...
6
votes
2answers
2k views

Info on cp --preserve=links

I'm trying to understand what cp --preserve=links does when used by itself, from my tests it seems that it copies a normal file normally and dereferences symlinks, but it seems like it just has the ...
1
vote
0answers
128 views

Copy without overwriting does not work [closed]

I have a folder structure that contains a bunch of files named "swagger.json" and I need to copy them to a destination folder without overwriting. The expected result is: /Downloads/swagger.json /...
0
votes
1answer
864 views

Do cp and tar create temporary files and then do an atomic mv ?

I'm using Java's Files.walkFileTree to scan a particular directory periodically for *.csv files and then reading them. I know that mv is atomic ( at least within the same device ) so 'mv'ing a file ...
8
votes
5answers
1k views

make scp behave like it is supposed to (remote file copy program) [closed]

I want to copy local file to a remote server using scp. scp -rp local-file my.server.com:/tmp/ Sometimes I forget to specify where on the remote server the file should be copied to: scp -rp local-...
4
votes
3answers
690 views

Remove lines of text that end in “/”

I am using rsync to generate a list of files that have changed and then using that list to upload the files to s3: rsync -av somefiles/ someotherfiles/ > list.txt while read F ; do echo $...
1
vote
2answers
1k views

find and copy files using input list and partial file paths

I have a list of filenames names.list which contains names only. These files are scattered throughout my system in various sub folders but the structure is generally uniquename/uniquename2/spades/...
4
votes
3answers
17k views

How to copy directories via ssh

I am connected with ssh and I want to copy a directory from my local to our remote server; how can I do that? I have read several post using scp but that doesn't worked for me. Some posts suggested ...
1
vote
1answer
170 views

How to copy same named files from one location to another location number of times using linux command?

I have the following tree struture. sl_top | |-- Pinmux_Formal_checklist | | |-- Pinmux_Formal_checklist.config | | |-- Pinmux_Formal_checklist.html | | `-- rev1 | ...
7
votes
1answer
8k views

cp: cannot create regular file: Invalid argument

sudo cp -r "/home/fleamour/Music/Mum's Music" /run/media/fleamour/3732-6531 cp: cannot create regular file '/run/media/fleamour/3732-6531/Mum'\''s Music/Louis Armstrong - At His Very Best/13 - Louis ...
2
votes
2answers
2k views

Why does cp not set source attributes and fail with -p?

I have these files: -rw-rw-r-- 1 root adm 0 Jun 22 11:25 a -rw-rw-r-- 1 wilmes wilmes 0 Jun 22 11:23 b When I cp b over to a as user wilmes why does it keep the original owner of a (root)? I ...
2
votes
1answer
539 views

cp -al not creating hard links

I want to create snapshots/hard links for my backups, using the cp -al command. While cp -al does create hardlinks when using it on my main system (Mint 18.1), where the parent directory size stays ...
-3
votes
1answer
58 views

How to create copies of a directory with sequential numbers

I have a template directory containing sub-directories and MS-Windows links. This directory needs to be sequentially reproduced at the same folder level. The range needs to be from one to twenty. So, ...
2
votes
1answer
445 views

cp: prevent error when source and destination are the same

Can you tell cp (GNU coreutils) to prevent reporting an error on: $ echo 1 > foo $ cp foo foo Currently, this reports: cp: 'foo' and 'foo' are the same file That's very sensible, but it's not ...
1
vote
1answer
464 views

Excluding specific folders while copying stuffs from one directory to another

I have to copy contents of some code from one folder called aim-db-dir to another called aim-db-dir_nosvn. aim-db-dir contains .svn folders in all the directories (and subdirectories) and these .svn ...
1
vote
1answer
102 views

How to copy a certain amount of sorted files? (e.g. 11 GB)

I'd like to copy a total of 11 GB of files (all of the type .mp3 for the sake of this question) from folder ~/ABC/ to ~/DEF/. And I like to do that for the files sorted descending by date last edited/...
1
vote
1answer
1k views

cp: ‘x’ and ‘y’ are the same file

This is really weird. I am trying to copy a file. I do cp config.yaml config-test.yaml. However, I get cp: ‘config.yaml’ and ‘config-test.yaml’ are the same file. ls -l config*.yaml gives May 30 16:...
0
votes
1answer
445 views

cp from different directory to one directory certain files

I want to do the following. I want to copy from a remote FTP server every day certain files. This FTP directory is mounted. Every day a directory is created and within that directory I need 3 files ...