We’re rewarding the question askers & reputations are being recalculated! Read more.

Questions tagged [cp]

cp - Command-line tool to copy a file

Filter by
Sorted by
Tagged with
1
vote
2answers
20 views

For loop to find files of largest size and copy them to another directory

I am trying to create a loop to sort files within each of many directories by size, then copy the largest two to another location, keeping the directory format (below). folder/sample 1 .../...
0
votes
1answer
74 views

Copy and rename file

The structure of my files is as follows: My_Files: |-- Folder_1: | |-- a.txt | |-- b.txt | |-- c.txt | |-- Folder_2: ...
0
votes
1answer
27 views

How to extract and copy certain files from a directory in shell

I'm trying to write a script to do the following: There´s a directory "x". In this directory there are several folders, some of these folders begin with NZ or NC (e.g NZ_FGT10000, NC_HGU987000) (...
0
votes
3answers
18 views

Not able to access files copied using double quote

By mistake, I have copied 100 files using the cp command as $ cp file1 "/data/ file1" $ cp file2 "/data/ file2" note:- there is a space between /data and file2, file1 Within the /data directory, I ...
3
votes
2answers
61 views

Copy a file over serial connection

So what I am trying to achieve seems quite simple, but I can not seem to find a way to do it without using external utilities or not pre-installed libraries. I have an embedded system running Linux (...
0
votes
1answer
23 views

Copy files with specific header

How can I copy files with a contition that: the file content starts with Ascii UnityFS5 ? I think I have to join commands cp, find, cat and grep but I don't know how to do it.
0
votes
1answer
22 views

Copying latest files (date=today) from local to HDFS with spaces in the names on daily basis

I have daily incoming files in a local folder(/home/gas_uk). I want to put/copy the latest files from local for today to the HDFS directory (/apps/hive/warehouse/gas_uk/). I have tried : find /home/...
2
votes
2answers
105 views

Coping with filenames starting with a dash (“-”) when using `-exec` and `xargs`

I am following this question though some of the file names here contain a dash at the beginning of the filename. This is interpreted as an additional option for cp. Following another question (on ...
2
votes
4answers
77 views

Copy multiple files in multiple folders into one

How may I copy multiple files in multiple folders into one folder and change their names according to what directory they are copied from? Initial directory hierarchy: folder1/ file1.gz ...
0
votes
1answer
22 views

Rsync/Copy certain file extensions stripping folders

I have a bunch of folders with sub directories please see below Books -- Temp1.nfo -- Temp2.txt -- Temp3.doc Books 2 -- Temp4.nfo -- Temp5.txt -- Temp6.doc I want to copy the txt and doc file ...
0
votes
2answers
37 views

How to find and copy only the first 100 .jpg files under the home directory, including all the subdirectories within?

I coded like below: $ find . -maxdepth 1 -name '*.jpg' | head -n 100 | xargs -0 {} cp {} /home/rachael/backup Error showed: xargs: {}: No such file or directory What's wrong with my code and how ...
0
votes
3answers
54 views

How to copy a file to a destination folder and cd to the destination folder in one command

To explain my question, here is the dumb way of how I'm doing things: cp fileFromMyFriend.txt ~/my_first_subfolder/my_second_subfolder/more_subfolders cd ~/my_first_subfolder/my_second_subfolder/...
-3
votes
1answer
35 views

How to make several copies of a directory with `cp`?

I am running Debian GNU/Linux. I ran the following commands: mkdir code cp -Rf code code{1..255} The first cmd created a directory called code. The second command is meant to copy the folder ...
1
vote
2answers
69 views

Copy the same file to the desktops of all users

I’m looking for a way to copy a file to all Desktops directory of each user. Something like: cp myfile /home/*/Desktop/ I found a way to copy files to all home directories using xargs but it fails ...
0
votes
1answer
27 views

Zip a folder while copying it

Is it possible to zip a folder while copying it? I want to copy a folder and then zip it, but this implies that I need for a while twice the space in my /mnt path, right? /bin/cp -r /mnt/myfolder /...
2
votes
1answer
77 views

Bash copy command not working after file rename

I have this installer shell script in a bash script. I am doing a rename of the existing text file (backing it up). I remove old file Copy fresh file to the target dir mv /target/data.ini /target/...
-2
votes
2answers
128 views

cp -a doesn't work to copy all files inside a directory

I desire to copy all files inside a directory which has only these files (all are regular files - there are no directories, symlinks, etc, inside that directory) to another pre-existing directory. The ...
4
votes
4answers
389 views

Just one file echoed from an array of files

I try to copy 2 or more files from one directory to another with cp using an array. I executed: files=( LocalSettings.php robots.txt .htaccess ${domain}.png googlec69e044fede13fdc....
-7
votes
1answer
88 views

What is -a argument for GNU cp? [closed]

The manual for GNU cp says -a, --archive same as -dR --preserve=all What is the meaning of "archive" here (which I assume radically different than with tar or zip)? Edit: I should have read -...
0
votes
2answers
93 views

cp in multi line fashion

In CentOS with Bash 3.2.52(2) I have to copy many files (not all) from one directory to another. I can create a long one liner such as cp /"$HOME"/dir1/{file1,fil2} ... /"$HOME"/dir2 but because ...
0
votes
0answers
32 views

cp from locally mounted sshfs corrupting .gz files

I have used sshfs to locally mount a SFTP server's filesystem. I am trying to copy .gz files from the sshfs mount (/mnt/mysftp/) to /tmp and noticed when the file is large (~10MB+), it will copy over ...
-1
votes
2answers
28 views

bash: why can't I copy 3 files into 3 directories that share a name with the files?

So if I can do this: $ mkdir ./blah_{007,011,090} And end up with three directories... Why can't I do this... cp ../blah_{007,011,090}.swf ./blah_{007,011,090}_src And copy the files into 3 ...
9
votes
5answers
1k views

How to copy a file transactionally?

I want to copy a file from A to B, which may be on different filesystems. There are some additional requirements: The copy is all or nothing, no partial or corrupt file B left in place on crash; Do ...
-1
votes
1answer
82 views

Copy files from remote machine to folder on remote machine

Why do we get the following error about "No such file or directory" when we copy files from remote folder to another remote folder? ssh -n -o ConnectTimeout=50 -o StrictHostKeyChecking=no -xaq $IP ...
2
votes
0answers
56 views

Using cp to copy ~/.config to an external drive but getting “cannot create regular file…File exists” errors

The command is simple enough, executed while in a subdirectory of /mnt/e, an external drive: cp -r ~/.config .. Every time, every time I run it, the same set of files refuse to copy properly: cp: ...
1
vote
1answer
27 views

Copy file with changed content

I'm writing bash script where I need to store some files as a .bak files and change it content at the beginning(using sed for that). I'm looking for better way to write it down for my bash script. cp ...
-1
votes
2answers
143 views

How to copy files one by one to different folders?

In a directory I have files with the names: 01.txt 02.txt 03.txt In the same directory are folders with the names: 01.abc 02.def 03.ghi I need a command to copy the files to the folders one by one,...
0
votes
1answer
41 views

Shell script cp command to a folder that will constantly change name

I have a script that downloads a folder. The folder has a fixed name with an ever changing number as a suffix, e.g. fixed_name_450. Each time I run to script the downloaded folder will have a new ...
0
votes
1answer
592 views

Missing destination file operand

I am beginner as far as Linux is concerned and therfore ran into trouble with the following command. $ cp VRP/share/ViennaRNA/bin/*. The error I got is as follows: cp: missing destination file ...
1
vote
0answers
40 views

cp - Does not recognizning accent characters [duplicate]

I have written a simple script, to copy some files, and change there name: #!/bin/bash for directory in ./../old_files/*; do DIR_NAME=$(basename $directory) for file in $directory/*; do ...
0
votes
3answers
122 views

Copying a list of files

I have a directory which has plenty of files which need to be copied over to another directory. Remember, not all files need to be copied, only some of them. Is there a way I can come up with a script ...
0
votes
1answer
49 views

How to select a path in a find […] -exec cp {} dest_dir \; command?

I'm having a hard time trying to limit the path with find. I have this command find ${DIR_PATH} -type f -name ".py" -exec cp --parent {} ${DEST_DIR} \; Which give me this output : ${DIR_PATH}/a/...
1
vote
3answers
50 views

Copy files from one path to another except .zip files [closed]

I need to copy all files from one UNIX path to another within the same server. However, there are some .zip files I want to exclude while copying. How can I achieve this using the cp command options?
1
vote
1answer
2k views

COPY failed: stat /mnt/sda1/var/lib/docker/tmp/docker-builder006125699/src: no such file or directory

When I run this command docker build -t hello-world . I got this kind of error...what should I do...How to copy file to /var/www/html/ Sending build context to Docker daemon 2.048kB Step 1/3 : ...
0
votes
2answers
32 views

Copying diff results files

I have two folders - Folder A and Folder B. I compared the files from both folders using diff command. Now after finding that certain files are only available in Folder A and Certain files in Folder ...
1
vote
2answers
95 views

How to avoid copying “..” while using cp command in terminal? [duplicate]

I am using CentOS7 and when I use command cp /root/test/.* /root/test1 it also copies .. which copies all the files and folder in the parent directory of the source. How to avoid copying . and ..?
4
votes
1answer
99 views

Move/copy millions of images from Macos to external drive to ubuntu server

I have created a dataset of millions (>15M, so far) of images for a machine-learning project, taking up over 500GB of storage. I created them on my Macbook Pro but want to get them to our DGX1 (GPU ...
1
vote
1answer
46 views

Overwrite or don't copy?

I'm trying to copy a file only if it already exists, not if it doesn't, basically overwrite only on Linux. Does anyone know a solution? I basically need to "look" for a folder then if a file exists, ...
1
vote
1answer
254 views

cp runs from command line but file not found from script [duplicate]

I have a script to reorganize my directory structure that contains: files=./*"$pattern"I{"$ifirst".."$ilast"}.ext cp ${files} ../"$pattern"/"$i"/ When I run the script, I get an error: ./*S6I{001.....
0
votes
2answers
70 views

Copy every 10 files from source into a target directory using cp

I have 110 large files inside a directory. But I cannot copy them at once since the system gets timed out after 50 min. I want to copy files 1 to 10, next 11 to 20, next 21 to 30, and so on. The order ...
2
votes
1answer
48 views

How to write a script to move files with a specific name from folder “A” to folder “B” in my Google drive?

How can I write a script that moves files with a certain name from a certain folder to another certain folder in my Google drive? Example: I have a folder named 'A' with three files named 'X', 'Y', ...
-6
votes
1answer
122 views

What is the meaning of -r and -R in copy command?

I read that they stand for recursively in the man page. However, I am not sure what their role is in the command. When I tried to copy some empty directory into another directory with, $ cp EMPDIR ...
0
votes
1answer
94 views

What happens when you copy a hardlink?

Imagine I have a file something/a.txt, which I hardlink from b.txt. Now, if I cp b.txt c.txt, is c.txt a hard link to a.txt, or is it a copy of the contents of a.txt?
1
vote
1answer
44 views

Attempting to only copy files that have changed within the last day while maintaining folder structure

I'm attempting to find and copy files that have been modified within the last day. While doing that I'm trying maintain folder structures under dir1. There are many subdirectories under dir1 and data ...
0
votes
0answers
44 views

Can I specify a size space while using mount command?

I mount a *.img file, and want to copy some new files into it. But there is not enough space for me to place new files. Can I specify more size space while I use mount. ./Image: No space left on ...
0
votes
2answers
25 views

Recursively copying a folder to an empty subfolder

How to copy all the content of the folder /foo/bar, which contains the file /foo/bar/a to an empty subfolder /foo/bar/subfolder without ending up with the file /foo/bar/subfolder/subfolder/a. Doing cp ...
5
votes
1answer
754 views

systemd and copy (/bin/cp): no such file or directory

While manually copying the file the following works, as below: userx@x:~$ cp -rv /opt/test-bak/* /opt/test/ '/opt/test-bak/file1' -> '/opt/test/file1' '/opt/test-bak/file2' -> '/opt/test/file2' ...
1
vote
1answer
151 views

cp multiple files do not work in bash script

I would like to run the below command in a bash script but, it doesn't work. command: cp /tmp/first/{abc.conf,xyz.conf} /tmp/backup/ bash script: firstDir=/tmp/first #secondDir=/tmp/second ...
2
votes
1answer
673 views

“cp: target '…’ is not a directory” during while loop

I have a directory of files whose names I want to shorten: (3) andrew@andrew Learning_Plans $ ls -al total 580 drwxr-xr-x 2 andrew andrew 4096 Apr 10 21:40 . drwxr-xr-x 7 andrew andrew 4096 Apr 10 ...
1
vote
2answers
261 views

How do I get commands in a bash script to complete? (files get truncated with cp)

I have a server that receives backupname.tar.gz files in /home/my_user/drop directory every hour. I installed incron utility and use incrontab -e entry to run a script whenever a new file shows up in /...