Sunday, February 17, 2019

How to Linux or Something Like That

I am by no means a Linux expert, but at work I am the one they tend to defer to with "how do I Linux" questions. So maybe it would be worthwhile to make a small beginner guide on how to at least pretend you know what you're doing. So let's get out the basic "gotchas" of Linux and some semantics.

Linux is a kernel. Linux is to Ubuntu (or whatever you flavor is) as Windows NT is to Windows 7. I sometimes com across those snarky "Linux isn't an OS" comments online and it gets annoying, but this is the brief explanation to those.

Linux itself comes in different distributions referred to as "distros" or "flavors." If you're gonna talk about Mint, flavors seems like the better term, although it may get weird when you talk about Puppy being your favorite flavor. Sometimes different distributions are just the same one with a different desktop environment (DE) or software pre-loaded on it. Some desktops include things like Gnome, KDE, X11, xfce, MATE, LXQt, etc. There are a lot of desktop environments. To further add to some confusion, there are also window managers (WM) like xmonad, i3, and a million other ones. When discussing with others the environments they use, it can get complicated and layered because everyone uses a million and one things just to stick two windows on the screen at just the right location and spacing.

Personally, I use things mostly default because I often have to move around to a lot of different environments. I use CentOS minimal (no DE), Kali, Windows 7, Windows 10, Mac OSX Sierra, Ubuntu and various derivatives of, just to name a few.

If you're looking to pick the right distro for you, you can check out Distro Watch, they keep up to date on everything. Browsing there, you can find quite literally hundreds to choose from. Each one varies to some extent with the file structure, commands, or general way of doing things.

One of the big things for people starting out is the package manager. Without being able to install software, there are limitations for those that don't just make things themselves and package managers are the biggest help. It's one of the things that I loved when starting out with Linux. You can download or keep up-to-date all of your software in a simple manor. Each distro has its own way of doing things. Debian based has aptitude, RedHat based has yum, Arch based has pacman, and so on. Most have some form of package tool and special format.

I'm on Kali right now, so if I want to update all of my stuff, I may do something like:

apt-get update && apt-get upgrade -y

This is really dependent on what distro you're on, what kind of updates you're getting (like if you're on a rolling distro), and the like.

Now a brief look at file structures. The root file is /. It contains a handful of folders such as bin (user binaries), boot (boot files), dev (device files), etc (configuration files), home (user folders), lib (libraries), mnt (mount), opt (optional apps, usually ones you install outside of a package manager will end up here), proc (process information), root (root user, not to be confused with the file root), sbin (system binaries), srv (service data), tmp (temporary files), usr (user programs), and var (variable files such as logs, default web root for web services, etc.). Chances are you actually have many more than that, and it all depends on the distribution. I'm personally a fan of how Linux handles devices in the dev folder allowing you access to devices in similar ways you interact with files.

Shells. Your shell on a Linux system is an invaluable tool for when all else fails. Knowing how to use it is immensely helpful, and customizing it to make it your own is very satisfying. Most variations seem to default to Bash (Bourne Again Shell), based off of the Bourne Shell. There are numerous other variations such as Korn shell (ksh), Almquist Shell (ash), Dash (default for recent debian distros), C shell (csh), tcsh (unix compatible c shell that Mac used for a while), Friendly Interactive shell (fish), Z shell (zsh), and many more. Most of them have cross compatibility with minor changes here and there for syntax and the big distinction being how they handle interactive sessions.

Personally, I use zsh with Oh-my-zsh!, and tmux (a terminal multiplexer) when I'm getting down and dirty. For scripting, I stick to good ol' Bash... or Python or Tcl, depends on what I'm doing really. Tcl seems to pop up at random and I use it at work for a custom backup script for the many switches we have (with expect).

Some of the more basic things you would do to get started on Linux and really grab into the shell is basic file navigation and text editing. When it comes to text editing, I love Vim. My favorite thing about Vim/Vi is how quick and easy it is to do stuff when you know what you're doing. My second favorite things is when people copy a command with vi or vim in it and have no idea what they're doing. You see kids, Vi is a visual text editor that requires knowing commands in it to edit, save, and even exit it. There is also nano, which is to speed with most newcomers, but not every distro comes with it. So let's go over a quick and incomplete Vi/Vim lesson!

To quit the program you type :q
To move the cursor, you can use arrows or h (left), j (down), k (up), l (right)
To insert text (go into insertion mode), i inserts on the cursor, a inserts after, I inserts at the very beginning, A at the very end of the line
To stop inserting, press esc
Backspace doesn't always work, delete always does, x will delete when not in insertion mode
To save you type :w
To save and quit you can type :wq or :x
To quit without saving, you type :q!

There are also ways to copy and paste, regex substitute, find, and all sorts of things. If you start getting used to it now, you can soon start to learn all the other cool things.

Let's say we want to edit the hostname on a computer. We do something along the lines of:

cd /etc
vim hostname

Then press i, type in the hostname, press esc, then :wq
We can then restart the computer. So what are some quick and easy commands to get started?

cd <directory> (change directory)
mkdir <directory> (make directory)
touch <file> (create a file)
rm <file> (remove a file)
cp <file1> <file2> (copy a file)
mv <file1> <file2> (move or rename a file)

There are a lot of commands, and it changes from system to system to some degree. Without getting into one specifically, it's hard to go too in-depth.

So how do you pick a distro for you to get started? Major distributions are a good start with the large communities and lots of documentation and tutorials. Ubuntu, Mint, CentOS, Debian, Fedora, Manaro are just a handful of some of the major ones. I personally started out with Ubuntu. With Ubuntu I could do everything with GUI and introduce myself into command line stuff at my own pace. After that, I learned how to configure and run systems entirely from the command line.

No comments:

Post a Comment

Tag Cloud

.NET (2) A+ (5) ad ds (1) addon (4) Android (4) anonymous functions (1) application (9) arduino (1) artificial intelligence (1) backup (1) bash (6) camera (2) certifications (3) comptia (5) css (2) customize (11) encryption (3) error (13) exploit (5) ftp (1) funny (4) gadget (4) games (3) GUI (5) hardware (16) haskell (6) help (14) HTML (3) imaging (2) irc (1) it (1) java (2) javascript (13) jobs (1) Linux (19) lua (1) Mac (4) malware (1) math (6) msp (1) network (13) perl (2) php (3) plugin (2) powershell (8) privacy (2) programming (24) python (10) radio (2) regex (3) repair (2) security (16) sound (2) speakers (2) ssh (1) story (5) Techs from the Crypt (5) telnet (1) tools (13) troubleshooting (11) tutorial (9) Ubuntu (4) Unix (2) virtualization (2) web design (6) Windows (16) world of warcraft (1) wow (1) wx (1)