Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single line create file with content

The OS is Ubuntu. I want to create file.txt in /home/z/Desktop where the content of the file is some text here.

The first and usual way is run nano /home/z/Desktop/file.txt and type some text here. after that, press ctrl+x, pressy followed by Enter.

The second way is run cat > /home/z/Desktop/file.txt, type some text here and press Enter followed by ctrl+c

I hope I can run single line of command to make it faster. I thought xdotool will work with the cat (the second way), but no, it not works

like image 502
apasajja Avatar asked Apr 12 '12 05:04

apasajja


Video Answer


1 Answers

You can use "echo" in bash. e.g.:

echo "some text here" > file.txt

If you don't want a new line character at the end of the file, use the -n argument:

echo -n "some text here" > file.txt
like image 161
gak Avatar answered Sep 29 '22 01:09

gak