Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cp: illegal option -- b on mac

Tags:

macos

cp

backup

I'm looking to backup a file. If the file exists in backup form, I'm looking to create a new version of that filename so as not to overwrite the previous backup.

I believe:

cp -b ~/.profile ~/
cp --backup ~/.profile ~/

is exactly what I need. However these options aren't available on a mac. Does anyone know if a substitute exists on a mac?

like image 400
Sam Odio Avatar asked Dec 16 '14 21:12

Sam Odio


1 Answers

Easiest thing to do is install GNU cp. The easiest way to do that is install Homebrew:

ruby -e \
  "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install coreutils

Then you can use gcp instead of cp whenever you need features not in the BSD cp that's part of OS X, e.g. gcp --backup.

like image 115
Ivan X Avatar answered Sep 21 '22 20:09

Ivan X