【问题标题】:Single line create file with content单行创建包含内容的文件
【发布时间】:2023-03-25 14:55:01
【问题描述】:

操作系统是 Ubuntu。我想在/home/z/Desktop 中创建file.txt,其中文件的内容是some text here

第一种也是常用的方法是运行nano /home/z/Desktop/file.txt 并输入some text here。之后,按ctrl+x,按y,然后按Enter

第二种方式是运行cat > /home/z/Desktop/file.txt,输入some text here,然后按Enter,然后按ctrl+c

我希望我可以运行单行命令以使其更快。我认为xdotool 将与cat 一起使用(第二种方式),但不,它不起作用

【问题讨论】:

    标签: command-line cat nano


    【解决方案1】:

    您可以在 bash 中使用 "echo"。例如:

    echo "some text here" > file.txt
    

    如果您不想在文件末尾出现换行符,请使用 -n 参数:

    echo -n "some text here" > file.txt
    

    【讨论】:

      最近更新 更多