What is the difference between using terminal in mac vs linux?

I have been using Ubuntu for the past four years.
I have a basic knowledge of shell commands, and I prefer to work in a terminal rather than using a graphical interface. I recently started using a Mac.

I tried several terminal commands (which I use on Ubuntu) in a Mac terminal and it seems to respond basically the same way.

Are there any significant differences in the commands that I use, the tasks they perform, or the shell environment that I should be aware of?

+65
bash shell terminal ubuntu macos
Nov 08 '11 at 13:29
source share
2 answers

If you made a new or clean installation of OS X version 10.3 or later, the default user terminal shell is bash.

Bash is essentially an extended and free version of GNU's original Bourne shell, sh. If you have previous experience with bash (often by default in GNU / Linux installations), this makes the OS X command line work familiar, otherwise consider switching your shell to either tcsh or zsh, as some find it friendly .

If you upgraded or used OS X version 10.2.x, 10.1.x or 10.0.x, the default user shell is tcsh, an extended version of csh ('c-shell'). The early implementations were a little flawed, and the programming syntax was a little weird, so he developed a bad rap.

There are still some fundamental differences between mac and linux, since Gordon Davisson lists them so precisely, for example, no useradd on Mac and ifconfig works differently.

The following table is useful for knowing the various unix shells.

 sh The original Bourne shell Present on every unix system ksh Original Korn shell Richer shell programming environment than sh csh Original C-shell C-like syntax; early versions buggy tcsh Enhanced C-shell User-friendly and less buggy csh implementation bash GNU Bourne-again shell Enhanced and free sh implementation zsh Z shell Enhanced, user-friendly ksh-like shell 

You can also find helpful tips:

http://homepage.mac.com/rgriff/files/TerminalBasics.pdf

http://guides.macrumors.com/Terminal
http://www.ofb.biz/safari/article/476.html

Finally, I am on Linux (Ubuntu 11) and Mac osX, so I use bash and I like setting up the .bashrc file (source'd from .bash_profile on OSX) with aliases, some examples below. Now I put all my aliases in a separate .bash_aliases file and included it with:

 if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi 

in a .bashrc or .bash_profile file.

Note that this is an example of the difference in mac-linux, since on Mac you cannot have --color=auto . The first time I did this (without knowing), I redefined ls as invalid, which was a little disturbing until I deleted --auto-color !

You can also find https://unix.stackexchange.com/q/127799/10043 useful

 # ~/.bash_aliases # ls variants #alias l='ls -CF' alias la='ls -A' alias l='ls -alFtr' alias lsd='ls -d .*' # Various alias h='history | tail' alias hg='history | grep' alias mv='mv -i' alias zap='rm -i' # One letter quickies: alias p='pwd' alias x='exit' alias {ack,ak}='ack-grep' # Directories alias s='cd ..' alias play='cd ~/play/' # Rails alias src='script/rails console' alias srs='script/rails server' alias raked='rake db:drop db:create db:migrate db:seed' alias rvm-restart='source '\''/home/durrantm/.rvm/scripts/rvm'\''' alias rrg='rake routes | grep ' alias rspecd='rspec --drb ' # # DropBox - syncd WORKBASE="~/Dropbox/97_2012/work" alias work="cd $WORKBASE" alias code="cd $WORKBASE/ror/code" # # DropNot - NOT syncd ! WORKBASE_GIT="~/Dropnot" alias {dropnot,not}="cd $WORKBASE_GIT" alias {webs,ww}="cd $WORKBASE_GIT/webs" alias {setups,docs}="cd $WORKBASE_GIT/setups_and_docs" alias {linker,lnk}="cd $WORKBASE_GIT/webs/rails_v3/linker" # # git alias {gsta,gst}='git status' # Warning: gst conflicts with gnu-smalltalk (when used). alias {gbra,gb}='git branch' alias {gco,go}='git checkout' alias {gcob,gob}='git checkout -b ' alias {gadd,ga}='git add ' alias {gcom,gc}='git commit' alias {gpul,gl}='git pull ' alias {gpus,gh}='git push ' alias glom='git pull origin master' alias ghom='git push origin master' alias gg='git grep ' # # vim alias v='vim' # # tmux alias {ton,tn}='tmux set -g mode-mouse on' alias {tof,tf}='tmux set -g mode-mouse off' # # dmc alias {dmc,dm}='cd ~/Dropnot/webs/rails_v3/dmc/' alias wf='cd ~/Dropnot/webs/rails_v3/dmc/dmWorkflow' alias ws='cd ~/Dropnot/webs/rails_v3/dmc/dmStaffing' 
+47
Nov 08 2018-11-11T00:
source share

@ Michael Darrant's answer cleverly covers the shell, but the shell environment also includes the various commands that you use in the shell, and they will be similar but not identical between OS X and Linux. In general, both of them will have the same basic commands and functions (especially those defined in the Posix standard), but many extensions will be different.

For example, Linux systems typically have the useradd command to create new users, but OS X does not. In OS X, you usually use a graphical interface to create users; if you need to create them from the command line, you can use dscl (which linux does not have) to edit the user database (see here ).

In addition, some of the commands that they have will have different functions and options. For example, linuxs typically include GNU sed , which uses the -r option to invoke extended regular expressions; on OS X, you must use the -E option to get the same effect.

EDIT: Another difference is that many linux commands allow parameters to be specified after their arguments (e.g. ls file1 file2 -l ), while most OS X commands require that parameters be executed strictly first ( ls -l file1 file2 ).

Finally, since the OS itself is different, some commands behave differently between the OS. For example, on linux, you probably use ifconfig to change the network configuration. In OS X, ifconfig will work (possibly with a slightly different syntax), but your changes will most likely be overwritten by accident with system configuration daemons; instead, you should edit the network settings using networksetup , and then let the configuration daemon apply them to the current state of the network.

+22
Nov 08 2018-11-11T00:
source share



All Articles