tar 多不同路徑檔,並移除絕對路徑 - Linux

By Heather
at 2017-12-08T16:05
at 2017-12-08T16:05
Table of Contents
Linux 板的棒油大家好。
在寫 script 中,取得了想要處理的檔案清單:
./01.txt
/tmp/02.txt
/home/user/03.txt
...
想要將其打包壓成 tar 檔,
不過若是直接下指令如下的話:
tar -zcvf test.tar.gz ./01.txt /tmp/02.txt /home/user/03.txt
則保存的資料夾路徑也會一起被 copy(根路徑被移除)
tar -ztvf test.tar.gz
01.txt
tmp/02.txt
home/user/03.txt
--
而希望的是能得到的結果為:
tar -ztvf test.tar.gz
01.txt
02.txt
03.txt
備分的原始 tar 完後,將之移除。
--
查網路上,多是在同一資料夾下處理,
則會用 tar 的 -C 參數切到該路徑做事。
而以此 需求來說,因要處理的檔案是散在多個不同路徑下,看來是不適用此法。
--
有想到幾個較為迂迴的做法:
做法-1:
再 parse 每個 檔案名,切出其 檔案路徑 及 檔案。
再一個個用 tar -C 去 add 每個檔案到 test.tar.gz 中。
做法-2:
把所有檔案先 copy 到一個 temp 資料夾下,tar 完後再把 temp 資料夾移除。
做法簡單,不過如果處理的檔案是好幾 GB 的話,感覺效能會非常差…
--
不過感覺應該是個會有很多人都會遇到,會有需要的功能,
所以想上來請教,是否有好方法能夠做到呢?
感激不盡~~
--
Tags:
Linux
All Comments

By Susan
at 2017-12-12T04:08
at 2017-12-12T04:08

By Margaret
at 2017-12-16T12:45
at 2017-12-16T12:45

By Robert
at 2017-12-20T16:54
at 2017-12-20T16:54

By Valerie
at 2017-12-25T03:05
at 2017-12-25T03:05

By Suhail Hany
at 2017-12-26T06:05
at 2017-12-26T06:05

By Linda
at 2017-12-29T06:59
at 2017-12-29T06:59

By Eden
at 2017-12-31T18:25
at 2017-12-31T18:25

By Ophelia
at 2018-01-02T21:02
at 2018-01-02T21:02

By Mia
at 2018-01-03T22:09
at 2018-01-03T22:09

By Mary
at 2018-01-05T21:07
at 2018-01-05T21:07

By Victoria
at 2018-01-10T13:27
at 2018-01-10T13:27
Related Posts
spyder安裝 遇到lzh_tw 問題

By Lily
at 2017-12-07T15:26
at 2017-12-07T15:26
freeNX server 新增用戶無法登入~~~

By Agatha
at 2017-12-07T06:43
at 2017-12-07T06:43
Microcode 可以降級嗎?

By Dinah
at 2017-12-06T12:57
at 2017-12-06T12:57
postfix限制使用者流量

By Rosalind
at 2017-12-05T21:28
at 2017-12-05T21:28
安裝14.04時發生的問題

By Audriana
at 2017-12-05T16:10
at 2017-12-05T16:10