Command Line 101: feel the power of the UNIX Shell!
Rationale
I'm about to start a serie to give you people tips and tricks on UNIX/Linux shell, aka Command Line Interface.
This might be of use for anybody who'd like to be more in control of her/his Operating System, and you'll be surprised to actually do things a lot faster using the CLI than clicking on buttons.
The goal here is not to write a complete, boring book as they exist in a million forms, I want to keep those posts simple and comprehensive. This first one might be longer in order to setup the landscape ;)
Fire up the shell!
First thing first, if you are not (yet) a Linux user, get yourself a copy of a friendly Linux Distribution like Linux Mint or Ubuntu Linux. No distro war here, I'm only giving those two examples as easy to run versions of Linux. Hardcore sysadmins, hackers and pros might prefer Debian GNU/Linux, ArchLinux or even a true UNIX system like FreeBSD, NetBSD or OpenBSD.
Once on the desktop, find out an icon similar to the following on your menu, usually under "System tools", often called "Terminal"
And there you go, a shiny new
shell
at your fingertips:Don't worry, when the time comes I'll show you how to get a nice shell prompt ;)
The first command
Now your first lesson: to cleanly exit from a terminal or more generally a shell session, simply type exit
or logout
or press Control
+D
, often referred to as ^D
.
Let's start with very basic commands:
$ ls
Desktop Documents Downloads Games
Music Pictures Public Templates
Videos
That's right, ls
lists the content of the current directory. A couple of useful tips:
- Every command has an associated
manpage
, a curated documentation about the command usage. It is invoked by the following sequence:
man ls
you can exit from man
by hitting the q
key.
- Commands usually accept parameters that will modify their behavior. For instance,
ls -l
will print more detailed information about the file list:
$ ls -l
drwxr-xr-x 2 imil imil 4096 Jun 12 08:32 Desktop
drwxr-xr-x 22 imil imil 4096 Jun 19 23:17 Documents
drwxr-xr-x 17 imil imil 4096 Nov 20 2016 Dolphin Emulator
drwxr-xr-x 2 imil imil 12288 Jun 24 12:57 Downloads
...
- Commands usually have a
-h
or--help
modifier flag which will show you available options and basic usage
Important note normal commands output is displayed to stdout
, or "standard output", error messages are displayed to stderr
or "standard error" and input is taken from stdin
or "standard input". Those three are called file descriptors
, we won't go through them right now as I want to keep this first course easy and straightforward.
Next up on my channel
In our next episode, if there is enough audience, I'll go through "piping", or how to filter one command with another.
Do you like this kind of HOWTO? Want me to continue the same path? If yes, please follow, share and comment!