I've been using cat and vim for the wrong reasons for so long...

twitter logo github logo ・1 min read

My situation: I have a file that I need to copy the entire contents of it.

In the terminal, I type: cat file.txt, then copy the terminal output.

The easy solution:

pbcopy < file.txt

And now the contents are saved in my clipboard.

Then, if I had to paste those contents somewhere else, I would use vim to create a file and paste those contents in there, and if I was lucky, I wouldn't have to restart my computer from getting stuck in vim.

Instead, the easy solution:

pbpaste > file-two.txt

And now, all of the contents from my clipboard are saved in file-two.txt!

What other bash commands have you found useful? Let me know in the comments!

twitter logo DISCUSS (7)
markdown guide
 
 

I use pbcopy all the time but was unaware of pbpaste (I've used the vim then paste method). So thanks for that!

For those offering suggestions on how to do a direct copy of one file to a new file. These are all great suggestions as well, but sometimes I'm copy to or pasting from something else.

 

An easy way to make a paste from the terminal instead of using paste in is to do;

cat <input> | nc termbin.com 9999
 

Also, in case you are working in a remote machine

man scp

But I'm trying to figure out why do you need to copy it into the clipboard in the first place.

a simple cat file1.txt > file2.txt would do the job (or the examples already in comments), unless you are in a remote session (that's where scp comes handy :).

 

There are a few commands that copy files. So instead of doing a copy/paste routine you can do like this:

ditto file1.txt file2.txt

Also check out cp

 
Classic DEV Post from Jul 2

How to refill someone’s “cup?”

Sometimes we rely so much on our friends and coworkers that we often forget to ma...

Matt Crowder profile image
Software Engineer at Appian, previously at Walmart Labs. Co-organizer of novajavascript.com, public speaker, teacher, codementor.io/mcrowder65