this post was submitted on 12 Dec 2025
45 points (95.9% liked)

Linux

10570 readers
451 users here now

A community for everything relating to the GNU/Linux operating system (except the memes!)

Also, check out:

Original icon base courtesy of lewing@isc.tamu.edu and The GIMP

founded 2 years ago
MODERATORS
 

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.

you are viewing a single comment's thread
view the rest of the comments
[โ€“] psycotica0@lemmy.ca 24 points 1 day ago* (last edited 1 day ago) (4 children)

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, ls is 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 -l is ls run 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, so ls -lth is the same as ls -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-readable which 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 size which is usually the same as ls -l --sort=size but confusingly not the same as ls -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 ls up until now we've been just listing the current folder over and over, but ls can list any folder, like ls Documents or ls Downloads, and that can be combined with flags, usually before the arguments, like ls -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 ls to 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 /sort to look for the word sort. And then n and N go forward and back searching for the next and previous hit for that search. Also man -k search will 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 -h or --help flag that tells them to list their own help as output instead of what they normally do. So ls --help lists 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, My and Folder, 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 like ls "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, like ls My\ Folder to 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 time ls sees 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. Like ls Downloads | grep pdf, which will take the list of files we're used to seeing ls output to us, and instead feed that to grep which 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 of grep and 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 rm means 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 run rm -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 the $ is an "environment variable", which is some value your shell has stored and allows you to inject into the command. You can run the env command to see what variables there currently are
  • echo blah is 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, like echo $HOME
  • ls ~/Pictures: The "tilde" is just a shortcut for your home folder, so it's actually the same as ls "$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 what man uses to present its pages, so the same arrow keys and q applies, but you can take any output and put it in less
  • ls `echo Documents` or ls $(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. So echo spits out "Documents" as its output, but not to us. That output is then an argument to ls, which just runs like ls 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: sudo is 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, but sudo whatever can. 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!

[โ€“] krh@programming.dev 3 points 1 day ago* (last edited 9 hours ago)

Wow. I think that is indeed quite enough to get off the ground. Thank you for compiling this information in such a readable manner! ๐Ÿ˜€

load more comments (3 replies)