What is Linux?

Linux is a kernel. A kernel is the core of the operating system that is responsible for starting/stopping other programs, handling requests for memory, accessing disks, and managing network connections. Abstractly, people use the term Linux to refer to a given Linux Distribution which is defined as a collection of software (with the Linux Kernel at the core) that together makes an operating system. Linux is a multitasking, multi-user, multipurpose operating system and the largest collaborative project in the history of humankind. Linux is a modular system which means that all its components are separate from each other which is what makes it the preferred operating system for embedded devices. Linux is the most used operating system in the world because most web servers run on Linux. In addition to its dominance in the Internet’s backbone, Android, Chromebooks (and other Google devices), Amazon fire devices, even Tesla cars use the Linux Kernel in their operating systems.

linux devices

A complete Linux system package is called a Linux Distribution. There is over 150 Linux distribution available to meet any computing requirement you could have. There are two main Linux distributions that branch out most of the other distros out there: Debian and Redhat. There are other independent distros like Slackware and Arch Linux. The main difference between distribution is the way they package and manage software. There are other differences like the init system. However, since they all share the same Kernel, they have more in common than they differ. Most Linux distributions follow the Filesystem Hierarchy Standard and pack the Bash shell as the default shell.

Basic Linux Commands

Moving Around The filesystem

A filesystem defines the way files are stored and organized in an operating system. Linux, like Unix, has a root directory from where all the files are arranged. Linux follows the Filesystem Hierarchy Standard (FHS) which specifies requirements and guidelines for file and directory placement in UNIX-like operating systems.


Before you start leaning the Linux Command Linux Interface (CLI), it is important to understand the concept of absolute and relative paths. A file path is a unique location to a file or a folder in a file system. An absolute path is defined as the specific location of a file starting at the root of the file system. A relative path on the other hand, starts with a directory that is related to the present working directory. to better ilustrate this concept, lets asume that you want to open a file located in the Downloads directory. The file name is games.txt. The absolute path of games.txt is: /home/user/Downloads/games.txt. If your present working directory is your home directory, the the relative path to games.txt is: Downloads/games.txt. Absolute paths can be used anywhere in the filesystem while relative path only work from the directory that they are relative to.

To navigate the filesystem from the CLI all you need to know are 3 commands: pwd, cd, and ls. The pwd command displays the present working directory. Pwd is used to know where you are at any time. The cd command is used to change from one directory to another. Cd is the main movement command since it allows you to change your present working directory. The cd command can use absolute path, regular path, or no path at all if the user wants to go to their home directory. Sometimes you want to see whats inside a particular directory. This is called listing the content of a directory. Other times you want to see some information about a file or a directory such as the size of the file or who owns it. For all of these scenarios we use the ls command.

PWD Examples:
CD Examples:
LS Examples:

Managing files and directories

Now that you know how to move around the filesystem, it is time to learn how to manage files. File management in the CLI involves creating files/directories, moving and copying files, and removing files and directories.

mkdir is used for creating a single directory or multiple directories.To create a directory with mkdir type: mkdir + the name of the directory. To create multiple directories, separate each directory name with a space. You can create directories in the present working directory or in a different directory by using an absolute path or relative path. You can create a directory with a space in its name using the escape character (\) or by surrounding the name in quotation marks (‘ ‘ or “ ” ). If you try to create a directory that already exists, you will get an error notifying you that the file already exists.

MKDIR Examples:

To create files we use the touch command. Although the touch program was not designed for creating files (in fact it is an unintended result) it was designed for updating files accesses time.

TOUCH Examples:

To remove files we use the rm command. Rm by default does not removes directories. To remove a directory use rm with the -r option. In Linux and other Nix systems you cannot remove non empty directories. To remove empty directories use the rmdir command. To remove non-empty directories use rm -r + directory name or directory absolute path.

RM Examples:

Part of working with files is moving them around. For this purpose we use the mv commad. Also, the mv command is used for renaming files. When you want to move a file from one place to another, you use the mv command with the following formula: mv + source file(s) + destination. When you want to rename a file, you can use the same formula. Mv can move and name files at the same time.

Mv Examples (Moving files and directories)

MV Examples (renaming files)

What if you want to copy the files instead of moving them? in this case we use the cp command. The cp command follows the same formula as the mv command: cp + files to copy + destination. When moving directories cp commands requires the -r or -R argument.

CP examples:

Working with text files

Working on the CLI involves more than just shuffling files around. In Linux, everything can be done on the command line and one of the greatest strength of the CLI is its large amount of commands that can be used to work with text files.

The Cat Command

The cat command is short for concatenate and it is used for concatenating files and displaying the content of a text file. To use the cat command follow this formula: cat + option + filename

CAT Examples:

The Tac Command

The tac command is used for concatenating and displaying the content of a file in reverse order. To use the tac command, use the following formula: tac + option + file name

The more and less commands

Both more and less are pager programs. A pager program is used for loading the output of a large program or a text file one page at the time. To use the more use the following program: more + option + file or command output To use the less command use the following formula: less + file

Examples of the more and less command

TAC Examples:

The Head Command

Displays a given number of lines or bytes of a file. If no option given it displays the fist 10 lines of a file. To use the head command, use the following formula head + option + file

HEAD Examples:

The Tail Command

Displays the last 10 lines of a given file.

TAIL Examples:

The Cut Command

The cut command is used to extract a specific section of each line of a file and display it to the screen. To use the cut command, use the following formula: cut option + file

CUT Examples:1

The paste command

The paste command is used to joing files horizontally in columns. To use the paste command use the following formula: paste option + files

PASTE Examples:

The sort command

The sort command is used for arranging a text file in a particular order. The sort command is used for arranging a text file in a particular order. The sort command arranges a file line by line. Sorting works in the following way:

To use sort command, follow this formula: sort + option + file

Examples of the sort command

The wc command

The wc command is used for printing the number of lines, characters, and bytes in a file. To use the wc command,follow this formula: wc option + file

WC Examples:

The tr command

The tr command is used for translating or deleting characters from standard output. To use the tr command use the following formula: command output | + tr + option + set + set

Regular Expressions character classes:
POSIX class Represents Means
[:upper:] [A-Z] Upper case letters
[:lower:] [a-z] Lower case letters
[:alpha:] [A-Za-z] Upper and Lower case letters
[:alnum:] [A-Za-z0-9] Lower case, upper case, and digits
[:digit:] [0-9] digits
[:xdigit:] [0-9A-Fa-f] hexadecimal digits
[:punct:] [.,!?:...] puctuation
[:blank:] [\t] space and tabs
[:cntrl:] n/a control characters
[:graph:] [^\t\n\r\g\v] printed characters without spaces
[:print:] [^\t\n\r\g\v] printed characters including spaces
[:space:] [ \t\n\r\g\v] whitespace characters
TR Examples:

The diff command

The diff command comparares files and display the differences between them. To use the diff command, follow this formula: diff option + file + file

DIFF Examples:

The find command

The find command is used for finding files in your system. To use the find command, follow this formula: find + start directory + option + file name to search

FIND Examples:

The sed command

The sed command is stream editor used for filtering and transforming text. To use the sed command, follow this formula: sed + option + sed command + file

SED Examples:

The Awk command:

Awk is a scripting language used for processing and displaying text. Awk can work with a text file or from standard output. Awk was created in Bell Labs during the 70s by Alfred Aho, Peter Weinberger, and Brian Kernighan and its name comes from its authors' initials. There are several implementations of Awk: nawk, mawk, gawk, and busybox.
From Stackoverflow by the user: Gilles 'SO- stop being evil'.

To use awk, follow this formula, awk + options +a ction with or without selection +file or standard output redirection +file to save (optional)

AWK Examples: