12

I am going to learn how to use the command line. Specifically, I will be using the book: "The Linux Command Line: A Complete Introduction". Now, do I have to use a Linux distro to walk through the book, or would OS X be sufficient?

If I need a Linux distro, then would using it through a VM be sufficient or do I need to install it natively?

  • 8
    The only reason you would need to install an OS on physical hardware and not a VM would be for performance. If you're just trying to learn basic procedures than that's not going to be an issue. It's probably preferable to run something like Arch in a VM. – Bratchley Oct 2 '15 at 18:42
  • same discussion on apple.stackexchange.com/q/208692/7057 – glenn jackman Oct 2 '15 at 18:50
  • 4
    Command-line is just a link between you and the system. Bash shell syntax may be the same, but when you need to deal with system specific parts, there's going to be differences. For instance, OS X doesnt have /proc filesystem, USB drives tend to appear in /Volumes not /media/username as on Ubuntu. CentOS has different dhclient.conf file . And so on and so on – Sergiy Kolodyazhnyy Oct 2 '15 at 19:00
  • 4
    The proposed cross-site duplicate is very clearly a different question, about virtualisation performance on MacBooks. The question is not cross-posted. – Michael Homer Oct 3 '15 at 19:42
  • 2
    @Utku I think what might help would be to separate a few concepts: using a command line, and the operating system you use it on. If you want to know your away a command line, OS X would work, as well as Linux, BSD, or even Windows with some effort. If you want to get to know UNIX or Linux, the command line is only a small part of that - it's only the interface through which you will interact with the OS. I think clarifying what you're going for will also make it easier to learn :) – rickcnagy Oct 4 '15 at 6:27
33

I would highly recommend running Linux in a VM. All the software is available freely to download and there is no practical difference between running in a VM and running natively for the purposes of learning the command line.

Furthermore, Linux command line mostly consists of bash + GNU coreutils, which is very different from BSD Unix (and OS X is a succedessor of BSD Unix). There is a very big difference of preferences in writing arguments in BSD Unix and GNU Linux. You can bite yourself even as non-newbie with different options to standard utilities like ps and tar if you work on both systems.

Using OS X when your book is Linux specific will regularly throw up inconsistencies and differences that will appear superficial when you're more experienced, but will simply be confusing when you're learning. Keep things easy for yourself.

This will also allow you to experiment without the worry of breaking your machine by deleting or changing any important files.

And last, though certainly not least, it will allow you to set up a SSH connection to your VM from your OS X Terminal, so you can get used to using SSH keys, and to the idea that it makes no difference whether your Linux server is a native machine, a local VM, or running out on AWS or Digital Ocean: it all works the same!

  • By the way, will I have the same directory structure in a VM vs. a native Linux as well? – Utku Oct 2 '15 at 18:47
  • 3
    Yes. For your purposes it's exactly the same as a native install. – seumasmac Oct 2 '15 at 18:52
  • This is the safest answer but depending on the book I would assume an introduction to the command line book would not show many (if any) of the differences. After a glance at the manual the only thing that stuck out to me would be the explanation of the directory structure. – pllee Oct 2 '15 at 20:11
  • 1
    @Utku If /dev/sda or /dev/hda is mentioned in the book and you can't find it in your install, try looking for /dev/vda. This is the only possible difference I can think of, that would matter to you. – Kimmax Oct 3 '15 at 16:01
  • 1
    You don't even have to use a VM, using a live CD is also possible if you don't want to take up a bunch of space on your HD. It can also be booted from a flash drive, and creating a CD/bootable flash drive takes very little time. – Chris Cirefice Oct 4 '15 at 18:27
18

OS X is sufficient to learn the command line as it is a certified UNIX and conforms to POSIX. If you are looking at Linux specific command line book you have to keep in mind that the userland tools in OS X are derived from BSD while the tools on Linux are GNU and there are some subtle (and not so subtle) differences between them.

If you want to learn with GNU tools you can install a GNU userland through macports or homebrew, or can do a full Linux install in a VM.

  • So, I guess that there is no "generic" book on command line? A book will either use GNU or BSD tools. Is that right? – Utku Oct 2 '15 at 17:40
  • 1
    If you have a book on a shell (e.g. bash), it'll suit just about any system that runs it. It varies when you start using operating system features or specific tools outside the shell. – teppic Oct 2 '15 at 17:43
  • 1
    @teppic But how useful is a shell just by itself? AFAIK, a shell by itself is useless since it doesn't have any command to execute. Even the most basic commands like ls must be either from GNU or BSD (please correct if I am wrong). So, I think this means that I need to pick one toolchain (or environment) and start learning the command line there. Is that right? – Utku Oct 2 '15 at 17:53
  • @Utku the commands are the same (for the most part) but options and output may differ (often because GNU implements many extensions). It easy to go back and forth between BSD and GNU tools. – casey Oct 2 '15 at 17:54
  • @casey So I might just start with the book on OS X. Then if I encounter with behavior not described as in the book, I might try it on Linux or just look at the BSD variant of the same command? – Utku Oct 2 '15 at 17:56
9

Some good answers so far, but one more reason to stay away from the default OS X command line tools is they are very old versions. For example, OS X's grep is from 2004, and bash is from 2007! The reason is that Apple refuses to ship tools licenced under the GPL3.

If you didn't want to install Linux proper, you could manually install the latest versions (perhaps via some port system like MacPorts, Fink or Homebrew).

3

First difference:

ls * -lah

Works on linux, fails on mac (parameters must come first). Use a VM or get a book for mac os. You should learn the one you will use more later and then the differences.

3

The best way to learn unix is to have real work to do with it. I'd say it's worth encountering the differences between the Linux-specific examples in your book and the Mac versions of the standard tools, just to be able to work with your own files and data in your normal working environment (OS X).

Encountering the differences will also be a valuable learning experience, even if it's frustrating at times.

Having a Linux VM as well to practice with (esp. for potentially dangerous commands) is also useful but nothing beats real-world usage for learning.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.