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

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$
主站蜘蛛池模板: 弋阳县| 新闻| 闵行区| 喀喇沁旗| 莒南县| 安新县| 镇原县| 兴隆县| 雷州市| 玛沁县| 财经| 手游| 枞阳县| 宁波市| 兰西县| 屏南县| 珲春市| 新干县| 福鼎市| 北海市| 孟津县| 南康市| 林甸县| 云南省| 文登市| 库伦旗| 博客| 南安市| 贞丰县| 唐河县| 林芝县| 邯郸市| 阿图什市| 张家界市| 宁城县| 江津市| 仙游县| 拉孜县| 揭西县| 顺平县| 孝义市|