Skip to content
WONGCW 網誌
  • 首頁
  • 論壇
  • 微博
  • 壁紙下載
  • 免費圖床
  • 視頻下載
  • 聊天室
  • SEO工具
  • 支援中心
  • 表格製作
  • More
    • 在線名片
    • 網頁搜索
    • 天氣預報
    • 二維碼生成器
    • WordPress 插件及主題下載
  • Search Icon

WONGCW 網誌

記錄生活經驗與點滴

The Linux ‘unzip’ Command

The Linux ‘unzip’ Command

2018-09-21 Comments 0 Comment

Zipping files is an easy, efficient way to transfer data between computers and servers. When files are compressed, they not only save disk space on a local drivebut also make it easier and more convenient to download files from the internet, using far less bandwidth than sending full-size files.

When you receive a zipped archive in Linux, decompressing it is just as easy. There are lots of switches available in Linux, which means that you have many ways to extract files with the unzip command in the command line.

Decompress Single ZIP Files

The basic syntax for decompressing a file is:

unzip filename

As an example, say you’ve zipped up an album named Menace to Sobriety. To unzip this file to the current folder, you’d simply run the following command:

Screenshot showing how to use the unzip command in Linux
unzip "Menace To Sobriety"

Decompress Multiple ZIP Files

The man command lets you decompress more than one file at a time using the following syntax:

unzip filename1 filename2 filename3

If you’ve zipped up three files of Alice Cooper albums named Trash, Hey Stoopid, and Dragontown, separately, you might try this to unzip them:

Screenshot of unzip errors in Ubuntu
unzip "Trash.zip" "Dragontown.zip" "Hey Stoopid.zip"

However, what you’d get is this error:

Archive: Trash.zip caution: filename not matched: Dragontown.zip

Assuming the three files live in the same folder, a better method is to use the following command:

Screenshot of the Ubuntu unzip command opening multiple ZIP files at once
unzip '*.zip'

Be careful, though. This command is indiscriminate and will decompress every ZIP file in the current folder.

Exclude Some ZIP Files

If you have a ZIP file and you want to extract all the files except for one, use the -xswitch.

unzip filename.zip -x filetoexclude.zip

To continue with our example, the album “Trash” in Trash.zip has an MP3 titled Bed Of Nails. To extract all the songs except for “Bed Of Nails,” you’d do this:

Screenshot showing how to unzip everything but one file from a ZIP archive in Ubuntu
unzip Trash.zip -x "Bed Of Nails.mp3"

Extract a ZIP File to a Different Directory

If you want to put the contents of the ZIP file in a different directory than the current one, use the -d switch.

unzip filename.zip -d path/to/extract/to

For example, to decompress the Trash.zip file to /home/music/Alice Cooper/Trash, you’d use the following syntax:

Screenshot showing how to use the unzip command to extract files to a different folder
unzip Trash.zip -d "/home/music/Alice Cooper/Trash"

How to Show the Contents of a Compressed Zip File

To list the contents of a compressed file, use the -l switch.

unzip -l filename.zip

In our example, we could use this switch to see all the files in Trash.zip.

Screenshot of the unzip command with the -l switch in Ubuntu
unzip -l Trash.zip

The information returned includes:

  • Length in bytes
  • Date created
  • Time created
  • Name

How to Test If a ZIP File Is Valid

To test whether a ZIP file is structured correctly and can be used properly before extracting it, use the -t switch.

unzip -t filename.zip

For example, to test whether Trash.zip is valid, you could run the following:

Screenshot showing how to use the -t switch in Ubuntu to test a ZIP file
unzip -t Trash.zip

Each file is listed, and OK should appear next to it. At the bottom of the output, a message should appear stating no errors detected in compressed data of….

See Detailed Information on a ZIP File

The -v switch (verbose) can give more detailed information.

unzip -v filename

To use this switch with Trash.zip to see more information, we’d type:

Screenshot showing how to use the -v switch in Ubuntu
unzip -v Trash.zip

The output contains the following information:

  • Length in bytes
  • Method
  • Size
  • Compression percentage
  • Date and time created
  • CRC
  • Name

Decompress a ZIP File Without Making Directories

For ZIP files that have folders, executing unzip alone, without switches, would re-create the same folder structure from the archive.

Extracting filename1.zip, for example, which has the following three folders, would result in the same folders being extracted:

  • Folder 1: filea.txt, fileb.txt, filec.txt
  • Folder 2: filed.txt, filee.txt
  • Folder 3: filef.txt

In this example, to extract all of the TXT files to the current folder without making those three folders, just append -j to the end of the command.

Screenshot showing how to use the -j switch with the unzip command in Ubuntu
unzip -j filename1.zip

Decompress a ZIP File Without Prompting to Overwrite

Suppose you’ve already unzipped a particular ZIP file and have started working on the unzipped files, changing and updating them however you wish. The last thing you want is to have those files overwritten when you extract a ZIP that has files with those same names. You’d immediately lose everything you were working on when the new files replace your existing ones.

However, you can use the -n switch if you want to not overwrite existing files. Every file from the ZIP archive that has a name matching a file in the extracted folder will not overwrite anything when this switch is used. Everything else, however, that has a unique name will still be extracted.

unzip -n filename.zip

If you don’t care whether the file already exists and you always want to overwrite the files as they are extracted without prompting, use the -o switch.

Screenshot of the -o switch used with the unzip command in Ubuntu
unzip -o filename.zip

Extract Password-Protected ZIP Files

If you need to unzip a file that requires a password for access, use the -p switch followed by the password.

unzip -P password filename.zip

For example, to unzip a file called cats.zip with the password kittens123, use the following:

Screenshot of the unzip command used with the -p switch in Ubuntu
unzip -P kittens123 filename.zip

Unzip a File Without Displaying Any Output

By default, the unzip command lists everything it’s doing, including showing every file in the archive as the command is extracting them. You can suppress this output by using the -q switch.

Screenshot of the -q switch used with the unzip command in Ubuntu
unzip -q filename.zip

This unzips the filename without providing any output and returns you to the cursor when it has finished.

分享此文:

  • 分享到 Twitter(在新視窗中開啟)
  • 按一下以分享至 Facebook(在新視窗中開啟)
  • 分享到 WhatsApp(在新視窗中開啟)
  • 按一下以分享到 Telegram(在新視窗中開啟)
  • 分享到 Pinterest(在新視窗中開啟)
  • 分享到 Reddit(在新視窗中開啟)
  • 按一下即可分享至 Skype(在新視窗中開啟)
  • 按一下即可以電子郵件傳送連結給朋友(在新視窗中開啟)
  • 點這裡列印(在新視窗中開啟)

相關


Linux資訊

Post navigation

PREVIOUS
Windows 10 2018 年 10 月更新 (RS5) 準正式版 Build 17763 發佈 + 繁體中文版下載
NEXT
EwoMail 开源企业邮件系统 的docker镜像

發表迴響 取消回覆

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料。

More results...

Generic filters
Exact matches only
Search in title
Search in content
Search in excerpt
Filter by 分類
網站公告
Featured
限時免費
ESET NOD32
WINDOWS 10 &11 INSIDER PREVIEW
Windows 軟件下載
系統軟件
辦公軟件
圖像處理
影音媒體
網絡軟件
應用軟件
Mac 軟件下載
安卓軟件下載
網絡資訊
Mac資訊
Linux資訊
VPS資訊
NASA資訊
金融資訊
WhatsApp Stickers教學
WordPress資訊
WeChat資訊
PHP資訊
Plesk資訊
TensorFlow
教學資源
開源程序
網頁工具
SEO工具
醫療健康
旅遊及消閒
其他資訊
Content from
Content to
2018 年 9 月
一 二 三 四 五 六 日
 12
3456789
10111213141516
17181920212223
24252627282930
« 8 月   10 月 »

分類

  • 網站公告
  • 限時免費
  • ESET NOD32
  • WINDOWS 10 &11 INSIDER PREVIEW
  • Windows 軟件下載
  • 系統軟件
  • 辦公軟件
  • 圖像處理
  • 影音媒體
  • 網絡軟件
  • 應用軟件
  • Mac 軟件下載
  • 安卓軟件下載
  • 網絡資訊
  • Mac資訊
  • Linux資訊
  • VPS資訊
  • NASA資訊
  • WhatsApp Stickers教學
  • WordPress資訊
  • WeChat資訊
  • PHP資訊
  • Plesk資訊
  • TensorFlow
  • 教學資源
  • 開源程序
  • 網頁工具
  • SEO工具
  • 醫療健康
  • 旅遊及消閒
  • 其他資訊

彙整

近期文章

  • 保姆級教程12306官方詳解如何用積分“免費坐高鐵” 2023-03-31
  • 挖礦毫無意義NVIDIA解釋為何賣礦卡:客戶願意花錢我們管不著 2023-03-31
  • 吃日料、聽京劇庫克時隔3年再訪中國 2023-03-31
  • 華為淨現金下滑至1763億元孟晚舟稱財務狀況依然穩健 2023-03-31
  • 任天堂Switch 2不會遠了開發者已收到新主機開發工具 2023-03-31
  • NASA太陽動力學觀測站捕捉到從太陽爆發的強烈耀斑 2023-03-31
  • 科學家發現製造原子級薄金屬層的簡單方法 2023-03-31
  • 華為發布2022年年度報告孟晚舟現場談壓力和信心 2023-03-31
  • 不要錯過:NASA將於4月3日揭曉Artemis II登月宇航員 2023-03-31
  • 新藥可”二合一”治療心力衰竭和睡眠呼吸障礙 2023-03-31

熱門文章與頁面︰

  • DP vs HDMI 誰才是遊戲玩家最佳選擇?
  • Autodesk AutoCAD 2021 正式版註冊版-簡體/繁體中文/英文版
  • ESET NOD32 LICENSE KEY (UPDATED 2023-01-17)
  • 打車叫到特斯拉不會開門很尷尬?官方介紹開關門方法
  • Explorer Patcher:讓Windows 11恢復Windows 10的行為特徵
  • 盜版Windows 7還能免費升級Windows 10嗎?
  • 世界上有多少個國家
  • 38歲985文科碩士被迫送外賣本人再發聲:已脫下孔乙己長衫應聘道士被拒
  • NVIDIA H100 Hopper加速計算卡上市:配備80GB顯存價格超24萬元
  • 讓WIN10去強制縮放那些不支援DPI縮放的軟體或遊戲

投遞稿件

歡迎各界人士投遞稿件到admin@wongcw.com

請提供以下資料:

1.你的名字

2.你的電郵

3.分類目錄

4.文章標題

5.文章摘要

6.文章內容

7.文章來源

 

聯繫我們

查詢,投稿,商務合作:
​admin@wongcw.com
​技術支援:
​support@wongcw.com
​客户服務:
​cs@wongcw.com

QQ群:833641851

快帆

MALUS

極度掃描

DMCA.com Protection Status

WONGCW 網誌

  • 免責聲明
  • 捐助我們
  • ThemeNcode PDF Viewer
  • ThemeNcode PDF Viewer SC
  • Events

服務器提供

本站使用之服務器由ikoula提供。

聯繫我們

查詢,投稿,商務合作:
​admin@wongcw.com
​技術支援:
​support@wongcw.com
​客户服務:
​cs@wongcw.com

QQ群:833641851

© 2023   All Rights Reserved.