简体   繁体   English

tar 文件夹并排除所有子文件夹,然后 tar 到特定路径

[英]tar folder and exclude all subfolders, then tar to specific path

Is there a tar command to exclude sub-directories but include every file in the root of the folder and then place them at specific path?是否有 tar 命令排除子目录但包含文件夹根目录中的每个文件,然后将它们放置在特定路径?

I would like to omit every subdir, and only keep files max-min depth = 1 I have tried the follwing but its not working:我想省略每个子目录,只保留文件 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
└── ... 

first, use find to find the files meeting your criteria:首先,使用find查找符合您条件的文件:

find ~/Desktop -type f -maxdepth 1

then pipe it to tar, using -T ( or --files-from ) to tell tar to get the list of files from stdin :然后将其通过管道传输到 tar, 使用-T (或--files-from )告诉tarstdin获取文件列表

 find ~/Desktop -type f -maxdepth 1 | \
tar -T - cvf r.tar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM