转载一片Mac电脑iterm2配置rz、sz命令超级实用

本文介绍了如何在Mac的iTerm2中配置rz和sz命令,包括安装lrzsz,设置文件权限,创建软链接,以及在iTerm2的触发器中配置这两个命令,实现文件的上传和下载功能。

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

rz 、sz 是什么意思?

  1. rz 即 recv-zmodem,receive zmodem 接收协议(对服务器),对本机表现为上传。
  2. sz 即 send-zmodem,send zmodem 发送协议(对服务器),对本机表现为下载。
  3. zmodem是一种传输协议(属于SecureCRT),该协议只能可靠地传输大小不超过4GB的文件

核心文件

iterm2-recv-zmodem.sh

#!/bin/bash
# Author: Matt Mastracci (matthew@mastracci.com)
# AppleScript from http://stackoverflow.com/questions/4309087/cancel-button-on-osascript-in-a-bash-script
# licensed under cc-wiki with attribution required 
# Remainder of script public domain

osascript -e 'tell application "iTerm2" to version' > /dev/null 2>&1 && NAME=iTerm2 || NAME=iTerm
if [[ $NAME = "iTerm" ]]; then
    FILE=`osascript -e 'tell application "iTerm" to activate' -e 'tell application "iTerm" to set thefile to choose folder with prompt "Choose a folder to place received files in"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")"`
else
    FILE=`osascript -e 'tell application "iTerm2" to activate' -e 'tell application "iTerm2" to set thefile to choose folder with prompt "Choose a folder to place received files in"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")"`
fi

if [[ $FILE = "" ]]; then
    echo Cancelled.
    # Send ZModem cancel
    echo -e \\x18\\x18\\x18\\x18\\x18
    sleep 1
    echo
    echo \# Cancelled transfer
else
    cd "$FILE"
    /usr/local/bin/rz -E -e -b
    sleep 1
    echo
    echo
    echo \# Sent \-\> $FILE
fi

iterm2-send-zmodem.sh

#!/bin/bash
# Author: Matt Mastracci (matthew@mastracci.com)
# AppleScript from http://stackoverflow.com/questions/4309087/cancel-button-on-osascript-in-a-bash-script
# licensed under cc-wiki with attribution required 
# Remainder of script public domain

osascript -e 'tell application "iTerm2" to version' > /dev/null 2>&1 && NAME=iTerm2 || NAME=iTerm
if [[ $NAME = "iTerm" ]]; then
    FILE=`osascript -e 'tell application "iTerm" to activate' -e 'tell application "iTerm" to set thefile to choose file with prompt "Choose a file to send"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")"`
else
    FILE=`osascript -e 'tell application "iTerm2" to activate' -e 'tell application "iTerm2" to set thefile to choose file with prompt "Choose a file to send"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")"`
fi
if [[ $FILE = "" ]]; then
    echo Cancelled.
    # Send ZModem cancel
    echo -e \\x18\\x18\\x18\\x18\\x18
    sleep 1
    echo
    echo \# Cancelled transfer
else
    /usr/local/bin/sz "$FILE" -e -b
    sleep 1
    echo
    echo \# Received $FILE
fi 

文件存放地址: /usr/local/bin/

开始配置

第一步:安装lrzsz
打开iTerm2 ,输入 brew install lrzsz 安装 lrzsz

第二步:放置文件
打开Finder后,按键command + shift + g 打开快速前往,输入/usr/local/bin进入该文件夹下。
将刚才的两个文件放入该文件夹,需要输入密码输入登录密码即可。

第三步:配置文件权限
打开iTerm2 ,输入 cd /usr/local/bin 进入该目录。再输入chmod 777 iterm2-* 调整文件权限为777。

第四步:软连接执行文件(关键)
新版的brew路径和老版本不同,上面两个文件写死了路径,所以这里使用软连接将文件指向进行调整。
在iTerm2 中输入以下指令:
sudo ln -s /opt/homebrew/bin/rz /usr/local/bin/rz
sudo ln -s /opt/homebrew/bin/sz /usr/local/bin/sz
参考链接
第五步:配置iterm2reference… -> Profiles -> Default -> Advanced -> Edit (in Triggers)
在这里插入图片描述
第六步:配置Edit中选项
在这里插入图片描述

关键配置步骤!!!

rz对应的选填项

1. Regular expression 中填写
rz waiting to receive.\*\*B0100

2. Action 选择
Run Silent Coprocess...

3. Parameters 中填写
/usr/local/bin/iterm2-send-zmodem.sh

4. Instant 不勾选

5. Enabled 勾选

sz对应的选填项

1. Regular expression 中填写
\*\*B00000000000000

2. Action 选择
Run Silent Coprocess...

3. Parameters 中填写
/usr/local/bin/iterm2-recv-zmodem.sh

4. Instant 不勾选

5. Enabled 勾选

配置完成如图:
在这里插入图片描述

配完试水,登录远程服务器输入命令rz。。。。超级好用~开心的不要不要滴
在这里插入图片描述

内容转载:
原文地址

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值