I found there is some differences between the utility command I used on the mac OSX and linux. I want to make my experience united.
How could I replace all my mac utilities with GNU utilities?
This adds symlinks for GNU utilities with g prefix to
brew install coreutils findutils gnu-tar gnu-sed gawk gnutls gnu-indent gnu-getopt
brew search gnu for other packages. If you want to use the commands without a g prefix, install the formulas with
--with-default-names if your
brew version is newer), or add for example
/usr/local/opt/coreutils/libexec/gnubin before other directories on your
$ brew info coreutils coreutils: stable 8.21 http://www.gnu.org/software/coreutils Depends on: xz /usr/local/Cellar/coreutils/8.20 (208 files, 9.4M) /usr/local/Cellar/coreutils/8.21 (210 files, 9.6M) * https://github.com/mxcl/homebrew/commits/master/Library/Formula/coreutils.rb ==> Caveats All commands have been installed with the prefix 'g'. If you really need to use these commands with their normal names, you can add a "gnubin" directory to your PATH from your bashrc like: PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH" Additionally, you can access their man pages with normal names if you add the "gnuman" directory to your MANPATH from your bashrc as well: MANPATH="/usr/local/opt/coreutils/libexec/gnuman:$MANPATH"
You can install GNU
grep by tapping homebrew/dupes:
brew tap homebrew/dupes; brew install grep
brew install coreutils, you may also need to install some other packages, such as
brew install findutils --with-default-names brew install gnu-indent --with-default-names brew install gnu-sed --with-default-names brew install gnutls brew install grep --with-default-names brew install gnu-tar --with-default-names brew install gawk
--with-default-names option is optional, turn on this if you really need to use these GNU commands as default ones, or they will be compiled with a
I'm not sure that I would recommend replacing them; however, you can install them to a different path and utilize them that way. Overall, if you are coming from Linux and would like access to more "generic" *nix utilities, and a system similar to apt, then I would recommend looking into Macports: http://www.macports.org
It allows, for example, using the latest "generic" GCC, as opposed to/in addition to Apple's included GCC, just as an example.
I've written a script to do exactly this! The script can be viewed here (or below). However, I can't always guarantee this post will reflect the latest version of the script linked previously.
Upon running the script, Homebrew will be installed (if not already), all the associated GNU utilities will be installed (if not already), and the
PATH variable will be built from the installed utilities.
#!/bin/bash # Install Homebrew (if not already installed) ruby -e "$(curl -fsSL "\ "https://raw.githubusercontent.com/Homebrew/install/master/install)" # Install required packages from Homebrew brew tap homebrew/dupes brew install coreutils binutils diffutils ed findutils gawk gnu-indent gnu-sed \ gnu-tar gnu-which gnutls grep gzip screen watch wdiff wget bash gdb gpatch \ m4 make nano file-formula git less openssh python rsync svn unzip vim \ --default-names --with-default-names --with-gettext --override-system-vi \ --override-system-vim --custom-system-icons # Empty the .bash_path file that holds GNU paths > ~/.bash_path # Build PATH variable script in ~/.bash_path for i in /usr/local/Cellar/*/*/bin; do echo 'export PATH="'$i':$PATH"' >> ~/.bash_path done for i in /usr/local/Cellar/*/*/libexec/gnubin; do echo 'export PATH="'$i':$PATH"' >> ~/.bash_path done for i in /usr/local/Cellar/*/*/share/man; do echo 'export MANPATH="'$i':$MANPATH"' >> ~/.bash_path done for i in /usr/local/Cellar/*/*/libexec/gnuman; do echo 'export MANPATH="'$i':$MANPATH"' >> ~/.bash_path done # Check if .bash_path is being called from .bash_profile PATCH=`grep "~/.bash_path" ~/.bash_profile` if [ "$PATCH" == "" ]; then # Add Ubuntu-style PS1 to .bash_profile cat <<EOF > ~/.bash_profile export PS1="\[\033[1;32m\]\u@\h\[\033[0m\]:\[\033[1;34m\]\w\[\033[0m\]# " EOF # Add .bash_path to .bash_profile echo "source ~/.bash_path" >> ~/.bash_profile fi