Ask HN: I want to learn to use the terminal, where do I start

33 points by macterminalnewb ↗ HN
as the title states, i want to become familiar/proficient in using the terminal on my mac, and just in general the code used in terminal/CLI. any tips on where to get started, like some online free course to follow? tips/help appreciated

56 comments

[ 2.6 ms ] story [ 120 ms ] thread
I originally learned much from the bash programming guide and advanced bash programming guide. While Mac uses zsh, you can still learn quite a bit that will carry over, and you can always run bash scripts with the `#!/bin/bash`

The Linux Documentation Project (TLDP) is a great resource generally

https://tldp.org/guides.html

Learn basic commands, use Youtube.

`man` will tell you the usage of most commands `man cp` for example will give you an explanation on the command `cp`.

Learn to use `grep` and `find`. And you'll also want to learn bash (the programming language).

a great place to start would be to take a few smaller tasks that you do everyday and use terminal to do those

i'll also suggest trying to automate smaller tasks by leveraging scripts and terminal

best way to learn is to do

The best way to learn the terminal is to use it. Whatever is that you do in your working day, do it from inside the terminal.

Any problem you come up with, solve it by seaching or asking GPT.

Of course, this presupposes that you do have the basic understanding of how file system is structured, have basic knowledge of shell commands (cd, ls, cp, gzip, etc...). If not, those are not difficult (at a begginer level) and just google "how to use command line" as there are countless resources out there. This is just one them: https://developer.mozilla.org/en-US/docs/Learn/Tools_and_tes...

But I would actually suggest one particular course, that is actually not targeted at begginers (in my opinion). That course is Destroy All Software (https://www.destroyallsoftware.com/screencasts/catalog) and it will teach you to really appreciate the beauty of the shell/terminal (yes, those are different but it really doesn't matter at this point). The course is not only about the terminal, but you will find gold nuggets in that series of screencast that are about the terminal and the philosophy of using it. There are few free episodes and one that I can specifically point to regarding learning the concepts is "Tar, Fork, and the Tar Pipe" (https://www.destroyallsoftware.com/screencasts/catalog/tar-f...).

If you want to be proficient in the shell wizardry, it will take time. But it's worth it.

There’s a pretty basic course on code academy for how to use the terminal with basic commands etc.It’s super easy. And then from there if you need to do something, but don’t know how/don’t know the command - Google it.
A useful first step is to stop using Finder. Instead perform the required operations from the terminal. When you don't yet know how, Google it. The first couple of useful commands are ls: list files (lots of options); cd: change directory; cp:copy; mv:move -- aka rename; vi:edit text file; file: what type of file is it? ... etc.

If that's too daunting, then still have Finder open, but try to match the operations with above and more.

Start with the basics of your shell. The internet is full of good info (like here for example https://www.gnu.org/software/bash/manual/html_node/) to get you started. Once you're at the point where you've customized your shell, and tried a bit of scripting move on from just playing around with tutorials and documentation and start doing something useful/entertaining.

Look into specific tools for whatever you need or are interested in doing. grep is really good to know. If you're into networking/internet stuff dig, whois, ping, and traceroute are too. wget curl and youtube-dl are great and provide all kinds of opportunities to automate some of the things you do online which can make you want to dig more into shell scripting and keep you going back to your terminal. ffmpeg and ImageMagick too. Maybe pick up some python.

> Start with the basics of your shell. The internet is full of good info (like here for example

That is not their shell. OP is on macOS, meaning their shell is Zsh. They should not be reading a comprehensive (and frankly very boringly structured, it starts with sections and sections of details irrelevant to a curious beginner) guide on Bash 5.2, which isn’t available on macOS by default.

As I said, it was only an example. I had no idea what shell they'd be using or that macOS apparently left them with Zsh and no other option. Apple's website suggests otherwise https://support.apple.com/guide/terminal/change-the-default-...
(comment deleted)
It’s not “no other option”, they can switch to Bash but it’s an old version, or they could install a newer version with Homebrew or similar. But none of those steps should be taken by someone just starting.

The point is precisely that the OP likely has no idea what their shell is. I wasn’t lobbying a criticism, but a correction so they are aware.

Regarding the example guide, I do think it’s not a great one for total beginners. someone with interest in learning the Terminal should be given an interesting resource that let’s them play a bit with commands and understand what it’s about before drowning them in theory and technical information.

I usually need a project.

Currently, probably trying to run a LLM locally is easiest to do in CLI, so just try that.

Alternatively, buy yourself a server, like 5$/month single core, ther eare budget friendly options, Linode is one. Once you have that, try to run something there. I.d.k. a miniecraft server. Open TTD server. Whatever you want. Not something too critical because you are learning and some automated bot could i.d.k. guess your password (don't use passwords) and turn your box into bitcoin miner ... but you will learn stuff.

Another is to watch a streamer on Twitch and try to get that you would like to do.
Let me tell you how I did it. I remember I wanted to start using Linux full-time no BS and have had some exposure to the terminal. I took the opportunity of a new position, I said I had to use Linux for the day-to-day activities and they bought it. So I had to use the terminal/Linux without disrupting any of the necessary activities.

Meanwhile, I read the beginning half of "The Linux Command Line" [1]. I highly recommend it. Looking back, I might have read it until part 2 and skimmed the rest, and read it as I needed it.

Try to do everything through the terminal. File creation, reading, managing stuff, changing wifi, configuring editors, writing files. Try to find the conversion tools with the rest of the "world". Some examples of what I mean are pandoc for md->docx conversion, python pandas for csv -> xlsx. Build small scripts for your tasks. For example, I work in a multilingual company and I have a tool for translation which at first used Google Translate and now uses gpt. At some point in the journey I even had my own custom dwm build. Fun times. Do read about suckless software, a fun philosophy with some genuine principles, and a nice (but not friendly) ecosystem.

So my recommendation is to read something to give you breadth on linux/terminal knowledge so you can navigate around and stick to it as your main driver.

Another book one I recommend is the "Unix and Linux system administration handbook"[2]. It will tell you more about the history and inner workings when compared to the previous one.

1: https://www.linuxcommand.org/tlcl.php

2: https://admin.com/

Just start because it is a years long process. Maybe set up a Linux VM so you don't break anything...good luck.
Aside: zsh is standard on macs now, thanks to Apple's lawyers freaking out over bash license terms. If you want to change to industry standard bash (I did) then there are three ways to do it.

Short: csh -s /bin/bash

Others: system settings or terminal settings.

[1] https://support.apple.com/en-gb/guide/terminal/trml113/mac

[2] https://www.howtogeek.com/444596/how-to-change-the-default-s...

You may want to update bash via homebrew, or install the full set of Xcode command line tools. (But not full Xcode environment)

xcode-select --install

[3] https://www.macobserver.com/tips/how-to/install-xcode-comman...

OP, I don't suggest you do this until you know what you're doing -- if ever.

Just start with the built-in zsh. Nearly everything you learn with zsh will work the same over on bash and Linux.

Also, I suggest resisting the urge of listening to those telling you to install oh-my-zsh. IMHO, it's a bloated plugins manager (no disrespect to robby <3) and introduces too much magic for beginners. Start basic.

I was curious as to why someone would prefer bash over zsh i.e. what are the salient differences, and a brief search led me to this thorough answer:

https://apple.stackexchange.com/questions/361870/what-are-th...

…but I’m still not sure there’s a material difference that would impact me, and I’ve been programming professionally since the mid 90s. If I can ask a side question, why would one switch back to bash from zsh?

I prefer bash because I'm more used to it and I feel like zsh gets in the way. One example would be tab completion. When there are multiple matches, zsh will cycle through all possible matches (like cmd.exe, but slightly less annoying). Do Not Want.
Is there any point in just learning to use a tool without making something with it? You won’t learn to use a saw until you build something with it.

Learn to program and you will be required to learn how to use the terminal.

There certainly is. I've been using Linux/Mac terminal off and on for a couple of decades and have never "built" anything with it. Certainly no programming or even shell scripting leaves out some of the usefulness of the command line, but knowing the commands to get individual tasks done is very useful.
I think my point still stands. You didn’t just learn it. You learned how to do things with it.
Terminal is a tool, it is to make you reach a destination. Chrome for a lot of folks is a browser, but for some it is a job to develop and for some it is a job to use it to test !! You have to figure out what your goal is, then use the tool to get there !! So small things like opening files, try doing text manipulation like copy paste vs replace some text using terminal and you are almost golden !!
Stop using one of the GUI applications.

A good one to start with on mac is probably Finder.

Type 'man man' to learn about man pages.

Read the pages for 'cd', 'cp', 'rm', 'mv', 'find', 'cat'.

Try each one.

Move around the filesystem, move or rename some files.

That's all a good part of what you'll be doing on the cli.

'ls' is probably the most fundamental command as it let's you list the files in a file system, then 'cd' (move in/out of directories). Then go from there.

for help on 'ls' use either:

ls --help

or

man ls

Well, one option is to boot into the terminal. Being forced to use it is by far the best way to learn.

Not having a browser may come to annoy though.

Learn how to find files without Finder using the terminal. Basically think of things you do outside of the Terminal and ask yourself “can I do this specifically in the terminal” a lot of times, yes, yes you can.

I also recommend iTerm 2 I think was the terminal emulator we used at a former job. It was really nice, and helped you install gnu utilities which honestly doing command line work without is a pain.

In addition to the other good advice - I would suggest opening your mind to possibilities.

For instance - say you're doing something repetitive and tedious in an AWS console, every day, and it's mostly the exact same task. Let's just say for the sake of argument you have to kick off some codebuild job every day at 8am first thing you go into work - so you log in, click through the UI, select account/region, find the job, etc. Takes you about 5 minutes.

But wait! The AWS CLI can do the same thing - write a simple script to do a repetitive task like that. Instead of spending 5 minutes every day, now you've got a script that you can run in 5 seconds or less, plus it could be possibly integrated into other automation.

Opening your mind to stuff like this will naturally get you to start using the terminal more often. I'd also suggest familiarizing yourself with a text editor like vim or emacs (or whatever flavor you prefer).