Welcome to the first of four parts of the Linux basics tutorial, designed to prepare you for the Linux Professional Institute 101 exam. You will learn about bash (the standard shell of the Linux command interpreter), learn about most of the features of standard Linux commands such as ls, cp and mv, understand inodes, hard and symbolic links, and much more. By the end of this tutorial, you will have formed a certain foundation of knowledge, and you will be ready to learn the basics of administering Linux. By the end of the course (8 parts), you will have enough skills to become a Linux system administrator and get LPIC Level 1 certification from the Linux Professional Institute, if you want to.
This first part of the tutorial is great for new Linux users, as well as for users who want to refresh or improve their understanding of the fundamental concepts of Linux, such as copying and moving files, creating symbolic and hard links, and standard text processing commands, including pipelines and redirects. Along the way, we will also give a lot of tips, tricks, and tricks, which makes this tutorial rich and practical, even for those who already have solid Linux experience. For beginners, much of this material will be new, but more advanced Linux users will find this guide to be an excellent tool to lay out their fundamental skills on the shelves in their heads.
Those who have studied the first version of this manual for a purpose other than preparing for the LPI exam may not need to reread it. However, those who plan to take exams should definitely look through this revised version.
If you have already used Linux before, you probably know that after logging in, you are welcomed by an invitation that looks something like this:
$In practice, the invitation you see may be slightly different. For example, it may contain the host name, the name of the current working directory, or all together. Regardless of how your prompt looks, there is one undoubted thing: the program that displays this prompt is called the shell of the command interpreter, and, most likely, All in all, your command shell will be 'bash'.
You can verify that you are using bash by typing:
$ echo $SHELL
/bin/bashIf the line above gives an error, or the answer does not match, it is possible that you started another shell. In this case, much of this tutorial will still be useful, but it would be much better for you to switch to bash for the sake of preparation for exam 101.
Bash is an acronym for Bourne-again-shell, from English. "Still-one-command-shell-bourne" or "born-again-command shell" (here a pun on the word Bourne / born - lane), and is the default shell for most Linux-based systems. The task of the shell is to receive commands from you through which you interact with the Linux system. After you have finished entering commands, you can exit the shell (exit) or end the session (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.
You may have already discovered that staring at bash is not the most impressive thing in the world. Well, let's learn how to travel through our file system. At the invitation, please enter the following command (without $):
$ 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 tree-shaped, 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. lane). cd sets the directory in which you are currently working, also known as the “current working directory”.
To find out the current working directory in bash you need to type:
$ pwd
/In the example with cd, the argument / is called a path. He tells cd where we want to go. In particular, the argument / is an absolute path, which means that it specifies the location relative to the root of the file system tree.
Below are a few of them:
/dev
/usr
/usr/bin
/usr/local/binAs you can see, all absolute paths have one thing in common, they start with /. Specifying, say, / usr / local / bin as an argument for cd, we announce that we want to go to the / directory, then to the usr directory inside it, and so on to local and bin , down the tree. Absolute paths are always counted from / first.
Another type of path is called “relative path”. bash, cd, and other commands always interpret them relative to the current directory. Relative paths NEVER begin with /. So, if we first move to / usr :
$ cd /usrSo, then we can use the relative path local / bin to get to the / usr / local / bin directory :
$ cd local/bin
$ pwd
/usr/local/binRelative paths may also contain one or more ".." directories. The ".." directory is special; it points to the parent directory. So, continuing with the example above:
$ pwd
/usr/local/bin
$ cd ..
$ pwd
/usr/localAs you can see, our current directory is now / usr / local . We were able to move "back" to one directory relative to the current, where they were before.
In addition, we can also use ".." in the existing relative path, which allows us to move to the directory "next" to the one in which we are:
$ pwd
/usr/local
$ cd ../share
$ pwd
/usr/shareRelative paths may be a bit more complicated. Below are a few examples, try to guess for yourself where you will find yourself after typing each of these commands.
$ cd /bin
$ cd ../usr/share/zoneinfo
$ cd /usr/X11R6/bin
$ cd ../lib/X11
$ cd /usr/bin
$ cd ../bin/../binNow type them in and test your assumptions. ;)
Before we finish exploring cd, there are a few points that need to be clarified. Firstly, there is another special directory ".", Which means "current directory". Although it is not used with the cd command, it is often used to execute a program from the current directory, as in the following example:
$ ./myprogIn this case, the myprog executable program running in the current working directory will be launched.
If we wanted to move to our home directory, we could type:
$ cdWithout any arguments, cd will move to your home directory, which will be / root for the superuser, or usually / home / username (for where the username is the username in the system - for example) for any other user. But, what if we want to specify a file in our home directory? Maybe we want to pass the file path as an argument to our myprog program. If the file is located in our home directory, we can type:
$ ./myprog /home/drobbins/myfile.txtHowever, using an absolute path like this is not always convenient. Fortunately, we can use the ~ (tilde) symbol to do the same:
$ ./myprog ~/myfile.txtBash will take 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 refer to a file called fredsfile.txt in the home directory of the user fred , we could type:
$ ./myprog ~fred/fredsfile.txtDaniel Robbins is the founder of the Gentoo community and the creator of the Gentoo Linux operating system. Daniel lives in New Mexico with his wife, Mary, and two energetic daughters. He is also the founder and head of Funtoo , has written many technical articles for IBM developerWorks , Intel Developer Services and the C / C ++ Users Journal.
Chris Hauser was a UNIX supporter since 1994 when he joined the team of administrators at Taylor University (Indiana, USA), where he received a bachelor's degree in computer science and mathematics. After that, he worked in many areas, including web applications, video editing, drivers for UNIX, and cryptographic protection. Currently working in Sentry Data Systems. Chris also contributed to many free projects, such as Gentoo Linux and Clojure, co-authored The Joy of Clojure .
Airon Griffis lives in Boston, where he spent the last decade working with 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. In his spare time, Airon prefers to ponder over the problems of programming while riding his bike, juggling bits, or cheering on the Boston Red Baseball team.
Source: https://habr.com/ru/post/99041/
All Articles