Transferring all files from one directory to another [duplicate]

The system displayed an error message upon execution of the following commands: “To copy all files from the ‘new’ folder created from July 20th until today’s date,” and “this command copied all files into a subfolder located within the ‘new’ folder.

Question:

I attempted to duplicate a folder’s images into another folder, and utilized the following code:

!cp -r /content/COVID-19 Radiography Database/COVID-19 /data

.

The current action results in the creation of a folder named

COVID-19

within the

data

folder. However, I do not wish to create a

COVID-19

folder within

data

. Instead, I would like to directly copy the images without creating any additional folders.

The command is designed to copy all files from

data

folder, except those in the

COVID-19

folder, and move them directly to the

data

folder.


Solution 1:

Consider employing a wildcard to capture all the contents within the folder.


!cp -r /content/COVID-19 Radiography Database/COVID-19/* /data

The initial instruction is to duplicate

COVID-19

directory into

/data

directory. The asterisk symbol implies that all files in the former directory should also be copied to

/data

directory.


Solution 2:

cp -a /source/. /dest/


The

-a

function facilitates recursive copying, while the

.

command at the end ensures the copying of
hidden files
as well.


Solution 3:


By using the flag “-R”, all the contents of “folder1” can be copied perfectly to the already existing “folder2”.

cp -R folder1/. folder2

When using the “-R” flag, symbolic links are also copied, whereas the “-r” flag skips them. Therefore, the “-R” flag is superior to the “-r” flag.

  • The most recent version of GNU Grep is 3.7.
-R, --dereference-recursive
For each directory operand, read and process all files in that directory, 
recursively, following all symbolic links.
-r, --recursive
For each directory operand, read and process all files in that directory, 
recursively. Follow symbolic links on the command line, but skip symlinks 
that are encountered recursively. Note that if no file operand is given, 
grep searches the working directory. This is the same as the 
‘--directories=recurse’ option.

Frequently Asked Questions