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

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
主站蜘蛛池模板: 姚安县| 天柱县| 溆浦县| 会理县| 杭锦旗| 东安县| 三亚市| 南宫市| 仪征市| 遵化市| 海原县| 龙里县| 成都市| 习水县| 秀山| 潜江市| 宝清县| 盘锦市| 高陵县| 金坛市| 巧家县| 班戈县| 麟游县| 许昌县| 班戈县| 汽车| 无为县| 鄂托克前旗| 尉犁县| 贡嘎县| 上林县| 湖南省| 益阳市| 万源市| 嘉峪关市| 思南县| 怀安县| 澄迈县| 绥中县| 德阳市| 苗栗县|