- Learn Linux Quickly
- Ahmed AlKabary
- 147字
- 2021-06-11 18:43:48
Copying one directory
You may also want to copy an entire directory; that's also easily accomplished. To demonstrate, create a directory named cities in your home directory, and inside cities, create three files paris, tokyo, and london as follows:
elliot@ubuntu-linux:~$ mkdir cities
elliot@ubuntu-linux:~$ cd cities/
elliot@ubuntu-linux:~/cities$ touch paris tokyo london
elliot@ubuntu-linux:~/cities$ ls
london paris tokyo
Now if you want to copy the cities directory to /tmp, you have to pass the recursive -r option to the cp command as follows:
elliot@ubuntu-linux:~/cities$ cd ..
elliot@ubuntu-linux:~$ cp -r cities /tmp
You will get an error message if you omitted the -r option:
elliot@ubuntu-linux:~$ cp cities /tmp
cp: -r not specified; omitting directory 'cities'
You can verify that the cities directory is copied to /tmp by listing the files in /tmp:
elliot@ubuntu-linux:~$ cd /tmp
elliot@ubuntu-linux:/tmp$ ls
apple.txt banana.txt carrot.txt cats2.txt cats.txt cities
elliot@ubuntu-linux:/tmp$ ls cities
london paris tokyo
推薦閱讀
- Fundamentals of Linux
- 微信公眾平臺與小程序開發:從零搭建整套系統
- Android開發精要
- Building a Home Security System with Raspberry Pi
- Azure IoT Development Cookbook
- Unity 2020 Mobile Game Development
- JavaScript+jQuery開發實戰
- Java程序員面試算法寶典
- Git高手之路
- 教孩子學編程:C++入門圖解
- Learn React with TypeScript 3
- Mastering Apache Spark 2.x(Second Edition)
- Learning Raspbian
- Python忍者秘籍
- Learning Laravel's Eloquent