是否有 tar 命令排除子目錄但包含檔案夾根目錄中的每個檔案,然后將它們放置在特定路徑?
我想省略每個子目錄,只保留檔案 max-min depth = 1 我已經嘗試了以下但它不起作用:
tar -cvf r.tar --exclude='~/root-dir/[subdir, ... ]' ~/Desktop
root-dir/
|
├── subdir/
│ ├── subdir/
│ │ └── a.txt
│ |
│ ├── subdir/
│ │ └── b.txt
│ │
│ └── c.txt
├── subdir/
│ ├── subdir/
│ │ └── d.txt
│ │
│ ├── subdir/
│ │ └── subdir/
│ │ └── subdir/
| | └── subdir/...
|
|
└── apple.txt
└── banana.image
└── ...
uj5u.com熱心網友回復:
首先,使用find來查找符合您條件的檔案:
find ~/Desktop -type f -maxdepth 1
然后將其通過管道傳輸到 tar,使用-T( 或--files-from) 告訴tar從以下位置獲取檔案串列stdin:
find ~/Desktop -type f -maxdepth 1 | \
tar -T - cvf r.tar
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/352408.html
