Linux fundamentals. Linux Basics

Linux Essentials

Have questions about working with Linux? Do you want to switch to using this system, but have doubts? Is your goal to quickly and fully master Linux to effectively solve professional problems? The teachers of the Specialist Center will help you with this.

Every year Linux becomes more and more popular in the world. And it’s not just about the colorful penguin – the symbol of this operating system. Linux is free, reliable and confidently safe from the point of view of viruses - all supercomputers and many server systems run on it, it is simple and intuitive to use - a user-friendly interface, loads quickly, which is nice, and does not require frequent updates, which is the sin of Windows.

We invite you to study Linux in a course developed by the flagship of the IT industry - Cisco. The training program consists of 16 modules, which allows you to fully master the operating system. The theoretical part is immediately reinforced in laboratory classes.

Well "Linux Basics" reveals the basic principles of working in this operating system and the CLI interface, the basic concepts of open source code. The training focuses on practical tasks: access to a Linux virtual machine is provided, which allows you to study and test commands in practice CLI Linux.

The course will be of interest to high school students, university students, IT specialists, and anyone who wants to use one of the most popular operating systems in their work.

Master Linux - a convenient and secure operating system. Become a pro not only in Windows. Strengthen your position in the labor market.

About this guide

Welcome to the first of a four-part Linux Basics tutorial designed to prepare you to take the Linux Professional Institute 101 exam. In it, you'll become familiar with bash (the standard shell shell in Linux), and learn most of the capabilities of standard Linux commands such as ls, cp and mv, you will understand inodes, hard and symbolic links, and much more. By the end of this guide, you will have built a foundation of knowledge and will be ready to learn the basics of Linux administration. By the end of the entire course (8 parts), you will have enough skills to become a Linux system administrator and pass the LPIC Level 1 certification from the Linux Professional Institute, if you want to.

This first part of the tutorial is great for those new to Linux, as well as for those users who want to refresh or improve their understanding of fundamental Linux concepts, such as copying and moving files, creating symbolic and hard links, and standard text processing commands, including pipelines and redirects. We'll also cover plenty of tips, tricks, and tricks along the way, making this guide rich and practical, even for those who already have a solid amount of Linux experience. For beginners, much of this material will be new, but more advanced Linux users will find this guide a great way to get their fundamental skills straight in their heads.



For those who studied the first version of this manual for a purpose other than preparing for the LPI exam, you may not need to re-read it. However, those who are planning to take exams should definitely review this revised version.

Introduction to bash

Shell

If you've used Linux before, you probably know that when you log in, you'll be greeted with a prompt that looks something like this:

In practice, the prompt you see may be slightly different. For example, it may contain the hostname, the name of the current working directory, or both. Regardless of what your prompt looks like, one thing is certain: the program that displays that prompt is called a shell, and most likely In general, your command shell will be "bash".

Are you running bash?

You can make sure you are using bash by typing:

$ echo $SHELL
/bin/bash

If the line above gives an error or the answer doesn't match, you may be running a different shell. In that case, most of this tutorial will still be useful, but it would be significantly better for you to switch to bash for the sake of preparing for the 101 exam.

About bash

Bash is an acronym for Bourne-again-shell, from the English. "another-Bourne-shell" or "born-again-shell" (a pun on Bourne/born), and is the default shell for most Linux systems. The shell's job is to receive commands from you through which you interact with the Linux system. Once you have finished entering commands, you can exit the shell (exit) or logout, in which case you will see a login prompt.

By the way, you can also exit the bash shell by pressing control-D at the prompt.

Using "cd"

You may have already discovered that staring at the bash prompt isn't the most impressive thing in the world. Well, let's find out how to navigate our file system. At the prompt, please enter the following command (without the $):

$ cd/

You just told bash that you want to work in the / directory, also known as the root directory; all directories in the system are in the form of a tree, and / is its top, i.e. root (in computer science, trees grow the other way around, the root is at the top, and the branches go down - approx. per.). cd sets the directory you are currently working in, also known as the "current working directory".

Paths

To find out the current working directory in bash you need to type:

$ pwd
/

In the cd example, the argument / is called the path. It tells cd where we want to go. Specifically, the / argument is an absolute path, which means it specifies a location relative to the root of the filesystem tree.

Absolute paths

Below are a few of them:

/dev
/usr
/usr/bin
/usr/local/bin

As you can see, all absolute paths have one thing in common: they start with /. Indicating, for example, /usr/local/bin as an argument to cd, we say we want to go to the / directory, then to usr directory inside it, and so on in local And bin, down the tree. Absolute paths are always counted from / first.

Relative paths

Another type of path is called a "relative path". bash, cd, and other commands always interpret them relative to the current directory. Relative paths NEVER start with /. So if we first move to /usr:

$ cd /usr

Then we can use a relative path local/bin to get to the directory /usr/local/bin:

$ cd local/bin
$ pwd
/usr/local/bin

Usage..

Relative paths can also contain one or more ".." directories. Directory ".." special; it points to the parent directory. So, continuing from the example above:

$ pwd
/usr/local/bin
$ cd..
$ pwd
/usr/local

As you can see, our current directory is now /usr/local. We were able to move “back” one directory relative to the current one, where we were before.

Additionally, we can also use ".." in an existing relative path, allowing us to move to a directory "next to" the one we're in:

$ pwd
/usr/local
$ cd ../share
$ pwd
/usr/share

Examples of relative paths

Relative paths can be a little more complex. Below are a few examples, try to guess for yourself where you will end up after typing each of these commands.

$ cd /bin
$ cd ../usr/share/zoneinfo

$ cd /usr/X11R6/bin
$ cd ../lib/X11

$ cd /usr/bin
$ cd ../bin/../bin

Now type them and test your guesses. ;)

Understanding.

Before we finish exploring cd, there are a few things that need to be cleared up. First, there is another special directory ".", which means "current directory". Although not used with the cd command, it is often used to execute a program from the current directory, as in the following example:

$ ./myprog

In this case, the executable program will be launched myprog, located in the current working directory.

cd and home directory

If we wanted to move to our home directory, we could type:

Without any arguments, cd will move to your home directory, which will be /root for superuser, or usually /home/username(Where username- username in the system - approx. per.) for any other user. But, what if we want to point to a file in our home directory? Maybe we want to pass a file path as an argument to our program myprog. If the file is located in our home directory, we can type:

$ ./myprog /home/drobbins/myfile.txt

However, using an absolute path like this is not always convenient. Luckily, we can use the ~ (tilde) symbol to do the same thing:

$ ./myprog ~/myfile.txt

Other user home directories

Bash will treat a single ~ as a pointer to your home directory, but you can also use it to point to other users' home directories. For example, if we wanted to reference a file called fredsfile.txt in the user's home directory fred, then we could type:

$ ./myprog ~fred/fredsfile.txt

About the authors

Daniel Robbins

Daniel Robbins is the founder of the Gentoo community and creator of the Gentoo Linux operating system. Daniel resides in New Mexico with his wife Mary and two energetic daughters. He is also the founder and CEO of Funtoo, and has written numerous technical articles for IBM developerWorks, Intel Developer Services, and C/C++ Users Journal.

Chris Houser

Chris Houser has been a UNIX advocate since 1994, when he joined the administrative team at Taylor University (Indiana, USA), where he received a bachelor's degree in computer science and mathematics. He has since worked in a variety of areas, including web applications, video editing, UNIX drivers, and cryptographic security. Currently working at Sentry Data Systems. Chris has also contributed to many free projects, such as Gentoo Linux and Clojure, and co-authored the book The Joy of Clojure.

Aron Griffis

Aaron Griffis lives in the Boston area, where he has spent the last decade working at Hewlett-Packard on projects such as UNIX network drivers for Tru64, Linux security certification, Xen and KVM virtualization, and most recently the HP ePrint platform. When he's not programming, Aaron likes to think about programming problems while riding his bike, juggling bats, or cheering on the Boston Red Sox professional baseball team.

Linux Basics

Linux is inspired by the Unix operating system, which appeared in 1969 and is still in use and development. Much of the internal workings of UNIX exist in Linux, which is key to understanding the fundamentals of the system.

Unix focused primarily on the command line interface, and Linux inherited this. Thus, the graphical user interface with its windows, images and menus is built on top of the main interface - the command line. Additionally, this means that the Linux file system is designed to be easily manageable and accessible from the command line.

Directories and file system

File systems in Linux and Unix are organized according to a hierarchical, tree-like structure. The top level of the file system is / or root directory . This means that all other files and directories (including other drives and partitions) are located inside the root directory. In UNIX and Linux, everything is considered a file - including hard drives, their partitions, and removable media.

For example, /home/jebediah/cheeses.odt shows the full path to the cheeses.odt file. The file is located in the jebediah directory, which is located in the home directory, which in turn is located in the root directory (/).

Inside the root directory (/) there are a number of important system directories that are present in most Linux distributions. The following is a list of shared directories that are located directly under the root directory (/):

Access rights

All files in Linux have permissions that allow or deny them to be read, modified, or executed. The super user "root" has access to any file on the system.

Each file has the following three sets of permissions, in order of importance:

    owner

    refers to the user who is the owner of the file

    group

    belongs to the group associated with the file

    other

    applies to all other users of the system

Each of the three sets defines access rights. The rights, and how they are applied to various files and directories, are given below:

    reading

    files can be displayed and opened for reading

    directory contents are available for viewing

    recording

    files may be changed or deleted

    the contents of the directories are available for changes

    execution

    executable files can be run as programs

    directories can be opened

To view and edit the permissions on files and directories, open the Applications → Accessories → Home Folder and right-click on a file or directory. Then select Properties. The permissions exist under the Permissions tab and allow for the editing of all permission levels, if you are the owner of the file.

To learn more about file permissions in Linux, read the file permissions page in the Ubuntu Wiki.

Terminals

Working at the command line is not as daunting a task as you would think. There is no special knowledge needed to know how to use the command line. It is a program like everything else. Most things in Linux can be done using the command line, although there are graphical tools for most programs. Sometimes they are just not enough. This is where the command line comes in handy.

The Terminal is located in Applications → Terminal . The terminal is often called the command prompt or the shell. In days gone by, this was the way the user interacted with the computer. However, Linux users have found that the use of the shell can be quicker than a graphical method and still holds some merit today. Here you will learn how to use the terminal.

The terminal was originally used for file management, and indeed it is still used as a file browser if the graphical environment does not work. You can use the terminal as a browser to manage files and undo changes that have been made.

Basic commands

View directory contents: ls

Team ls shows a list of files in different colors with full text formatting

Creating directories: mkdir (directory name)

Team mkdir creates a new directory.

Go to directory: cd (/address/directory)

Team CD allows you to go to any directory you specify.

Copying a file or directory: cp (which is the name of the file or directory) (where is the name of the directory or file)

Team cp copies any selected file. Team cp -r copies any selected directory with all contents.

Removing files or directories: rm (file or folder name)

Team rm deletes any selected file. Team rm -rf deletes any selected directory with all its contents.

Rename a file or directory: mv (file or directory name)

Team mv renames or moves the selected file or directory.

Finding directories and files: locate (directory or file name)

Team locate allows you to find a specified file on your computer. File indexing is used to speed up work. To update the index, enter the command updatedb. It runs automatically every day when the computer is turned on. To run this command, you need super user rights (see “The root user and the sudo command”).

You can also use wildcards to specify more than one file, such as "*" (match all characters) or "?" (match one character).

For a thorough more introduction to the Linux command line, please read the command line introduction on the Ubuntu wiki.

Editing text

All of the configurations and settings in Linux are saved in text files. Even though you most often can edit configurations through the graphical interface, you may occasionally have to edit them by hand. Mousepad is the default Xubuntu text editor, which you can launch by clicking Applications → Accessories → Mousepad on the desktop menu system.

Sometimes, Mousepad launched from the command line using the application gksudo, which runs Mousepad with administrative privileges, which allows you to change configuration files.

If you need a text editor on the command line, you can use nano- easy to use text editor. When running from the command line, always use the following command to disable automatic word wrapping:

Nano-w

For more information about how to use nano, refer to the guide on the wiki.

There are also quite a few other terminal-based editors available in Ubuntu. Popular ones include VIM and Emacs(the pros and cons of each are cause for much friendly debate within the Linux community). These are often more complex to use than nano, but are also more powerful.

root user and sudo command

The root user in GNU/Linux is the user which has administrative access to your system. Normal users do not have this access for security reasons. However, Ubuntu does not enable the root user. Instead, administrative access is given to individual users, who may use the "sudo" application to perform administrative tasks. The first user account you created on your system during installation will, by default, have access to sudo. You can restrict and enable sudo access to users with the Users and Groups application (see "Managing Users and Groups" for more information).

When you open a program that requires super user rights, sudo will require you to enter your password. This will ensure that malicious applications cannot damage your system, and will also remind you that you are about to perform actions that require extra caution!

To use sudo on the command line, simply type "sudo" before the command you want to run. After this you will be required to enter your password.

Sudo will remember your password for 15 minutes (by default). This feature was designed to allow users to perform multiple administrative tasks without being asked for a password each time.

Be careful when doing administrative tasks - you might damage your system!

Some other tips for using sudo include:

    To use the terminal as super user (root), type "sudo -i" at the command line

    The entire suite of default graphical configuration tools in Ubuntu already use sudo, so they will prompt you for your password if needed.

    When running graphical applications, "gksudo" is used instead of "sudo". This allows you to prompt the user for a password in a small graphical window. The "gksudo" command is handy if you want to install a start button Synaptic to your panel or something similar.

    For more information on the sudo program and the absence of a root user in Ubuntu, read the sudo page on the Ubuntu wiki.

It would probably be better to place this article somewhere at the beginning of the series, but we doubt that anyone would read it when starting to learn Linux. Now that you've completed our Linux tutorials and are familiar with how it works, we'd like to take this moment to talk about the philosophy behind the Linux operating system.

When we use the concept of “philosophy”, we do not at all mean questions like “what is the meaning of life” or “does God exist”, we rather mean what logic, what ideas underlay the creation of this omnipresent and living operating system .

As many of you already know, we are big proponents of the Linux operating system. And there are many reasons for this, which we talked about in the article on why every hacker should know Linux. Since Linux is probably ideal for hacking and many other tasks, we think it is important to understand the philosophy behind the Linux/Unix structure and model for any environment.

In this article, we will use the term Unix/Linux to refer to this operating system. Unix was the original, developed by Thompson and Ritchie. Linus Torvalds and his team reverse-engineered Unix.

Mac OS X, iOS, Android, Solaris, AIX, HP-UX and IRIX are all forms of Unix/Linux.

Red Hat, Ubuntu, Mint, Fedora, Debian, Slackware and SUSE are all Linux distributions. A Linux distribution is simply an operating system that uses the Linux kernel and adds its own additional components to it. These components include various applications, utilities, modules, and graphical interfaces.

This diversity of distributions can often be confusing and somewhat frustrating for newbies, but it's actually part of the beauty and power of Linux. Unix/Linux is designed to be flexible and portable, allowing users to work the way they want, rather than the way software developers force them to work.

Unix was first developed in the early 1970s by Dennis Ritchie and Ken Thompson at AT&T Labs. The fact that it is still in use after over 40 years tells us something about the quality, durability and efficiency of this operating system. These guys did it right! How many things do you know from the early 1970s in computing that are still around?

However, instead of fading into oblivion, this “ancient” operating system is gaining momentum almost every day. Chrome, Android, iOS, Linux and Mac OS X are based on this 40-year-old operating system. If we look at the fastest growing market (mobile devices), we see that it is dominated by Unix variants with iOS and Android accounting for over 91% of the market. It seems that the mobile market in the near future will consist of almost 100% Unix/Linux devices.

What is it about this humble operating system that has made it so durable and reliable? Let's look at some aspects of the Linux philosophy that have made it so successful.

Assumption that the user is tech savvy

The designers of Unix (and by extension Linux) made a radical assumption: users are computer savvy. We can't say the same about other operating systems. In many cases, operating system developers assume that we are ignorant, illiterate Neanderthals who need to be protected. Everything is completely different with Unix/Linux.

As one thoughtful person said: "Unix (Linux) is not designed to stop users from doing stupid things, because that would also stop them from doing smart things."

Wonderful! Couldn't have said it better!

Full control

One of the main reasons why hackers use Linux and only Linux is that it gives us complete control. Other operating systems try to hide some of their operations and features from us for fear that we will break something. Linux is completely transparent and allows us to see and use whatever we want.

Favoring tolerability over high efficacy

Unix was the first portable operating system, meaning it could be used on many different hardware platforms. It has worked well since Unix/Linux has been ported and compiled for nearly 60 hardware platforms. This has been the main reason for its durability and ability to adapt to the ever-changing technological environment.

Storing data in simple text files

Unix/Linux stores data in simple text files, unlike other operating systems. This makes the data as portable as the code itself. Almost all systems can import and use simple text files.

Using shell scripts to increase efficiency and portability

The use of shell scripts expands the capabilities of our applications. By writing a script, we can automate the use of an application to do something as many times as we need, just as we could use the capabilities of other applications at the same time. In addition, these scripts can be transferred to other systems without compiling them.

Allowing users to customize their environment

Unix/Linux was designed to allow the user to customize their work environment to suit their needs and tastes. Everything is controlled by the user, not the software developers. Unix/Linux just implements the mechanism of operation, but does not force you to do things in a certain way. This type of user adaptation can take many forms, including the use of graphical user interface (GUI) environments. There are many GUI environments available for Linux, including GNOME (installed by default on Kali and most widely used), KDE, Unity (used by default on Ubuntu), Sugar, Trinity, Xfce, Enlightenment, and many others. In most cases, no matter what GUI environment you have installed on your system by default, you can install and use absolutely any other one you want.

Creating a small and light core

To provide users with more options, new features are constantly being added to many operating system kernels, making them increasingly bulky. The main idea in the Unix/Linux models is to keep the kernel small and lightweight, but still allow developers and users to add components and modules to it as they see fit.

Use lowercase and short titles

Traditionally, Unix/Linux uses short names and commands and only lowercase ones.

Silence is golden

Unix/Linux commands generally won't tell you anything if you do everything correctly. This can be somewhat annoying for some new users when, for example, they copy a file from one location to another, and Unix/Linux doesn't say anything about it. You won't get any acknowledgment or a pat on the back.

Think about hierarchy

The Unix/Linux operating system was the first to develop a file system organized in a hierarchical tree. This hierarchical thinking extended to many other areas of the operating system, such as networking and object-oriented programming.

Hopefully this little introduction to Linux philosophy will help you understand why it is so different from other operating systems. The result of this philosophy is a small, lightweight and flexible operating system that respects its users.