Take the 2-minute tour ×

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

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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
share|improve this answer
add comment

Your Answer


