Copying Hidden Files

Screen Link: Learn data science with Python and R projects

I am trying to complete this exercise : Create a copy of the hidden file /home/dq/prize_winners/.mike called mike. Place it in /home/dq/prize_winners

I tried to acheive this with the following code
cp /home/dq/prize_winners/.mike /home/dq/prize_winners

However the answer uses this code:

cp /home/dq/prize_winners/.mike /home/dq/prize_winners/mike

I thought when you specified a file location, you specify a directory, but this specifies a file as the location. Why?

Thankyou for your time and help.

When you use

You are trying to create a copy of the file .mike in the prize-_winners folder. There is no name provided so the file will be saved as .mike.

When you use

You are trying to create a copy of the file .mike in the prize_winners folder. But, this time, there is a name provided - mike. So, the file will be saved as mike and not as .mike.

If mike was an existing folder then the above command would have copied over the .mike file inside of that folder. If mike was an existing file then the above command would have copied the contents of .mike into mike. Since mike didn’t exist, a new file containing the contents from .mike was created.

1 Like