单行创建包含内容的文件

apa*_*jja 8 command-line nano cat

操作系统是Ubuntu.我要创建file.txt/home/z/Desktop该文件的内容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(第二种方式),但不,它不起作用

gak*_*gak 14

你可以"echo"在bash中使用.例如:

echo "some text here" > file.txt
Run Code Online (Sandbox Code Playgroud)

如果您不希望在文件末尾添加新行字符,请使用以下-n参数:

echo -n "some text here" > file.txt
Run Code Online (Sandbox Code Playgroud)