tar命令
本站整理 發(fā)布時(shí)間:2009-03-10 10:57:35 作者:jb51.net
我要評(píng)論

怎樣使用tar命令打包(備份)文件?
A:The syntax of tar is:
tar [options][files]
The options used most often with tar are as follows:
c Creates a new backup,overwriting any files already on the backup destination.
x Extracts files from backup media.
t Lists
怎樣使用tar命令打包(備份)文件?
A:The syntax of tar is:
tar [options][files]
The options used most often with tar are as follows:
c Creates a new backup,overwriting any files already on the backup destination.
x Extracts files from backup media.
t Lists the contents of backup media.
v Displays the name of each file being processed.
f Creates backups on a specified device.
u Adds files to the backup if they are not already there,or if they have been modified since they were last written on the backup.
步驟:
1)估算打包文件的大小,確定使用檔案媒體(archive media)的空間,用命令du -s
例如:
$ lf
a.out* fork.c mbox time.c
atoi.c int.c memcpy.c vi
$ du -s
296 .
$
該例顯示的296代表the total number of 512-byte blocks,計(jì)算:512*296/1024=148kilobytes.
2)制作備份,用命令tar cvf /dev/fd0135ds18 .(將該目錄下的所有內(nèi)容備份到1.44英寸軟盤中where c causes a new backup to be created,v causes each file to be displayed as the backing up takes place,and f causes the subsequent argument--/dev/fd0135ds18 to be the destination of the backup.)
注:平時(shí)硬盤上的備份,我們一般用命令tar cvf filename.tar .
例如:
$ tar cvf wuyd.tar .
a ./.profile 2 tape blocks
a ./.lastlogin 0 tape blocks
a ./mbox 10 tape blocks
a ./fork.c 2 tape blocks
a ./memcpy.c 1 tape blocks
a ./.sh_history 3 tape blocks
a ./a.out 91 tape blocks
a ./time.c 1 tape blocks
a ./vi 169 tape blocks
a ./int.c 1 tape blocks
a ./atoi.c 1 tape blocks
tar: same as archive file: ./wuyd.tar
a ./.scoadmin.pref 1 tape blocks
$ lf
a.out* fork.c mbox time.c wuyd.tar
atoi.c int.c memcpy.c vi
我們還可以用命令tar cvf /dev/fd0135ds18 ./filename將該目錄下的名為filename的文件備份到archive media中
怎樣列出tar文檔的內(nèi)容?
A:tar tvf /dev/fd0135ds18
tar tvf filename.tar
例如:
$ tar tvf wuyd.tar
tar: blocksize = 20
rw-------203/50 896 Sep 17 15:07 2003 ./.profile
r--------203/21 0 Sep 24 19:49 2003 ./.lastlogin
rw-------203/50 4720 Sep 21 11:17 2003 ./mbox
rw-r--r--203/50 583 Sep 17 15:27 2003 ./fork.c
rw-r--r--203/50 218 Sep 17 20:22 2003 ./memcpy.c
rw-------203/50 1474 Sep 24 20:26 2003 ./.sh_history
rwxr-xr-x203/50 46224 Sep 22 21:00 2003 ./a.out
rw-r--r--203/50 341 Sep 19 09:02 2003 ./time.c
rw-r--r--203/50 86283 Sep 21 09:14 2003 ./vi
rw-r--r--203/50 93 Sep 21 10:53 2003 ./int.c
rw-r--r--203/50 144 Sep 22 21:00 2003 ./atoi.c
rw-r--r-- 0/3 41 Sep 23 20:34 2003 ./.scoadmin.pref
$
怎樣從tar文檔中導(dǎo)出文件?
A:tar xvf /dev/fd0135ds18
tar xvf filename.tar
例如:
$ mkdir uu;cp wuyd.tar ./uu
$ lf
a.out* fork.c mbox time.c vi
atoi.c int.c memcpy.c uu/ wuyd.tar
$ cd uu
$ tar xvf wuyd.tar
tar: blocksize = 20
x ./.profile, 896 bytes, 2 tape blocks
x ./.lastlogin, 0 bytes, 0 tape blocks
x ./mbox, 4720 bytes, 10 tape blocks
x ./fork.c, 583 bytes, 2 tape blocks
x ./memcpy.c, 218 bytes, 1 tape blocks
x ./.sh_history, 1474 bytes, 3 tape blocks
x ./a.out, 46224 bytes, 91 tape blocks
x ./time.c, 341 bytes, 1 tape blocks
x ./vi, 86283 bytes, 169 tape blocks
x ./int.c, 93 bytes, 1 tape blocks
x ./atoi.c, 144 bytes, 1 tape blocks
x ./.scoadmin.pref, 41 bytes, 1 tape blocks
$
我們可用命令tar xvf /dev/fd0135ds18 ./filename導(dǎo)出archive media中的單個(gè)文件
例如:
$ lf
wuyd.tar
$ tar xvf wuyd.tar ./time.c
tar: blocksize = 20
x ./time.c, 341 bytes, 1 tape blocks
$ lf
time.c wuyd.tar
$
怎樣使用tar命令提供的簡(jiǎn)寫形式?
A:
$ more /etc/default/tar
# @(#) def135.src 25.2 94/07/25
#
# Copyright (C) 1987-1994 The Santa Cruz Operation, Inc.
# All Rights Reserved.
# The information in this file is provided for the exclusive use of
# the licensees of The Santa Cruz Operation, Inc. Such users have the
# right to use, modify, and incorporate this code into other products
# for purposes authorized by the license agreement provided they include
# this notice and the associated copyright notice with any such product.
# The information in this file is provided "AS IS" without warranty.
#
# default/tar - archive devices: tar(C)
#
# device block size tape
#
archive0=/dev/rfd048ds9 18 360 n
archive1=/dev/rfd148ds9 18 360 n
archive2=/dev/rfd096ds15 10 1200 n
archive3=/dev/rfd196ds15 10 1200 n
# archive4=/dev/rfd096ds9 18 720 n
archive4=/dev/rfd0135ds9 18 720 n
archive5=/dev/rfd1135ds9 18 720 n
# archive5=/dev/rfd196ds9 18 720 n
archive6=/dev/rfd0135ds18 18 1440 n
archive7=/dev/rfd1135ds18 18 1440 n
archive8=/dev/rct0 20 0 y
archive9=/dev/rctmini 20 0 y
archive10=/dev/rdsk/fp03d 18 720 n
archive11=/dev/rdsk/fp03h 18 1440 n
archive12=/dev/rdsk/fp03v21 10 20330 n
#
# The default device in the absence of a numeric or "-f device" argument
A:The syntax of tar is:
tar [options][files]
The options used most often with tar are as follows:
c Creates a new backup,overwriting any files already on the backup destination.
x Extracts files from backup media.
t Lists the contents of backup media.
v Displays the name of each file being processed.
f Creates backups on a specified device.
u Adds files to the backup if they are not already there,or if they have been modified since they were last written on the backup.
步驟:
1)估算打包文件的大小,確定使用檔案媒體(archive media)的空間,用命令du -s
例如:
$ lf
a.out* fork.c mbox time.c
atoi.c int.c memcpy.c vi
$ du -s
296 .
$
該例顯示的296代表the total number of 512-byte blocks,計(jì)算:512*296/1024=148kilobytes.
2)制作備份,用命令tar cvf /dev/fd0135ds18 .(將該目錄下的所有內(nèi)容備份到1.44英寸軟盤中where c causes a new backup to be created,v causes each file to be displayed as the backing up takes place,and f causes the subsequent argument--/dev/fd0135ds18 to be the destination of the backup.)
注:平時(shí)硬盤上的備份,我們一般用命令tar cvf filename.tar .
例如:
$ tar cvf wuyd.tar .
a ./.profile 2 tape blocks
a ./.lastlogin 0 tape blocks
a ./mbox 10 tape blocks
a ./fork.c 2 tape blocks
a ./memcpy.c 1 tape blocks
a ./.sh_history 3 tape blocks
a ./a.out 91 tape blocks
a ./time.c 1 tape blocks
a ./vi 169 tape blocks
a ./int.c 1 tape blocks
a ./atoi.c 1 tape blocks
tar: same as archive file: ./wuyd.tar
a ./.scoadmin.pref 1 tape blocks
$ lf
a.out* fork.c mbox time.c wuyd.tar
atoi.c int.c memcpy.c vi
我們還可以用命令tar cvf /dev/fd0135ds18 ./filename將該目錄下的名為filename的文件備份到archive media中
怎樣列出tar文檔的內(nèi)容?
A:tar tvf /dev/fd0135ds18
tar tvf filename.tar
例如:
$ tar tvf wuyd.tar
tar: blocksize = 20
rw-------203/50 896 Sep 17 15:07 2003 ./.profile
r--------203/21 0 Sep 24 19:49 2003 ./.lastlogin
rw-------203/50 4720 Sep 21 11:17 2003 ./mbox
rw-r--r--203/50 583 Sep 17 15:27 2003 ./fork.c
rw-r--r--203/50 218 Sep 17 20:22 2003 ./memcpy.c
rw-------203/50 1474 Sep 24 20:26 2003 ./.sh_history
rwxr-xr-x203/50 46224 Sep 22 21:00 2003 ./a.out
rw-r--r--203/50 341 Sep 19 09:02 2003 ./time.c
rw-r--r--203/50 86283 Sep 21 09:14 2003 ./vi
rw-r--r--203/50 93 Sep 21 10:53 2003 ./int.c
rw-r--r--203/50 144 Sep 22 21:00 2003 ./atoi.c
rw-r--r-- 0/3 41 Sep 23 20:34 2003 ./.scoadmin.pref
$
怎樣從tar文檔中導(dǎo)出文件?
A:tar xvf /dev/fd0135ds18
tar xvf filename.tar
例如:
$ mkdir uu;cp wuyd.tar ./uu
$ lf
a.out* fork.c mbox time.c vi
atoi.c int.c memcpy.c uu/ wuyd.tar
$ cd uu
$ tar xvf wuyd.tar
tar: blocksize = 20
x ./.profile, 896 bytes, 2 tape blocks
x ./.lastlogin, 0 bytes, 0 tape blocks
x ./mbox, 4720 bytes, 10 tape blocks
x ./fork.c, 583 bytes, 2 tape blocks
x ./memcpy.c, 218 bytes, 1 tape blocks
x ./.sh_history, 1474 bytes, 3 tape blocks
x ./a.out, 46224 bytes, 91 tape blocks
x ./time.c, 341 bytes, 1 tape blocks
x ./vi, 86283 bytes, 169 tape blocks
x ./int.c, 93 bytes, 1 tape blocks
x ./atoi.c, 144 bytes, 1 tape blocks
x ./.scoadmin.pref, 41 bytes, 1 tape blocks
$
我們可用命令tar xvf /dev/fd0135ds18 ./filename導(dǎo)出archive media中的單個(gè)文件
例如:
$ lf
wuyd.tar
$ tar xvf wuyd.tar ./time.c
tar: blocksize = 20
x ./time.c, 341 bytes, 1 tape blocks
$ lf
time.c wuyd.tar
$
怎樣使用tar命令提供的簡(jiǎn)寫形式?
A:
$ more /etc/default/tar
# @(#) def135.src 25.2 94/07/25
#
# Copyright (C) 1987-1994 The Santa Cruz Operation, Inc.
# All Rights Reserved.
# The information in this file is provided for the exclusive use of
# the licensees of The Santa Cruz Operation, Inc. Such users have the
# right to use, modify, and incorporate this code into other products
# for purposes authorized by the license agreement provided they include
# this notice and the associated copyright notice with any such product.
# The information in this file is provided "AS IS" without warranty.
#
# default/tar - archive devices: tar(C)
#
# device block size tape
#
archive0=/dev/rfd048ds9 18 360 n
archive1=/dev/rfd148ds9 18 360 n
archive2=/dev/rfd096ds15 10 1200 n
archive3=/dev/rfd196ds15 10 1200 n
# archive4=/dev/rfd096ds9 18 720 n
archive4=/dev/rfd0135ds9 18 720 n
archive5=/dev/rfd1135ds9 18 720 n
# archive5=/dev/rfd196ds9 18 720 n
archive6=/dev/rfd0135ds18 18 1440 n
archive7=/dev/rfd1135ds18 18 1440 n
archive8=/dev/rct0 20 0 y
archive9=/dev/rctmini 20 0 y
archive10=/dev/rdsk/fp03d 18 720 n
archive11=/dev/rdsk/fp03h 18 1440 n
archive12=/dev/rdsk/fp03v21 10 20330 n
#
# The default device in the absence of a numeric or "-f device" argument
相關(guān)文章
Fedora Linux 42 穩(wěn)定版發(fā)布: 帶來(lái)大量新功能和軟件更新
Fedora 42昨日發(fā)布,這是 Red Hat 贊助開(kāi)發(fā)的杰出前沿 Linux 發(fā)行版的最新版,包含大量新功能和軟件更新,使其成為 2025 年上半年發(fā)布的一款出色的 Linux 操作系統(tǒng)之一,內(nèi)2025-04-16如何在Linux查看硬盤信息? 查看Linux硬盤大小類型和硬件信息的5種方法
使用Linux系統(tǒng)的過(guò)程中,查看和了解硬盤信息是非常重要的工作,尤其是對(duì)于系統(tǒng)管理員而言,那么在Linux系統(tǒng)中如何查看硬盤信息?以下是具體內(nèi)容介紹2025-03-12如何在 Linux 中查看 CPU 詳細(xì)信息? 3招輕松查看CPU型號(hào)、核心數(shù)和溫度
在日常運(yùn)維工作中,獲取 CPU 信息是系統(tǒng)運(yùn)維管理員常見(jiàn)的工作內(nèi)容,無(wú)論是為了性能調(diào)優(yōu)、硬件升級(jí)還是僅僅滿足好奇心2025-03-11什么是 Arch Linux? 獨(dú)樹(shù)一幟的Arch Linux發(fā)行版分析
Arch Linux是為簡(jiǎn)化,優(yōu)化,現(xiàn)代化,實(shí)用主義,用戶中心和多功能性而創(chuàng)建Linux發(fā)行版,究竟是什么讓 Arch 與眾不同?下面我們就來(lái)簡(jiǎn)要解讀2025-02-19如何在Linux環(huán)境下制作 Win11裝機(jī)U盤?
一直用的linux辦公,想要將筆記本電腦從 Linux 系統(tǒng)切換回 Windows 11,我們可以制作一個(gè)win11裝機(jī)u盤,詳細(xì)如下2025-02-17Rsnapshot怎么用? 基于Rsync的強(qiáng)大Linux備份工具使用指南
Rsnapshot 不僅可以備份本地文件,還能通過(guò) SSH 備份遠(yuǎn)程文件,接下來(lái)詳細(xì)介紹如何安裝、配置和使用 Rsnapshot,包括創(chuàng)建每小時(shí)、每天、每周和每月的本地備份,以及如何進(jìn)2025-02-06Linux Kernel 6.13發(fā)布:附更新內(nèi)容及新特性解讀
Linux 內(nèi)核 6.13 正式發(fā)布,新版本引入了惰性搶占支持,簡(jiǎn)化內(nèi)核搶占邏輯,通過(guò)減少與調(diào)度器相關(guān)的調(diào)用次數(shù),讓內(nèi)核在運(yùn)行時(shí)表現(xiàn)更優(yōu),從而提高效率2025-01-23五大特性引領(lǐng)創(chuàng)新! 深度操作系統(tǒng) deepin 25 Preview預(yù)覽版發(fā)布
今日,深度操作系統(tǒng)正式推出deepin 25 Preview版本,該版本集成了五大核心特性:磐石系統(tǒng)、全新DDE、Treeland窗口合成器、AI For OS以及Distrobox子系統(tǒng)2025-01-18Linux Mint Xia 22.1重磅發(fā)布: 重要更新一覽
Beta 版 Linux Mint“Xia” 22.1 發(fā)布,新版本基于 Ubuntu 24.04,內(nèi)核版本為 Linux 6.8,這次更新帶來(lái)了諸多優(yōu)化和改進(jìn),進(jìn)一步鞏固了 Mint 在 Linux 桌面操作系統(tǒng)領(lǐng)域的2025-01-16LinuxMint怎么安裝? Linux Mint22下載安裝圖文教程
Linux Mint22發(fā)布以后,有很多新功能,很多朋友想要下載并安裝,該怎么操作呢?下面我們就來(lái)看看詳細(xì)安裝指南2025-01-16