Quickly Copying Text to a File

Posted on In Linux

Copying some text to a new file is a common operation on Linux. I usually do this by opening the file with ‘vim’, pasting the text in ‘vim’, and then saving the file. I learned a more efficient and quicker way from my advisor during one discussion with him when I show him some results.

Here is the quicker way to copy text to a file.

First, copy the text to the clipboard. In the gnome-terminal, it is ‘Ctrl+Shift+c’. In other GUI programs, it is usually ‘Ctrl+c’.

Then, the most important part, past the text to a new or to-be-overwritten file, say ‘file.txt’:

$ cat > file.txt

The ‘cat’ now is waiting for input from STDIN. We can paste the text to it by ‘Ctrl+Shift+v’.

The last step, press ‘Ctrl+d’ to tell ‘cat’ that we have finished inputting the text.

After this, the text is saved to the new file ‘file.txt’.

I like this method much—it improves the efficiency significantly of this common operation and save much of my time.

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *