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

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$
主站蜘蛛池模板: 象山县| 特克斯县| 方城县| 宁晋县| 保山市| 贡嘎县| 拉孜县| 双辽市| 南岸区| 邵阳县| 扶风县| 宜黄县| 库尔勒市| 炉霍县| 三门县| 白玉县| 兰坪| 和田县| 称多县| 滨海县| 两当县| 三江| 南和县| 南江县| 宜昌市| 马尔康县| 封丘县| 苏尼特左旗| 连州市| 卢氏县| 永川市| 青铜峡市| 聂拉木县| 湖南省| 贡嘎县| 昌黎县| 九寨沟县| 辽宁省| 四子王旗| 建瓯市| 满洲里市|