
[@ysx-dlfwq-2 555]$ tree
.
├── 666
├── 777
│ └── 71.sh
├── 888
│ └── 8881
├── test2.sh
├── test.sh
└── test.txt
4 directories, 4 files
After executing the command
find /opt/share/555/ -mindepth 1 -type d \( -path /opt/share/555/666 -o -path /opt/share/555/888/8881 \) -o -type f \( -path /opt/share/555/test.txt \) -prune -o -exec cp -prf {} /opt/share/2/ \;
[@ysx-dlfwq-2 2]# tree
.
├── 71.sh <<<----Files that should not appear
├── 777
│ └── 71.sh
├── 888
│ └── 8881 <<<----Directory that should not appear
├── test2.sh
└── test.sh
3 directories, 4 files
我們的環境只允許使用內建系統指令,rsync不在考慮範圍內。如果我目前所知沒有支援正規表示式的指令,請專家幫忙?
答案1
我有點不清楚你想要完成什麼,但...
您可以使用find
它來產生要複製的文件列表,傳遞該列表以grep
對其進行過濾,並將結果通過管道傳遞到cpio
實際複製文件:
find /opt/share/555/ -type f |
grep -v 'whatever' |
cpio -pd /opt/share/2
這允許您使用正規表示式來控制複製或不複製的內容。