copy file contents from the command line

2020-07-25

 | 

~1 min read

 | 

134 words

I have a dotfiles repository where I store all of my settings for things like zsh and VS Code. Whenever I make a change to one of those files, I want to quickly copy them to update my repository.

There are a number of ways I can do this.

For example, I can use pbcopy to add the contents of a file to my clipboard and then paste them somewhere using cmd + v or pbpaste (assuming MacOS):

$ pbcopy < ~/.zshrc
$ pbpaste > ~/path/to/target/file.txt

(Note: The inverse, pbcopy, does not work)

Alternatively, I can merely redirect the contents from my .zshrc file to the respository’s equivalent:

$ cat ~/.zshrc | ~/code/dotfiles/.zshrc

These are yet more uses of redirection with the shell that I find very useful.


Hi there and thanks for reading! My name's Stephen. I live in Chicago with my wife, Kate, and dog, Finn. Want more? See about and get in touch!