DEV Community

Avinash Sivaraman
Avinash Sivaraman

Posted on

⚡️ Lighting blaze file content copying to the Clipboard (Mac) 💻

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)

Collapse
 
karthikgk97 profile image
Karthik Ganesan

Very helpful blog.

Collapse
 
jjdharshini4 profile image
Dharshini Jaiganesh

It's an useful and an easy read! 👏👏