Orcka Orcka - 2 months ago 5
Bash Question

How to Copy contents in a directory to my current directory in shell?

Let's say I have a directory called A.

Directory A has a bunch of c files, and I want to cp all of these files to the directory the script is running in (in the case it would be Home in the linux system).

To make sure it successfully copied I would then echo whatever was copied.

This is what I have tried:

cp -r A Home/

echo `.c` # prints the files that have a .c at the end after they get copied


However the error I am getting is that the directory doesn't exist even though the directory is also in the Home directory. I also tried changing it to another directory which didn't seem to work either.

Another problem is that this doesn't copy to the current directory it copies to home. I used this list to see if there is a shell command, but couldn't find a copy command that allows me to place the files in the directory the script is running in.

https://www-xray.ast.cam.ac.uk/~jss/lecture/computing/notes/out/commands_basic/

Pat Pat
Answer

You should either be in the parent directory of A to copy it somewhere or mention the full path of the files to be copied.

Eg. if B is the parent of A.

You should already be in directory B to execute the command

cp -R A <your_destination_folder_path>

Eg. cp -R A . to denote the files are to be copied to the current path

It is better to give the full absolute path of your destination.

If you are already inside of directory A and just want to copy the directory files alone. You can give this

cp * <your_destination_folder_path>

If you are in any directory but just want to copy the contents of A, then provide the full (absolute) path or relative path to A to copy the files..