【问题标题】:tar folder and exclude all subfolders, then tar to specific pathtar 文件夹并排除所有子文件夹,然后 tar 到特定路径
【发布时间】:2021-12-20 22:37:21
【问题描述】:

是否有 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
└── ... 

【问题讨论】:

    标签: linux shell tar


    【解决方案1】:

    首先,使用find 查找符合您条件的文件:

    find ~/Desktop -type f -maxdepth 1
    

    然后将其通过管道传输到 tar,using -T ( or --files-from) to tell tar to get the list of files from stdin:

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

    【讨论】:

    • 哇,谢谢!这正是我想要的。是否有另一种选择可以防止将文件放入相应的路径文件夹中;即/home/Desktop/files -> /files 提取时?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-12
    • 2016-10-02
    • 1970-01-01
    相关资源
    最近更新 更多