命令
find
sed
腳本
# copy directory
find . -type d | sed 's/./mkdir -p ..\/clone_dir_arch/' | sh
tree ../clone_dir_arch
step1: 列出所有當(dāng)前目錄下所有目錄及其子目錄
$ find . -type d
輸出:
.
./examples
./examples/ace
./examples/ace/ttcp
./examples/ace/logging
./examples/wordcount
./examples/simple
./examples/simple/chargenclient
./examples/simple/timeclient
./examples/simple/chargen
./examples/simple/time
./examples/simple/daytime
./examples/simple/discard
./examples/simple/allinone
./examples/simple/echo
./examples/zeromq
./examples/pingpong
./examples/multiplexer
./examples/multiplexer/harness
./examples/multiplexer/harness/src
./examples/multiplexer/harness/src/com
./examples/multiplexer/harness/src/com/chenshuo
./examples/multiplexer/harness/src/com/chenshuo/muduo
./examples/multiplexer/harness/src/com/chenshuo/muduo/example
./examples/multiplexer/harness/src/com/chenshuo/muduo/example/multiplexer
./examples/multiplexer/harness/src/com/chenshuo/muduo/example/multiplexer/testcase
step2: 將上述列表的.
當(dāng)前目錄標(biāo)志替換為mkdir -p ../clone_dir_arch字符串
find . -type d | sed 's/./mkdir -p ..\/clone_dir_arch/'
輸出:
mkdir -p ../clone_dir_arch
mkdir -p ../clone_dir_arch/examples
mkdir -p ../clone_dir_arch/examples/ace
mkdir -p ../clone_dir_arch/examples/ace/ttcp
mkdir -p ../clone_dir_arch/examples/ace/logging
mkdir -p ../clone_dir_arch/examples/wordcount
mkdir -p ../clone_dir_arch/examples/simple
mkdir -p ../clone_dir_arch/examples/simple/chargenclient
mkdir -p ../clone_dir_arch/examples/simple/timeclient
mkdir -p ../clone_dir_arch/examples/simple/chargen
mkdir -p ../clone_dir_arch/examples/simple/time
mkdir -p ../clone_dir_arch/examples/simple/daytime
mkdir -p ../clone_dir_arch/examples/simple/discard
mkdir -p ../clone_dir_arch/examples/simple/allinone
mkdir -p ../clone_dir_arch/examples/simple/echo
mkdir -p ../clone_dir_arch/examples/zeromq
mkdir -p ../clone_dir_arch/examples/pingpong
mkdir -p ../clone_dir_arch/examples/multiplexer
mkdir -p ../clone_dir_arch/examples/multiplexer/harness
mkdir -p ../clone_dir_arch/examples/multiplexer/harness/src
mkdir -p ../clone_dir_arch/examples/multiplexer/harness/src/com
mkdir -p ../clone_dir_arch/examples/multiplexer/harness/src/com/chenshuo
mkdir -p ../clone_dir_arch/examples/multiplexer/harness/src/com/chenshuo/muduo
mkdir -p ../clone_dir_arch/examples/multiplexer/harness/src/com/chenshuo/muduo/example
mkdir -p ../clone_dir_arch/examples/multiplexer/harness/src/com/chenshuo/muduo/example/multiplexer
mkdir -p ../clone_dir_arch/examples/multiplexer/harness/src/com/chenshuo/muduo/example/multiplexer/testcase
step3: 執(zhí)行上述列表的每一項(xiàng)命令
find . -type d | sed 's/./mkdir -p ..\/clone_dir_arch/' | sh
step: 顯示復(fù)制的目錄列表
tree ../clone_dir_arch
輸出:
clone_dir_arch/
├── examples
│ ├── ace
│ │ ├── logging
│ │ └── ttcp
│ ├── asio
│ │ ├── chat
│ │ └── tutorial
│ │ ├── timer2
│ │ ├── timer3
│ │ ├── timer4
│ │ ├── timer5
│ │ └── timer6
│ ├── cdns
│ ├── curl
│ ├── fastcgi
│ ├── filetransfer
│ │ └── loadtest
│ ├── hub
│ ├── idleconnection
│ ├── maxconnection
│ ├── memcached
│ │ ├── client
│ │ └── server
│ ├── multiplexer
│ │ └── harness
│ │ └── src
│ │ └── com
│ │ └── chenshuo
│ │ └── muduo
│ │ └── example
│ │ └── multiplexer
│ │ └── testcase
│ ├── netty
│ │ ├── discard
│ │ ├── echo
│ │ └── uptime
│ ├── pingpong
│ ├── procmon
│ ├── protobuf
│ │ ├── codec
│ │ ├── resolver
│ │ ├── rpc
│ │ ├── rpcbalancer
│ │ └── rpcbench
│ ├── roundtrip
│ ├── shorturl
│ ├── simple
│ │ ├── allinone
│ │ ├── chargen
│ │ ├── chargenclient
│ │ ├── daytime
│ │ ├── discard
│ │ ├── echo
│ │ ├── time
│ │ └── timeclient
│ ├── socks4a
│ ├── sudoku
│ ├── twisted
│ │ └── finger
│ ├── wordcount
│ └── zeromq
└── muduo
├── base
│ ├── output
│ └── tests
└── net
├── http
│ └── tests
├── inspect
│ └── tests
├── output
├── poller
├── protobuf
├── protorpc
└── tests