how to rename files you put into a tar archive using linux 'tar'

前端 未结 4 1150
梦谈多话
梦谈多话 2021-01-03 21:32

I\'m trying to create a tar archive with a couple files, but rename those files in the archive. Right now I have something like this:

tar -czvf file1 /some/p         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-03 21:38

    We can refer to the man tar, the -O option is the best choice since files can be written to standard out.

    -O      (x, t modes only) In extract (-x) mode, files will be written to
             standard out rather than being extracted to disk.  In list (-t)
             mode, the file listing will be written to stderr rather than the
             usual stdout.
    

    here are the examples:

    # 1. without -O
    tar xzf 20170511162930.db.tar.gz
    # result: 20170511162930.db
    
    # 2. with -O
    tar xzf 20170511162930.db.tar.gz -O > latest.db
    # result: latest.db
    

提交回复
热议问题