Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a copy of a file and give it a different name mac terminal

Mac.

I'm in a directory dogs/scripts/cats.

Within this directory there is a file bla.txt.

I would like to make a copy of bla.txt called bla2.txt and keep it in the same directory.

How do I do that?

cp bla.txt dogs/scripts/cats 

'bla.txt' and `dogs/scripts/cats/bla.txt' are the same file

like image 952
Doug Fir Avatar asked May 05 '15 15:05

Doug Fir


People also ask

How do I rename a file in Mac terminal?

To rename a file in the terminal, move the file with mv from itself to itself with a new name. Here's an example. To rename a file on a computer with a graphical interface, you open a window, find the file you want to rename, click on its name (or right-click and select the option to rename), and then enter a new name.

How do I duplicate a file in Terminal?

To copy a file in a terminal, you use the cp command, which works exactly like the mv command, except that it duplicates the contents of a file rather than moving them from one location to another. As with the mv command, you can rename a file while copying it.

How do I copy and paste a file in Mac terminal?

In the Terminal app on your Mac, use the cp command to make a copy of a file. The -R flag causes cp to copy the folder and its contents.


1 Answers

cp can get a name of a target file:

cp bla.txt ./bla2.txt 

Or even simpler, as Mark noted:

cp bla.txt bla2.txt 
like image 123
Mureinik Avatar answered Oct 14 '22 12:10

Mureinik