我想寫一個腳本,需要一個文件名作爲參數,然後壓縮和解壓縮每個程序的文件,compress, gzip, bzip2
和zip
。在每個階段,它會記錄壓縮前後文件的大小。最後,它顯示一個列表,顯示壓縮程序,未壓縮大小,壓縮大小和壓縮比率(最多1位小數)。我希望通過壓縮來實現列表的排序,最高效的壓縮數據將顯示在頂部。任何意見或幫助將不勝感激。非常感謝。壓縮和解壓縮與每個「壓縮,gzip,bzip2和zip」文件
0
A
回答
3
#!/bin/bash
file="$1"
# Original file size
orig_size=$(stat -c'%s' $file)
# Get sizes
gzip_size=$(gzip -c "$file" | wc -c)
# Repeat for other compression types...
# Get ratios
gzip_ratio=$(echo "scale=1; 100 * ($orig_size - $gzip_size)/$orig_size" | bc)
# Repeat for others...
# Unsorted output
echo "gzip $orig_size $gzip_size $gzip_ratio" >> unsorted.txt
# Repeat for others...
# Create sorted list
sort -n -r +3 -4 unsorted.txt > sorted.txt
cat sorted.txt # Print sorted list
+2
我認爲'orig_size'不應該指向'$ {file} .gz',而只能指向'$ {file}'。 – Danosaure 2010-11-17 13:08:26
+0
@Danosaure:非常感謝!固定。 – 2010-11-17 13:38:31
+2
以獲得gzip的大小,我只是寫'gzip_size = $(gzip -c「$ file」| wc -c)'而不是實際將「$ file.gz」寫入磁盤。 – 2010-11-17 14:55:03
相關問題
- 1. GZIP壓縮和解壓縮問題
- 2. 與django_compressor壓縮文件以gzip壓縮
- 3. Magick ++壓縮和解壓縮文件
- 4. 壓縮和解壓縮文件夾
- 5. png文件的壓縮和解壓縮
- 6. 解壓縮GZIP
- 7. Gzip解壓縮
- 8. 解壓縮zip
- 9. ASP.NET MVC WEB API Gzip壓縮 - 解壓縮
- 10. Python:將zip文件解壓縮並解壓縮.zip
- 11. gzip和webpack壓縮
- 12. 無法解壓縮使用BZip2壓縮的文件
- 13. 壓縮和解壓縮在PHP和JS
- 14. 解壓縮(解壓縮)由.net壓縮(解壓縮)的文件.net system.io.compression.gzipstream
- 15. BlackBerry - 解壓縮Zip文件
- 16. 解壓縮Zip文件
- 17. 解壓縮.zip文件
- 18. 解壓縮.zip文件
- 19. 解壓縮Zip文件3.6
- 20. 解壓縮GZIP流
- 21. Apache gzip解壓縮
- 22. 解壓縮和解壓縮建議?
- 23. Gzip壓縮與MockRestServiceServer
- 24. Protobuf與GZIP壓縮
- 25. 壓縮和解壓縮文件和文件夾
- 26. 解壓gzip壓縮iOS上的文件(使用Objective-Zip或SSZipArchive)
- 27. .NET使用壓縮和非壓縮數據壓縮文件
- 28. Java LZW壓縮和解壓縮圖像
- 29. 壓縮和解壓字符串減縮
- 30. Java壓縮和解壓縮byte []塊
爲什麼?這必須是功課,對吧? – 2010-11-17 04:44:42
你卡在哪裏?你有什麼更具體的問題嗎? – 2010-11-17 04:45:55
將它分解成更小的步驟,您可以在shell提示符下執行以下操作:查找文件大小,壓縮文件,查找其壓縮大小,計算比率,然後將其放入腳本中。在壓縮gzip bzip2 zip中使用'for COMPRESSION;做...;完成「來處理壓縮程序,然後在相應的輸出列上放置一個管道進行排序。回到你不能做的那些問題的具體問題。 – 2010-11-17 07:12:32