在Linux上编辑远程文件的快速方法是什么? [英] What is a quick way to edit a remote file on Linux?

查看:156
本文介绍了在Linux上编辑远程文件的快速方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个定期编辑的远程文件.我想用一个可能通过SSH起作用的快速,简单的命令对其进行编辑.目前,我的工作流程是通过SSH连接到远程计算机,使用编辑器(例如vim或nano)打开文件,进行编辑,保存然后关闭连接.

I have a remote file that I edit regularly. I would like to edit it with a quick, simple command that would work likely via SSH. At present, my workflow is to connect to the remote computer via SSH, open the file using an editor (say vim or nano), edit, save and then close the connection.

我知道我可以使用SSHFS或Nautilus功能挂载远程计算机文件系统,但是我实际上是在寻找一个在终端中运行的命令,该命令将在编辑器中打开文件,让我保存然后保存.退出,关闭与远程计算机的所有连接.

I am aware that I can mount the remote computer filesystem using SSHFS or Nautilus capabilities, but I'm really looking for a single command to run in the terminal which shall open the file in an editor, allow me to save and then exit, closing all connections to the remote computer.

当前,我正在尝试通过SSH将命令传递给远程计算机来执行此操作,但是我遇到了麻烦.对于VIM,该命令类似于以下内容:

Currently, I am trying to do this by passing a command to the remote computer via SSH, but I am running into difficulties. For VIM, the command is something like the following:

ssh user1@computer1 "vim /path/laboratory_notebook_1.md"

使用此过程,VIM无法正确运行,并出现以下错误:

Using this procedure, VIM does not run correctly and presents the following error:

Vim: Warning: Output is not to a terminal
Vim: Warning: Input is not from a terminal

对于nano,命令类似于以下内容:

For nano, the command is something like the following:

ssh user1@computer1 "nano /path/laboratory_notebook_1.md"

使用此过程,nano无法运行,并出现以下错误:

Using this procedure, nano does not run and the following error is presented:

Error opening terminal: unknown.

我不确定如何按照这种思路进行.对于这种方法的帮助,以及通过最少的交互即可快速编辑远程文件的其他方法,我将不胜感激.

I'm not sure how to proceed on this line of thought. I would appreciate assistance on this method and suggestions on other ways to edit remote files briskly with a minimum amount of interaction.

推荐答案

强制伪TTY分配

您可以使用一个或多个-t标志强制伪伪分配. SSH(1)手册页显示:

Force Pseudo-TTY Allocation

You can force pseudo-tty allocation with one or more -t flags. The SSH(1) man page says:

 -t      Force pseudo-tty allocation.  This can be used to execute arbi-
         trary screen-based programs on a remote machine, which can be
         very useful, e.g. when implementing menu services.  Multiple -t
         options force tty allocation, even if ssh has no local tty.

示例

使用您自己的示例(稍作修改),如果您具有本地TTY或PTY,则可以使用以下示例:

Example

Using your own example, slightly modified, the following would work if you have a local TTY or PTY:

ssh -t user1@computer1 'vim /path/laboratory_notebook_1.md'

对于我来说,使用OpenSSH_6.2p2可以正常工作.您的里程(和操作环境)可能会有所不同.

It works fine for me with OpenSSH_6.2p2. Your mileage (and operating environment) may vary.

这篇关于在Linux上编辑远程文件的快速方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆