Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 13 years ago.
The community reviewed whether to reopen this question 11 months ago and left it closed:
Original close reason(s) were not resolved
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
如果您全新安装或全新安装了 OS X 10.3 版或更高版本,则默认用户终端 shell 为 bash。
Bash 本质上是原始 Bourne shell sh 的增强版和 GNU 免费软件版本。如果您以前有过使用 bash(通常是 GNU/Linux 安装上的默认设置)的经验,这会使 OS X 命令行体验变得熟悉,否则请考虑将 shell 切换到 tcsh 或 zsh,因为有些人发现这些对用户更友好。
如果您从 OS X 版本 10.2.x、10.1.x 或 10.0.x 升级或使用 OS X 版本,则默认用户 shell 为 tcsh,它是 csh('c-shell') 的增强版本。早期的实现有点错误,编程语法也有点奇怪,因此名声不佳。
正如 Gordon Davisson 所恰当地列出的那样,Mac 和 Linux 之间仍然存在一些根本差异,例如 Mac 上没有
useradd
且ifconfig
的工作方式不同。下表对于了解各种 UNIX shell 很有用。
您可能还会发现这些指南很有帮助:
http://homepage.mac.com/ rgriff/files/TerminalBasics.pdf
http://guides.macrumors.com/Terminal
http://www.ofb.biz/safari/article/476.html
最后一点,我使用的是 Linux (Ubuntu 11) 和 Mac osX,所以我使用 bash,我最喜欢的是自定义 .bashrc(源自 OSX 上的
.bash_profile
)文件和别名,下面是一些示例。现在,我将所有别名放在单独的 .bash_aliases 文件中,并将其包含在:
.bashrc 或 .bash_profile 文件中。
请注意,这是 mac-linux 差异的示例,因为在 Mac 上您无法使用
--color=auto
。我第一次这样做(不知道)时,我将ls
重新定义为无效,这有点令人担忧,直到我删除了--auto-color
!您可能还会发现https://unix.stackexchange.com/q/127799/10043很有用
If you did a new or clean install of OS X version 10.3 or more recent, the default user terminal shell is bash.
Bash is essentially an enhanced and GNU freeware version of the original Bourne shell, sh. If you have previous experience with bash (often the default on GNU/Linux installations), this makes the OS X command-line experience familiar, otherwise consider switching your shell either to tcsh or to zsh, as some find these more user-friendly.
If you upgraded from or use OS X version 10.2.x, 10.1.x or 10.0.x, the default user shell is tcsh, an enhanced version of csh('c-shell'). Early implementations were a bit buggy and the programming syntax a bit weird so it developed a bad rap.
There are still some fundamental differences between mac and linux as Gordon Davisson so aptly lists, for example no
useradd
on Mac andifconfig
works differently.The following table is useful for knowing the various unix shells.
You may also find these guides helpful:
http://homepage.mac.com/rgriff/files/TerminalBasics.pdf
http://guides.macrumors.com/Terminal
http://www.ofb.biz/safari/article/476.html
On a final note, I am on Linux (Ubuntu 11) and Mac osX so I use bash and the thing I like the most is customizing the .bashrc (source'd from
.bash_profile
on OSX) file with aliases, some examples below.I now placed all my aliases in a separate .bash_aliases file and include it with:
in the .bashrc or .bash_profile file.
Note that this is an example of a mac-linux difference because on a Mac you can't have the
--color=auto
. The first time I did this (without knowing) I redefinedls
to be invalid which was a bit alarming until I removed--auto-color
!You may also find https://unix.stackexchange.com/q/127799/10043 useful
@Michael Durrant 的答案巧妙地涵盖了 shell 本身,但 shell 环境还包括您在 shell 中使用的各种命令,这些命令在 OS X 和 Linux 之间是相似的,但不完全相同。一般来说,两者都具有相同的核心命令和功能(尤其是 Posix 标准中定义的命令和功能),但许多扩展会有所不同。
例如,Linux系统通常有一个
useradd
命令来创建新用户,但OS X没有。在 OS X 上,您通常使用 GUI 来创建用户;如果您需要从命令行创建它们,您可以使用dscl
(linux没有)来编辑用户数据库(请参阅此处)。 (更新:从 macOS High Sierra v10.13 开始,您可以改用 sysadminctl -addUser 。)此外,它们共有的一些命令将具有不同的功能和选项。例如,linux通常包含GNU
sed
,它使用-r
选项来调用扩展正则表达式;在 OS X 上,您可以使用-E
选项来获得相同的效果。类似地,在 Linux 中,您可以使用 ls --color=auto 来获取彩色输出;在 macOS 上,最接近的等效项是ls -G
。编辑:另一个区别是许多Linux命令允许在其参数之后指定选项(例如
ls file1 file2 -l
),而大多数OS X命令要求选项严格放在第一位(ls - l 文件1 文件2
)。最后,由于操作系统本身不同,因此某些命令在操作系统之间的行为会有所不同。例如,在 Linux 上,您可能会使用
ifconfig
来更改网络配置。在 OS X 上,ifconfig
可以工作(可能语法略有不同),但您的更改可能会被系统配置守护程序随机覆盖;相反,您应该使用networksetup
编辑网络首选项,然后让配置守护进程将它们应用到实时网络状态。@Michael Durrant's answer ably covers the shell itself, but the shell environment also includes the various commands you use in the shell and these are going to be similar -- but not identical -- between OS X and linux. In general, both will have the same core commands and features (especially those defined in the Posix standard), but a lot of extensions will be different.
For example, linux systems generally have a
useradd
command to create new users, but OS X doesn't. On OS X, you generally use the GUI to create users; if you need to create them from the command line, you usedscl
(which linux doesn't have) to edit the user database (see here). (Update: starting in macOS High Sierra v10.13, you can usesysadminctl -addUser
instead.)Also, some commands they have in common will have different features and options. For example, linuxes generally include GNU
sed
, which uses the-r
option to invoke extended regular expressions; on OS X, you'd use the-E
option to get the same effect. Similarly, in linux you might usels --color=auto
to get colorized output; on macOS, the closest equivalent isls -G
.EDIT: Another difference is that many linux commands allow options to be specified after their arguments (e.g.
ls file1 file2 -l
), while most OS X commands require options to come strictly first (ls -l file1 file2
).Finally, since the OS itself is different, some commands wind up behaving differently between the OSes. For example, on linux you'd probably use
ifconfig
to change your network configuration. On OS X,ifconfig
will work (probably with slightly different syntax), but your changes are likely to be overwritten randomly by the system configuration daemon; instead you should edit the network preferences withnetworksetup
, and then let the config daemon apply them to the live network state.