[root@linux ~]# tar [-cxtzjvfpPN] 檔案與目錄 .... 選項: -c :建立一個打包檔案(create); -x :解開一個打包檔案; -t :查看 tarfile 內的檔案;(c/x/t 不可同時存在!) -z :同時用 gzip 壓縮; -j :同時用 bzip2 壓縮; -v :壓縮的過程中顯示檔案; -f :使用檔名,在 f 之後要立即接檔名! -p :保留檔案的原來屬性(屬性不會依據使用者而變) -P :保留絕對路徑; -N :比後面接的日期(yyyy/mm/dd)還要新的才會被打包; --exclude FILE:排除 FILE 。
[root@dywOffice tmp]# tar -cvf txt.tar txt
[root@dywOffice tmp]# tar -cvf /tmp/etc.tar /etc %*<== 僅打包,不壓縮*) [root@dywOffice tmp]# tar -zcvf /tmp/etc.tar.gz /etc %*<== 打包後,以 gzip 壓縮*) [root@dywOffice tmp]# tar -jcvf /tmp/etc.tar.bz2 /etc %*<== 打包後,以 bzip2 壓縮*)
[root@dywOffice tmp]# tar -ztvf /tmp/etc.tar.gz
[root@dywOffice tmp]# tar -zxvf /tmp/etc.tar.gz
[root@dywOffice tmp]# tar -zxvf /tmp/etc.tar.gz etc/passwd
[root@dywOffice tmp]# tar -zcvPf testdir.tar.gz /home/csie/testdir
[root@dywOffice tmp]# tar -zcvpf /tmp/etc.tar.gz /etc
[root@dywOffice tmp]# tar -N '2007/11/30' -zcvf home.tar.gz /home
[root@dywOffice tmp]# tar -zcvf home.tar.gz /home --exclude /home/csie/tmp
$ tar -cvf myapp-1.0.tar main.c 2.c 3.c *.h myapp.1 Makefile5 main.c 2.c 3.c a.h b.h c.h myapp.1 Makefile5 $
$ ls -l *.tar -rw-r--r-- 1 neil users 10240 2003-02-15 11:31 myapp-1.0.tar $
$ gzip myapp-1.0.tar $ ls -l *.gz -rw-r--r-- 1 neil users 1668 2003-02-15 11:31 myapp-1.0.tar.gz $
$ mv myapp-1.0.tar.gz myapp_v1.tgz $ mv myapp_v1.tgz myapp-1.0.tar.gz
$ gzip -d myapp-1.0.tar.gz $ tar -xvf myapp-1.0.tar main.c 2.c 3.c a.h b.h c.h myapp.1 Makefile5 $
$ tar -zcvf myapp_v1.tgz main.c 2.c 3.c *.h myapp.1 Makefile5 main.c 2.c 3.c a.h b.h c.h myapp.1 Makefile5 $
$ tar -zxvf myapp_v1.tgz main.c 2.c 3.c a.h b.h c.h myapp.1 Makefile5 $
all: myapp # Which compiler CC = gcc # Where are include files kept INCLUDE = . # Options for development CFLAGS = -g -Wall -ansi # Options for release # CFLAGS = -O -Wall -ansi # Local Libraries MYLIB = mylib.a myapp: main.o $(MYLIB) $(CC) -o myapp main.o $(MYLIB) $(MYLIB): $(MYLIB)(2.o) $(MYLIB)(3.o) main.o: main.c a.h 2.o: 2.c a.h b.h 3.o: 3.c b.h c.h clean: -rm main.o 2.o 3.o $(MYLIB) dist: myapp-1.0.tar.gz myapp-1.0.tar.gz: myapp myapp.1 -rm -rf myapp-1.0 mkdir myapp-1.0 cp *.c *.h *.1 Makefile myapp-1.0 tar -zcvf $@ myapp-1.0
$ make dist
$ ls myapp-1.0.tar.gz myapp-1.0.tar.gz
$ tar -zxvf tarballfile.tar.gz $ ./configure $ make clean $ make $ make install
/usr/bin %*<== 執行檔*) /usr/lib %*<== 函式庫*) /usr/share/applnk/ %*<== 程式選單連結檔*) /usr/share/apps/ %*<== 程式內容*) /usr/share/doc/ %*<== 程式文件*) /usr/share/icons/ %*<== 程式圖標*) /usr/share/locale/ %*<== 程式支援之語系*) /usr/share/services/ %*<== 程式支援之服務*)
/usr/local/bin /usr/local/lib /usr/local/share
/usr/local/kplayer/bin /usr/local/kplayer/lib /usr/local/kplayer/share/applnk /usr/local/kplayer/share/apps /usr/local/kplayer/share/doc /usr/local/kplayer/share/icons /usr/local/kplayer/share/locale /usr/local/kplayer/share/services
tar -zcvf $@ myapp-1.0
代表意義為何?