Linux file creation command: tail command to create self-decompressed tar file

Source: Internet
Author: User
This article lists the tail commands in the linux file creation command to teach you how to use the tail command to create a self-decompressed tar file. The Tail command parameter has a parameter-n, -- linesN, which can be directly output by

This article lists the tail commands in the linux file creation command to teach you how to use the tail command to create a self-decompressed tar file.

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

Using this parameter and the tar command, you can create a windows-like winrar self-decompressed file in linux.

  1. #! /Bin/sh
  2. [$ #! = "1"] & echo "Usage: $0 tarfile" & exit 0
  3. DESTFILE = "$ 1.sh"
  4. Echo "#! /Bin/sh "> $ DESTFILE
  5. Echo "LINES = 'WC-l $0 | awk '{print $1}'' "> $ DESTFILE # calculate the number of rows of the target file
  6. Echo "LINES = 'expr $ LINES-4 '"> $ DESTFILE # Calculate the row to be output, which is the total number of rows-4 (4 rows run the script)
  7. Echo "tail-n $ LINES $0 | tar-xv" >>$ DESTFILE # output and release (compressed files can be released in combination with-z/-j)
  8. Echo "exit 0" >>$ DESTFILE
  9. Chmod + x $ DESTFILE
  10. Cat $1 >>$ DESTFILE # add the tar file to the end of the file

The above is the usage of the tail command in the linux file creation command.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.