It's easy.

Batch pack

This one will pack and compress each directory into separate tar.gz file.
ls | awk '{ print "tar zcvf "$0".tar.gz " $0|"/bin/bash" }'

If you do not wish to compress it, just pack the directory into file, use this one.
ls | awk '{ print "tar cvf "$0".tar " $0|"/bin/bash" }'

Batch unpack

For tar.gz files:
for i in $(ls *.tar.gz);do tar xzvf $i;done

For tar files:
for i in $(ls *.tar);do tar xvf $i;done

Notes

If you do not wish command printing every file it processed, just want it to do things quietly, remove option v in those commands.

Reference

  1. tar 批量打包一个文件夹下的多个目录(tar批量打包与解压)
文章目录