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

  • Learn Linux Quickly
  • Ahmed AlKabary
  • 169字
  • 2021-06-11 18:43:48

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$
主站蜘蛛池模板: 江口县| 喀什市| 屏东市| 申扎县| 甘泉县| 广昌县| 泽普县| 临邑县| 广宁县| 卢湾区| 高阳县| 桦南县| 会同县| 西安市| 连南| 平和县| 东莞市| 万州区| 丘北县| 静宁县| 额敏县| 尤溪县| 枣庄市| 莱州市| 南康市| 九龙坡区| 班戈县| 邻水| 宾川县| 从江县| 赣榆县| 乾安县| 阿克苏市| 郁南县| 当涂县| 邮箱| 岳阳县| 安泽县| 靖西县| 陵川县| 黄骅市|