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

  • 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
主站蜘蛛池模板: 耒阳市| 梓潼县| 景德镇市| 越西县| 纳雍县| 齐河县| 隆德县| 常宁市| 大连市| 藁城市| 宜州市| 舟山市| 泾阳县| 驻马店市| 喀喇| 阿鲁科尔沁旗| 周至县| 七台河市| 丰城市| 湛江市| 马尔康县| 修文县| 鹤庆县| 凌云县| 吕梁市| 彝良县| 衡阳市| 苗栗市| 湘乡市| 怀仁县| 永康市| 兴文县| 富裕县| 仁化县| 阿勒泰市| 沾化县| 甘洛县| 天长市| 阿坝县| 安泽县| 凉城县|