Custom Search

Ubuntu copy paste in command line terminal

Sometimes we need to copy text from somewhere and paste it in Ubuntu command line for some reasons. For example, you are learning Linux bash shell scripting from the Internet. It is faster, easier and safer if you can copy an example bash script from the Internet and paste it in command line rather than typing it. How do you copy and paste text in Ubuntu command line? Here is how I do it.



Using cat command


This is one of the mostly used command in Linux, at least by me. The cat command normally used to read file but also can be used to append text to a file. We are going to use that append part to copy and paste text in command line terminal. Let's see an example:





This is a script from the Internet that I want to copy. So I highlight the text, right-click and choose copy.



Next, open Ubuntu command line terminal and using cat command to paste the text I copied earlier. Here is the steps:




luzar@ubuntu:~$ cat >> paste.txt
NameVirtualHost *
<VirtualHost * >
ServerAdmin webmaster@localhost

DocumentRoot /var/www/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
luzar@ubuntu:~$ ls -l | grep paste.txt
-rw-r--r-- 1 luzar luzar 432 2008-12-12 18:55 paste.txt
luzar@ubuntu:~$ cat paste.txt
NameVirtualHost *
<VirtualHost * >
ServerAdmin webmaster@localhost

DocumentRoot /var/www/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
luzar@ubuntu:~$


Here is explanation of the example above. The command cat >> paste.txt will append text(input) into a file name paste.txt. Press enter and you'll see no command prompt. That means cat is waiting for the input. So, right-click to paste the text we copied earlier. When we finished, press Ctrl+d to save and exit.



The ls -l | grep paste.txt and cat paste.txt just to show result of what we did.



That's all. Light and easy.

No comments:

Post a Comment

Please keep comment relevant and strictly no spam will be tolerated. Thank you.