# tar -cf teacher.tar teacher/
# ls -l
total 228
-rwxr--r-- 1 root root 552 2012-04-09 15:50 down.sh
drwxr-xr-x 2 root root 4096 2012-04-09 15:50 teacher
-rw-r--r-- 1 root root 225280 2012-04-09 17:27 teacher.tar
$ tar -cf mybox.tar file1 file2 dir1 dir2 ..
# tar -rvf teacher.tar down.sh
down.sh
# tar -tvf teacher.tar
drwxr-xr-x root/root 0 2012-04-09 15:50 teacher/
-rw-r--r-- root/root 19368 2012-04-09 15:50 teacher/5715408995_1f13f5aa48_t.jpg
-rw-r--r-- root/root 6397 2012-04-09 15:50 teacher/4711140313_ee5d697b7a_t.jpg
-rw-r--r-- root/root 17546 2012-04-09 15:50 teacher/5167263404_3993b64eae_t.jpg
... ...
# tar -xf teacher.tar
# ls
down.sh teacher teacher.tar
# echo "hello world" > tmp1.txt
# echo "hello shell" > tmp2.txt
# echo "hello linux" > tmp3.txt
# ls
down.sh teacher teacher.tar tmp1.txt tmp2.txt tmp3.txt
# mkdir temp
# tar -cf - tmp1.txt tmp2.txt tmp3.txt | tar -xvf - -C ./temp
tmp1.txt
tmp2.txt
tmp3.txt
# ls -l temp/
total 12
-rw-r--r-- 1 root root 12 2012-04-09 17:54 tmp1.txt
-rw-r--r-- 1 root root 12 2012-04-09 17:54 tmp2.txt
-rw-r--r-- 1 root root 12 2012-04-09 17:54 tmp3.txt
# tar -cf tmp1.tar tmp1.txt
# tar -cf tmp2.tar tmp2.txt
# ls tmp*.tar
tmp1.tar tmp2.tar
# tar -Af tmp1.tar tmp2.tar
# tar -tf tmp1.tar
tmp1.txt
tmp2.txt
[/qutoe]
8. 使用 -u 选项根据时间戳更新压缩包里的文件
-u 选项可以根据时间戳来更新包里的文件,也就是说如果外头的文件比包里的文件(两个都是同名文件)的时间戳要来的新,那么就将外头的文件添加到包中,否则不添加:
[quote]# tar -tvf tmp1.tar
-rw-r--r-- root/root 10251 2012-04-09 18:26 tmp1.txt
# tar -uvf tmp1.tar tmp1.txt
# tar -tvf tmp1.tar
-rw-r--r-- root/root 10251 2012-04-09 18:26 tmp1.txt
-rw-r--r-- root/root 10251 2012-04-09 18:26 tmp1.txt
# touch tmp1.txt
# ls -l tmp1.txt
-rw-r--r-- 1 root root 10251 2012-04-09 18:35 tmp1.txt
# tar -uvf tmp1.tar tmp1.txt
tmp1.txt
# tar -tvf tmp1.tar
-rw-r--r-- root/root 10251 2012-04-09 18:26 tmp1.txt
-rw-r--r-- root/root 10251 2012-04-09 18:26 tmp1.txt
-rw-r--r-- root/root 10251 2012-04-09 18:35 tmp1.txt
# tar -cf tmp.tar tmp1.txt tmp2.txt
# tar -tf tmp.tar
tmp1.txt
tmp2.txt
# tar -f tmp.tar --delete tmp1.txt
# tar -tf tmp.tar
tmp2.txt
# tar -tf tmp.tar
tmp2.txt
# tar -df tmp.tar tmp2.txt
# echo "are you ok" >> tmp2.txt
# tar -df tmp.tar tmp2.txt
tmp2.txt: Mod time differs
tmp2.txt: Size differs
# tar -cjf tmp.tar.bz2 tmp1.txt
# tar --auto-compress -cf tmp.tar.gz tmp1.txt
# ls temp
andy.tar test2.sh test.sh tmp1.txt
# tar -cf temp.tar temp --exclude "*.txt"
# tar -tf temp.tar
temp/
temp/andy.tar
temp/test2.sh
temp/test.sh
tar --exclude-vcs -czvf sourcecode.tar my_svn_dir
# tar -cf temp.tar temp --exclude "*.txt" --totals
Total bytes written: 10240 (10KiB, 3.9MiB/s)
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |