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
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With