tar Command Daily Work Summary

This article used to walk you through some commonly tar usages , based on a real life scenario.

################################################################
#   Insert latest update at the top of the logs
#
#   Date           Description
#   02/22/2019     list tar content
#   02/21/2019     tar exclude
#   02/20/2019     untar multiple files
#   02/19/2019     tar files
#
################################################################

02/19/2019

tar files into example.tar.gz

tar czf example.tar.gz file1 file2 file3 …

tar directory target and its content into example.tar.gz

tar czf example.tar.fz target

02/20/2019

When untar multiple files, you cannot do this, it will fail

tar zxf file1 file2 file3

The reason please see this link, the solution is to use xargs instead:

ls *.tar.gz | xargs -i tar xzf {}

Or you can use find with -exec

find . -maxdepth 1 -name "*.tar.gz" -exec tar zxf '{}' \;

02/21/2019

For example, if you want to tar things inside a folder but exclude some files

tar czf target.tar.gz ./* --exclude='createInstallerTar.sh' --exclude="target.tar.gz" --exclude='pushBIPayload.sh'

If you don’t exclude target.tar.gz, it will tar itself.

02/22/2019

list tar.gz file content, flag z sued to distinguish tar or tar.gz

tar ztvf target.tar.gz

猜你喜欢

转载自www.cnblogs.com/chengdol/p/10434924.html
tar