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

  • 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
主站蜘蛛池模板: 青田县| 崇义县| 天全县| 兴安县| 苍溪县| 资源县| 泽库县| 周口市| 军事| 吉隆县| 上高县| 普格县| 扎赉特旗| 工布江达县| 县级市| 通许县| 丰台区| 元氏县| 长汀县| 雷州市| 昌江| 克什克腾旗| 固原市| 永宁县| 焦作市| 小金县| 南华县| 保亭| 武义县| 丹东市| 广州市| 阜康市| 福鼎市| 宁阳县| 丹巴县| 遂昌县| 南木林县| 神木县| 沙雅县| 高雄市| 吉安县|