PowerShell 不登录到窗口执行命令

有些时候,需要执行命令,又不想去登录到窗口。

1. 假设要登录服务器执行 touch a.txt 后就退出:

ssh root@192.168.1.20 "touch a.txt"

2.如果遇到文件名中有空格,需要双引号的,可以用\转义

ssh root@192.168.1.20 "touch \"a b.txt\""

3.如果想留在窗口,可以在后面加上 bash

ssh root@192.168.1.20 "touch a.txt";bash

注意,进入 bash 后没有提示用户名和路径,直接输入命令就可以执行




参考、来源:
https://learn.microsoft.com/zh-cn/windows/terminal/tutorials/ssh
https://learn.microsoft.com/zh-cn/windows/terminal/install#settings-json-file
https://learn.microsoft.com/zh-cn/windows/terminal/command-line-arguments
https://stackoverflow.com/questions/626533/how-can-i-ssh-directly-to-a-particular-directory



posted @ 2023-11-02 14:26  悟透  阅读(51)  评论(0)    收藏  举报