Have you ever tried to copy the content of a file and paste it somewhere else like copying a JSON file and pasting it in some website. When you want to copy a file, we need to open a file and select all the content by command + A (or using the mouse) and copying the content of the file.
Here is the trick to copy the content directly from the terminal.
pbcopy < filename.txt
We can simplify the command by adding an alias in our .bashrc file. So, we don't need to type this whole command to copy the content. Open the .bashrc in vim or any other editor of your choice.
vim ~/.bashrc
Add the below line inside the .bashrc file and save it.
alias cc='pbcopy <'
Now we need to restart the terminal or run the below command in the terminal to see our alias in action.
source ~/.bashrc
Finally, you can copy the content of the file by using the cc command and this command is local to your machine.
cc demo.txt
Happy Coding π». You can find my personal .bashrc file which contains a lot of GitHub and npm shortcuts here. I am really happy to discuss more tips and tricks to improve productivity. Feel free to comment down below β¬οΈ
Top comments (2)
Very helpful blog.
It's an useful and an easy read! ππ