Quickly Copying Text to a File

By Zhiqiang Ma On Dec 12, 2012

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.

By: Zhiqiang Ma Last updated: Dec 12, 2012 Views: 60
Tags: , , ,

About Zhiqiang Ma

Zhiqiang Ma is a PhD candidate at Dep. of CSE, HKUST. He is interested in system software for cloud computing, virtualization of large-scale distributed system, etc. Find Zhiqiang on Facebook, Twitter, LinkedIn and Google+.

Add your comments, share your thoughts

Be nice. Keep it clean. Stay on topic. No spam.