So, I installed Linux Mint not too long ago, and while I’ve been able to do what I want to do without touching the Terminal, I am a bit curious how it works, and whether it could help me.
In particular, I am slowly getting into programming, and I’ve heard some people talk about strange, otherworldly things, like Vim, and Shell Scripts.
There was this PDF I downloaded called “The Linux Command Line” by William Shotts, but it is 570 pages long, and glancing through it, it seems to go into many different things, and I am afraid I’ll end up learning a hundred things while only ever using ten of them, if you get my meaning.
So yeah, anyone who has some tips, or resources for a Linux newbie, please let me know.
Before you get too lost, I want to write a tiny intro:
The terminal (also called shell and sometimes command prompt, even though these are technically different things) is a place where you run commands.
If you open one right now and type
ls(that is a lower case L), and then hit enter, it will list the files in your current folder. And it spits that out as text, which will be important later. So that’s the gist,lsis a program that does something, and you type the name of it to run it, and it outputs its result as text.Most commands have “flags”, which are options you give it when you run it.
ls -lislsrun with the “l” flag (also lower case L). If you run that you’ll see it lists more information per file this time. The mnemonic here is “l for long”. There are lots of flags, and you can usually combine them with a single dash, sols -lthis the same asls -l -t -h, which lists extra data, sorts by time, and uses human readable units like “3GB” instead of 3096432764 bytes.There are also “long flags” that start with two dashes by convention. These would look like
ls -l --time --human-readablewhich does the same thing as before, but is more readable but less compact. Long options don’t combine the way short options do, so you need to separate them with spaces.Some flags need values. Like
ls -l --sort sizewhich is usually the same asls -l --sort=sizebut confusingly not the same asls -l --sort = size(note the spaces) which makes sense if you know how these things work, but for now you just need to accept.Commands also have “arguments”, which are not flags. Sometimes also called “parameters”. So for
lsup until now we’ve been just listing the current folder over and over, butlscan list any folder, likels Documentsorls Downloads, and that can be combined with flags, usually before the arguments, likels -lth Downloads.Okay, so that’s flags and arguments, but you may be wondering how do you know what flags are available and what they do? Two main options!
The first is called a “man page”, man being short for manual. Man itself is a command that opens essentially instructions for a command, in the terminal itself, and you can use the arrow keys to go up and down and “q” to quit. Try
man lsto see what is it’s got for you. You usually don’t need to read it to to bottom and understand everything, you normally just go looking for something in particular. You can also use/in man to search for something, like/sortto look for the word sort. And thennandNgo forward and back searching for the next and previous hit for that search. Alsoman -k searchwill search through the man pages looking for things that match, in this case, the term “search” and list you commands. You may want that for being like “there’s gotta be a way to do this, but I don’t know what the command is!”. Also man pages are sorted into sections, and contains more than just commands. So you only care a out the things in section 1 for now.The second way to get help is that most commands, but not all, will have a
-hor--helpflag that tells them to list their own help as output instead of what they normally do. Sols --helplists the options it supports.Quoting! You may have noticed the shell is sensitive to spaces. So imagine you had a folder with a space in the name. If you ran
ls My Folder, it would break that into two arguments,MyandFolder, and would try to find you the contents of both of those two folders, which would fail because they don’t exist! So to fix that we have two options: quoting and escaping. You can wrap it in quotes likels "My Folder"to tell the shell “this is all one unit, don’t break it up”, or you can “escape” the space by putting a backslash before it, likels My\ Folderto tell it “this next space isn’t a splitting one, so please include it in the argument”. The backslash won’t be there by the timelssees it, it’s just telling the shell how to split the arguments.And then pipes! Pipes are the killer feature of the shell, as they allow you to take the output of one command and make it the input of the next. And some commands are built with this in mind. Like
grep, which can search its input for things that match the pattern given as its argument. Likels Downloads | grep pdf, which will take the list of files we’re used to seeinglsoutput to us, and instead feed that togrepwhich will filter it down to just the pdfs. There’s a lot you can do with these pipelines, because you could then take the output ofgrepand pipe it to something else to further process it, etc.So that’s nowhere near everything, not even close, but it’s hopefully enough to be able to wander around the big wide world and know what the heck people are talking about, and at least how to read what you’re seeing.
Quick note! The command
rmmeans remove. It deletes files, and it doesn’t use a trash can or anything, they’re just gone. So be very careful with that one! And if some jackass out there tries to get you to runrm -rf /or some equivalent, DON’T DO IT. That stands for “remove” with the flags “recursive”, which means descend into child folders and keep going, and “force” which means delete things even if you shouldn’t. Then it has the argument of “/” which is the root of your filesystem, meaning a recursive operation on that will effect every file on your computer. So essentially this command deletes all files on your machine. Bad. 😅Here’s some quick notes to give words to other things you might see and have trouble looking up!
ls $HOME: the thing after theis an “environment variable”, which is some value your shell has stored and allows you to inject into the command. You can run theenvcommand to see what variables there currently areecho blahis a command that just outputs its args (argument is such a long word). It’s useful for injecting words into a pipeline, or outputting environment variables, likeecho $HOMEls ~/Pictures: The “tilde” is just a shortcut for your home folder, so it’s actually the same asls "$HOME/Pictures", but it’s so common to do things relative to your homedir, that it’s a shortcut.ls | less: the less command is great, because it takes its input and presents it in an interactive scrollable thing sometimes called a “pager”. This is actually whatmanuses to present its pages, so the same arrow keys andqapplies, but you can take any output and put it inlessls `echo Documents`orls $(echo Documents)are two equivalent ways of running a command in a subshell, and then having the result be itself and argument for the outer command. Soechospits out “Documents” as its output, but not to us. That output is then an argument tols, which just runs likels Documents. This is different than a pipe, but is a other way commands can be linked together to form larger units. The first one is called “back-ticks” by the way.sudo whoami:sudois a command that “does” something as “super user”. S U DO. It’s used to escalate your privileges. So maybe a normal user can’t install packages, butsudo whatevercan. The sudo command just asks your password and gets you access, the runs the rest of the command as-is. You’ll see this a lot in instructions people give.
I think that’s enough to get off the ground? Good luck!
sudois a command that “does” something as “super user”Fun fact, it originally stood for “superuser do”, however it now stands for “substitute user do” as it can “do” as any user - it’s just that the default user argument is root (IE super user)
For anyone coming later, I’d actually add a section between where you explain commands for the first time and where you explain their flags or at minimum directly after the flag section. The section should explain how commands are found, how the PATH works and where the majority of binaries on a Linux system are located. Knowing that will allow a reader to immediately understand how simple a shell is and how people are always able to write their own scripts for stuff.
Yeaaaaaaah, I wasn’t sure whether or not to put that somewhere or not, and eventually decided not. I devalued all env vars, which I would feel like I had to move up to get into the PATH. I love the path, and I do agree with you that is important for understanding how the system really works, and how you can add your own commands, but I guess I figure that’s a good Shell 201. For someone who wants to start using it, and isn’t sure what a grep is or why a cat is involved, I figure they’re not yet primed to care where these things live on their disk.
But soon after, for sure! And obviously others can disagree with me.
Wow. I think that is indeed quite enough to get off the ground. Thank you for compiling this information in such a readable manner! 😀
I would not say that reading a book is the way to go about it. At least the way I learned was just through using my computer like normal, and naturally I ended up using the terminal for some things e.g. updating packages, doing simple operations like moving files around, etc. I don’t think it’s a good idea to specifically try to “learn the command line” as a directed/targeted goal, because like you said you could end up learning a bunch of stuff you never use.
there’s an android app which I’ve found extremely useful. “Linux command library” it’s like a dictionary for linux commands ❤️
you can find it on F-droid
man man
Exciting you’re interested in the terminal. Personally I find it an invaluable tool, it’s powerful and versatile, suitable for almost any task. So as you learn, I’d encourage you to be concious about what you find interesting or fun, whether it is the coding-, problem solving-, automation-part, or an entiely different aspect.
There are several gamified introductions to programming, scripting and using the shell, which may be a good start. Some of my favourites (off the top of my head) are:
- “The Bandit” on Over the Wire to get familiar with the basics of the shell (terminal).
- Rustlings a collection of small exercises, and a great intro to tge Rust programming language
If you’ve already done a bit of programming, you can think of the terminal as a place that executes code. Just look at some bash scripts, and you’ll probably find it somewhat familiar.
Just like you can load new libraries, you can also install new commands on your system. You can think of each program as a function in some programming language such as Python.
I would suggest easing yourself into it. Since you’re in Mint start off with just installing and uninstalling programs via the terminal. If you really want to get into terminal use what helped me was this. “is there a GUI that I use a lot that I could potentially do from the terminal? lets research how.” So for example instead of using a package manager, use the terminal. Instead of using a file manager use the terminal with something like Yazi or Ranger and then from there you can use the terminal to manage files quite easily.
Want to unzip something? instead of doing it via the file manager look up how to do it via the terminal. need to empty your trash bin? same deal.
Instead of trying to learn everything at once when you’re doing something on your machine think to yourself “could I do this via the terminal?” and then look it up.
As far as programming goes I still firmly believe there’s nothing better out there than Vim/Neovim or Emacs/Doom Emacs. If you want to go that route instead of using Vim checkout Neovim with Lazyvim. both are extremely easy to install. OR if a total package and then some is what you’re looking for check out Doom Emacs. I use Doom Emacs currently for all my dev work and I love it. on my server I use Neovim just because it’s a bit faster since I have to SSH into it and it’s offsite.
Really like this take. I do move a lot of files between directories, so I could look into copying, cutting, and pasting things via the terminal.
I think learning my way around Neovim also couldn’t hurt. I was planning on setting up a little webserver at home, and accessing it remotely sounds pretty handy.
yup that’s the way to go. just whatever you want to do think “can I do this via the terminal?” and it’ll all flow from there.
AND if you start using Neovim you’ll start getting addicted to vim style navigation and want to apply it to everything…which you can for a lot of things. you’ll then find that using vim nav and doing things via the terminal is a lot faster than using your mouse in a GUI.
As far as vim goes I’ll say it’s not really necessary to learn but it’s a good tool to have in your belt. I once tried to print the manual to vim but noped out after about 100 pages. I’d say learn how to navigate, edit, copy-paste, find and replace text in vim. You could go all the way to do crazy things like running a CLI command from within vim and put the result into the editor but from a desktop environment it isn’t as helpful compared to simply having two terminal instances open.
https://tldp.org/LDP/abs/html/ https://www.shellhacks.com/
https://wiki.archlinux.de/title/Shell-Spickzettel
https://github.com/onceupon/Bash-Oneliner
https://devhints.io/
https://docs.linuxfabrik.ch/base/system/bash-scripting.html#snippets
https://cheatsheets.stephane.plus/
https://quickref.me/
https://github.com/LeCoupa/awesome-cheatsheets?tab=readme-ov-file
https://blog.desdelinux.net/en/more-than-400-commands-for-gnulinux-that-you-should-know/Maybe a short introduction what the terminal actually is. Programs are a bunch of code that runs on your computer. With many of that programs you as the user want to interact with. The point of contact between the program and you (and actually other programs) is called an interface. Some programs have a graphical interface (GUI - graphical user interface). Other programs have a Comand line interface (CLI). Writing a CLI is a lot easier than a GUI and it works on a lot more different systems. So many programs chose to only have a CLI while some only have a GUI and some have both. The terminal is your way to access those CLIs. And some problems are a lot easier to solve with a CLI than with a GUI. Maybe a function in a GUI is in a few menues deep so you need to click a lot to get there, and then use a slider to set a value, then click accept, etc. In a CLI, it is just one word you have to type. Especially in Linux a lot of developers are not designers so they write programs with good CLIs but bad (or none) GUIs. Especially when it comes to system settings sometimes there is no GUI to achieve what you need. So when you open the terminal, don’t think that you are diving in to a whole new magic world, but just that you are taking a different route to talk to the same programs that you were using already, and some new ones that you didn’t knew before.
Maybe just to take some of the mystique away, take a program you are used to (maybe Firefox?) and call that from the CLI. Type “firefox --help” and see the options that you have available there and compare them to what you know from the GUI. Most things will be in both but maybe some are very well hidden in the GUI.
After that it is just getting used to the utilities that you have for the terminal, all the little programs like “cd, ls, pwd, cp, mv”, etc… They are just programs that do things you are used to do with your mouse in the file explorer. Just the CLI analog to “select, right click, copy, paste”. Since CLIs are text based you also have a lot of utilities to handle text like grep, sed, cut, tr, they just do what you were doing in a text editor.






