zoukankan      html  css  js  c++  java
  • (转)Mac osx 下安装iTerm2,并使用rz sz上传下载(附homebrew配置)

    从window上转换到Mac还是有一些不习惯的地方,今天就一直在弄这个远程服务器的操作的软件,先是费了好大劲下载了SecureCRT,又是破解弄了半天发现上传下载用不了,很是伤心。
    一直想找一个类似xShell的软件,我放弃了,最后定为到iTerm配合rz和sz来实现上传下载。
    先说一下为什么写这个文章,因为在网络上真的是看了好多的文章,良莠不齐,有的好使,有的根本就是*,所以打算记录一篇文章,不能说很好,但是是我亲测可行的,所以记录下来,希望给同行人一些帮助。

    环境

    • Mac ox 10.12.3
    • iTerm2-3_1_5

    安装iTerm2

    安装方式和苹果的安装方式是一样的,解压双击 把他拖进application中就可以了。

    安装rz sz

    吐槽一下 好多的博客写的是很简单,一个命令 brew install lrzsz。。。可是也许有很多人没有brew这个命令 比如我 总是not found command,伤心。。

    安装rz sz 前的准备 安装brew

    简单介绍一下,一般我们在unix或者类unix的linux系统上,使用yum或者apt-get,不过抱歉,在mac osx上好像不好使,所以几经周折找到homebrew简称brew,它的功能就类似yum或者apt-get。它是max osx上的软件包管理工具。

    • 安装homebrew 只需要下面一条语句即可
    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    

    注意: 我在安装过程中看了很多博客,也尝试过很多链接,甚至打算FQ来着,不过上面这条语句我一次执行就通过了(没FQ),并看到了成功的标记 successful。

    注意 在安装过会有一次卡顿,建入回车 接着我们会看到让我们输入密码,输入密码后等待安装就可以了。

    好了,安装成功后输入 brew 查看是否有提示信息

    harryliangdeMacBook-Pro:~ harryliang$ brew
    Example usage:
      brew search [TEXT|/REGEX/]
      brew (info|home|options) [FORMULA...]
      brew install FORMULA...
      brew update
      brew upgrade [FORMULA...]
      brew uninstall FORMULA...
      brew list [FORMULA...]
    
    Troubleshooting:
      brew config
      brew doctor
      brew install -vd FORMULA
    
    Developers:
      brew create [URL [--no-fetch]]
      brew edit [FORMULA...]
      https://docs.brew.sh/Formula-Cookbook.html
    
    Further help:
      man brew
      brew help [COMMAND]
      brew home
      
      

    如果看到如上信息,则表示brew安装成功了。

    安装lrzsz

    • 这里安装才可以说简单了,使用如下命令即可
    brew install lrzsz  
    

    配置rz sz 进行上传下载

    要想使用rz 和sz进行上传下载我们要尽兴一些配置

    • 进入到/usr/local/bin 目录下
    cd /usr/local/bin
    
    
    
    • 这个目录下需要两个配置文件,这个配置文件可以自己粘贴,也可以去github网站下载。

      1. github网址: https://github.com/mmastrac/i...
      2. 如果不会下载就在github上打开文件 自己创建两个文件 并把内容粘贴进去
    • 这里把我的配置过程和配置文件内容粘贴出来给大家,方便大家操作。
    1. 在/usr/loal/bin 目录下创建两个文件

    图片描述

    命令:

    
    vi iterm2-recv-zmodem.sh
    vi iterm2-send-zmodem.sh
    

    创建好两个文件后分别添加内容:

    1. 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
    
    
    1. 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 
    
    
    1. 将文件写好后保存好,使用如下命令添加权限

      chmod +777 iterm2-*

    • 配置好配置文件之后,开始对iTerm2进行配置

    iTerm2 配置添加rz sz 功能

    • 点击 iTerm2 的设置界面 Perference-> Profiles -> Default -> Advanced -> Triggers 的 Edit 按钮

    图片描述


    图片描述


    图片描述

    --- 在最后一个图片的位置进行配置,上图是配置好的样子,配置文件如下:

    Regular expression: rz waiting to receive.**B0100
    Action: Run Silent Coprocess
    Parameters: /usr/local/bin/iterm2-send-zmodem.sh
    
    Regular expression: **B00000000000000
    Action: Run Silent Coprocess
    Parameters: /usr/local/bin/iterm2-recv-zmodem.sh
    
    

    按照上面的配置文件信息的格式填写即可。

    ok!到此为止我们的rz sz安装配置就可以了,接着我们介绍一下rz 和 sz 的使用

    rz 上传功能

    • 在bash中,也就是iTerm2终端输入rz 就会弹出文件选择框,选择文件 choose 就开始上传,会上传到当前目录

    sz 下载功能

    • sz fileName(你要下载的文件的名字) 回车
    • 会弹出窗体 我们选择要保存的地方即可。

    小记

    最后呢本来还想写点更多的用法,无奈在写文档的时候非常卡,下次再说吧。
    这里呢想呼吁一下大家多些一些完整的博客,不要去直接复制粘贴转载。

  • 相关阅读:
    Enterprise Library3.1 使用数据访问模块时,调用Microsoft.Practices.EnterpriseLibrary.Data报出源文件与当前应用程序不一致和创建dataconfiguration的配置节处理程序出错
    net精华:C#中对注册表的操作
    [翻译]使用Enterprise Library 3.0的日志程序块
    分布式应用程序概述
    调整Oracle数据库print_bill表字段BillMKID的顺序,并判断表print_bill是否存在及字段billMKID是否存在
    Win32下注册COM组件后对注册表产生的变动
    vc 字符串与指针
    SQL Server不允许进行远程连接的解决办法
    vc上字符串,CString ,string,char数组&char指针
    如何用Visual C#来创建、修改注册信息
  • 原文地址:https://www.cnblogs.com/nanxiang/p/14717003.html
Copyright © 2011-2022 走看看