linux建立檔案命令:tail命令建立自解壓tar檔案

來源:互聯網
上載者:User

本文列舉了linux建立檔案命令中的tail命令,教你巧用tail命令建立自解壓tar檔案。

Tail命令參數中有一個參數-n, --lines=N,可以直接輸出一個檔案中的最後N行。

利用此參數,結合tar命令可以在linux下建立類似windows下winrar的自解壓了。

# !/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 # 計算目標檔案的行數

echo "LINES=\`expr \$LINES - 4\`" >> $DESTFILE # 計算需要輸出的行,為總行數-4(4行執行指令碼)

echo "tail -n \$LINES \$0 | tar -xv " >> $DESTFILE # 輸出並釋放(可以結合-z/-j釋放壓縮檔)

echo "exit 0" >> $DESTFILE

chmod +x $DESTFILE

cat $1 >> $DESTFILE #添加tar檔案到檔案尾

以上是linux建立檔案命令中的tail命令的用法。

  1. linux建立檔案命令:建立一定大小檔案命令--dd
  2. Linux建立檔案命令的方法
  3. linux中的cron和linux at命令用法詳解

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.