我知道可以通过“touch”命令在ssh中创建文件,然后使用vi或pico之类的文本编辑器对其进行编辑并添加内容。
我想知道是否可以创建一个文件并将其内容添加到一个命令行中?
就像是:[create file command] [filename.txt] ["this is the contents of filename.txt"]
我问这是否可能的原因是因为我有一个ssh client in Go,其中 session 仅接受一个调用来运行,并且我打算将其用于没有用户输入的自动化应用程序,因此我想避免使用文本编辑器。
最佳答案
这是一种解决方案:
ssh [user@]hostname 'echo "this is the contents of filename.txt" > <path/filename>'
带“>”的回显将覆盖现有文件,或者如果不存在则创建一个新文件。
将“>”替换为“>>”,以将文本附加到现有文件中。
干杯
关于ssh - 在没有文本编辑器的情况下通过ssh创建具有内容的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19063163/