This article shows the alternative method to copy the content of the file onto the clipboard, via the Linux terminal. In OSX, the commands pbcopy and pbpaste are available by default. Thus, to copy a file onto the clipboard via OSX terminal, type:
pbcopy < 'path of the file'
Since, in Ubuntu, pbcopy and pbpaste commands are not available by default, installing xclip will serve our purpose.
The next step is to open the bash_aliases file.
Next, type in the following inside bash_aliases file and save it.
#using pbcopy and pbpaste for copy-paste a file's contents alias pbcopy='xclip -selection clipboard' alias pbpaste='xclip -selection clipboard -o'
This will set pbcopy and pbpaste as the aliases for xclip’s copy and paste commands respectively. Now we are ready to test the commands in the terminal. Let’s create a file named ‘file.txt’ and add some content into it.
Save the file and exit from the text editor. Let’s try copying and pasting its content from the terminal with our
Thus, now we are able to copy and paste the contents of our file using the terminal.
Note: One can use
pbcopy command in the terminal to copy the c++/python template file used for competitive programming. Instead of the opening and copying the template file every time you attempt a question, just run the command in the terminal to get the work done and save time.
- Cool Custom Welcome Messages on Linux terminal
- Custom commands for linux terminal
- Basic System Controls with Terminal in Linux
- Some useful Linux Hacks
- Daily life Linux Commands
- Basic Linux Commands for day to day life
- Reset a lost Linux administrative password and Explanation
- Encrypt/Decrypt Files in Linux using Ccrypt
- mindepth and maxdepth in Linux find() command for limiting search to a specific directory.
- Network configuration and trouble shooting commands in Linux
- Netstat command in Linux
- Practical applications of 'ls' command in Linux
- 'crontab' in Linux with Examples
- Important Linux Commands (leave, diff, cal, ncal, locate and ln)
- 'dd' command in Linux
- 'IPCS' command in Linux with examples
- Essential Linux/Unix Commands
- Permissions in Linux
- select command in Linux with examples
- grep command in Unix/Linux
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.