Get the App
SLTechnology News&Howtos  ›  Servers  › 

The linux tail command creates a self-extracting tar file

Shulou Source: shulou.com Published: 2022-06-01 18:01:40 10月27日 Update

This article mainly explains "linux tail command to create self-extracting tar file", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn the "linux tail command to create self-extracting tar file" bar!

The Tail command parameter has a parameter-n,-- lines=N, which can directly output the * * N lines in a file.

With this parameter, combined with the tar command, you can create a self-decompression similar to winrar under windows under linux.

#! / bin/sh

[$#! = "1"] & & echo "Usage: $0 tarfile" & & exit 0

DESTFILE= "$1.sh"

Echo "#! / bin/sh" > $DESTFILE

Echo "LINES=\ `wc-l\ $0 | awk'{print\ $1}'\ `" > > $DESTFILE # calculate the number of lines in the target file

Echo "LINES=\ `expr\ $LINES-4\ `" > $DESTFILE # calculates the lines that need to be output, which is the total number of lines-4 (4 lines execute script)

Echo "tail-n\ $LINES\ $0 | tar-xv" > > $DESTFILE # output and release (you can release the compressed file in combination with-zmermerj)

Echo "exit 0" > > $DESTFILE

Chmod + x $DESTFILE

Cat $1 > > $DESTFILE # add the tar file to the end of the file

At this point, I believe you have a deeper understanding of the "linux tail command to create self-extracting tar files". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Files commands parameters output content learning practicality deeper interest practicality head office simple operation method more friends goals websites scripts channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Redmi Huawei NVidia Shulou Information