- 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$
推薦閱讀
- The Complete Rust Programming Reference Guide
- LabVIEW入門與實戰開發100例
- C# 從入門到項目實踐(超值版)
- 區塊鏈架構與實現:Cosmos詳解
- Python自動化運維快速入門
- Learning Python Design Patterns(Second Edition)
- PostgreSQL Replication(Second Edition)
- 前端HTML+CSS修煉之道(視頻同步+直播)
- Go語言精進之路:從新手到高手的編程思想、方法和技巧(1)
- C語言開發基礎教程(Dev-C++)(第2版)
- Learning Apache Cassandra
- Building Wireless Sensor Networks Using Arduino
- 運維前線:一線運維專家的運維方法、技巧與實踐
- Java Web從入門到精通(第3版)
- SQL Server 2016 從入門到實戰(視頻教學版)