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

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
主站蜘蛛池模板: 济南市| 老河口市| 兴山县| 溧阳市| 赤水市| 浦县| 田东县| 湖州市| 定安县| 宜章县| 淮南市| 郯城县| 周宁县| 新闻| 南澳县| 龙胜| 石狮市| 长白| 钦州市| 黔西| 江西省| 郴州市| 监利县| 保靖县| 米脂县| 尉氏县| 安顺市| 黔东| 任丘市| 巴林左旗| 资中县| 腾冲县| 巴楚县| 大洼县| 邯郸县| 黄龙县| 东光县| 南召县| 洞口县| 金门县| 宽甸|