官术网_书友最值得收藏!

Copying one file

Sometimes you need to copy a single file. Luckily this is a simple operation on the command line. I have a file named cats.txt in my home directory:

elliot@ubuntu-linux:~$ cat cats.txt 
I love cars!

I love cats!
I love penguins!
elliot@ubuntu-linux:~$

I can use the cp command to make a copy of cats.txt named copycats.txt as follows:

elliot@ubuntu-linux:~$ cp cats.txt copycats.txt 
elliot@ubuntu-linux:~$ cat copycats.txt

I love cars!
I love cats!
I love penguins!
elliot@ubuntu-linux:~$

As you can see, the copied file copycats.txt has the same content as the original file cats.txt.

I can also copy the file cats.txt to another directory. For example, I can copy the file cats.txt to /tmp by running the cp cats.txt /tmp command:

elliot@ubuntu-linux:~$ cp cats.txt /tmp
elliot@ubuntu-linux:~$ cd /tmp
elliot@ubuntu-linux:/tmp$ ls
cats.txt
elliot@ubuntu-linux:/tmp$

Notice that the copied file has the same name as the original file. I can also make another copy in /tmp with a different name:

elliot@ubuntu-linux:~$ cp cats.txt /tmp/cats2.txt
elliot@ubuntu-linux:~$ cd /tmp
elliot@ubuntu-linux:/tmp$ ls
cats2.txt cats.txt

elliot@ubuntu-linux:/tmp$
主站蜘蛛池模板: 德化县| 建湖县| 麦盖提县| 南平市| 安达市| 枣强县| 荆门市| 垣曲县| 济宁市| 勐海县| 三江| 庐江县| 逊克县| 新干县| 莎车县| 夏津县| 临夏县| 岫岩| 西青区| 宣化县| 岱山县| 科技| 通河县| 顺平县| 金阳县| 钦州市| 高州市| 安义县| 来安县| 新河县| 库伦旗| 清水县| 荆门市| 浮山县| 毕节市| 江西省| 射阳县| 蓬溪县| 扎鲁特旗| 扎囊县| 河津市|