Mac 解压 rar包 Apple OS X: Open .Rar File / Extract rar

本文介绍了如何在Apple OS X操作系统中安装并使用unrar命令行工具来处理RAR格式的压缩文件,包括提取、列出文件内容、测试文件完整性等操作,并推荐了一款免费的GUI应用程序The Unarchiver。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The unrar command or gui tools are not supported out of the box. Use the following instructions install the same:

 

unrar Command Line Tool

You need to download unrar by visiting this page and look for OS X version. Alternativly, you can open the terminal and type the following command to download the same:

cd /tmp
curl -o output.tar.gz http://www.rarlab.com/rar/rarosx-3.9.3.tar.gz

 

Untar the tar ball, enter:

tar -zxvf output.tar.gz

 

Sample outputs:

Fig.01: Unrar Installation - OS X .Rar Extractor

Fig.01: Unrar Installation - OS X .Rar Extractor


You need to copy rar and unrar command to /bin directory, type the following commands:

sudo cp -v /tmp/rar/{rar,unrar} /bin
rm -rf /tmp/rar

 

Sample outputs:

Fig.02: Copying files to /bin under OS X

Fig.02: Copying files to /bin under OS X

 

How Do I Use Unrar Command Line?

You can use the unrar command as follows:

 

Task: Extract Files

The syntax is as follows to open or unrar file in current directory:  

unrar e file.rar
ls -l

 

Task: List (l) File Inside Rar Archive  
unrar l file.rar

 

Task: To Extract (x) Files With Full Path  
unrar x file.rar

 

Task: To Test (t) Integrity Of Archive  
unrar t file.rar

 

To see all support command line options type:

unrar | less

 

GUI App: The Unarchiver

You can use "The Unarchiver" is free software and it is a much more capable replacement for "BOMArchiveHelper.app", the built-in archive unpacker program in Mac OS X. The Unarchiver is designed to handle many more formats than BOMArchiveHelper, and to better fit in with the design of the Finder. Supported file formats include Zip, Tar-GZip, Tar-BZip2, RAR, 7-zip, LhA, StuffIt and many other more and less obscure formats. The goal is to make The Unarchiver able to extract anything you give it.
=> Download The Unarchiver

 

来源:http://www.cyberciti.biz/faq/unrar-apple-os-x-command-line-gui-tools/

 

 

 

import os import requests from urllib.parse import urljoin from bs4 import BeautifulSoup import logging from pathlib import Path # 配置日志记录 logging.basicConfig( level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s' ) def get_page_content(url): """获取网页内容""" headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36' } try: response = requests.get(url, headers=headers, timeout=10) response.raise_for_status() response.encoding = response.apparent_encoding return response.text except requests.exceptions.RequestException as e: logging.error(f"请求失败: {e}") return None def extract_file_links(html, base_url): """提取文件下载链接""" soup = BeautifulSoup(html, 'html.parser') file_links = [] # 查找所有含文件扩展名的链接 for link in soup.find_all('a', href=True): href = link['href'] if any(href.lower().endswith(ext) for ext in ('.pdf', '.doc', '.docx', '.xls', '.xlsx', '.zip', '.rar')): absolute_url = urljoin(base_url, href) file_links.append((absolute_url, link.text.strip())) return file_links def download_file(url, save_dir): """下载单个文件""" try: response = requests.get(url, stream=True, timeout=15) response.raise_for_status() # 从URL获取文件名 filename = os.path.basename(url.split('?')[0]) # 去除URL参数 if not filename: filename = f"file_{hash(url)}" # 创建保存目录 Path(save_dir).mkdir(parents=True, exist_ok=True) # 保存文件 file_path = os.path.join(save_dir, filename) with open(file_path, 'wb') as f: for chunk in response.iter_content(chunk_size=8192): if chunk: f.write(chunk) logging.info(f"成功下载: {filename}") return True except Exception as e: logging.error(f"下载失败 {url}: {str(e)}") return False def main(): target_url = "http://www.nhc.gov.cn/lljks/zcwj2/new_list.shtml" save_directory = "./downloaded_files" # 获取页面内容 html_content = get_page_content(target_url) if not html_content: return # 提取文件链接 file_links = extract_file_links(html_content, target_url) if not file_links: logging.warning("未找到可下载文件") return # 下载所有文件 success_count = 0 for url, name in file_links: if download_file(url, save_directory): success_count += 1 logging.info(f"下载完成,成功{success_count}/{len(file_links)}个文件") if __name__ == "__main__": main()
03-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值