How to working linux

Linux Tutorial

Welcome!

Ok, so you want to learn how to use the Bash command line interface (terminal) on Unix/Linux. Or, it’s part of a subject you’re doing and so you’re learning it because you have to. Either way, that’s great. You’re learning how to use a powerful tool that can make your life easier, and make you awesome (more so than I’m sure you already are).

Introduction

Working through this beginners guide to the Linux command line (BASH) you will be up and running utilising powerful techniques, tips and tricks to make your life easier in no time. The following pages are intended to give you a solid foundation in how to use the terminal, to get the computer to do useful work for you. You won’t be a Unix guru at the end but you will be well on your way and armed with the right knowledge and skills to get you there if that’s what you want (which you should because that will make you even more awesome).

Here you will learn the Linux command line (Bash) with our 13 part beginners tutorial. It contains clear descriptions, command outlines, examples, shortcuts and best practice.

At first, the Linux command line may seem daunting, complex and scary. It is actually quite simple and intuitive (once you understand what is going on that is), and once you work through the following sections you will understand what is going on.

Unix likes to take the approach of giving you a set of building blocks and then letting you put them together. This allows us to build things to suit our needs. With a bit of creativity and logical thinking, mixed in with an appreciation of how the blocks work, we can assemble tools to do virtually anything we want. The aim is to be lazy. Why should we do anything we can get the computer to do for us? The only reason I can think of is that you don’t know how (but after working through these pages you will know how, so then there won’t be a good reason).

A question that may have crossed your mind is «Why should I bother learning the command line? The Graphical User Interface is much easier and I can already do most of what I need there.» To a certain extent you would be right, and by no means am I suggesting you should ditch the GUI. Some tasks are best suited to a GUI, word processing and video editing are great examples. At the same time, some tasks are more suited to the command line, data manipulation (reporting) and file management are some good examples. Some tasks will be just as easy in either environment. Think of the command line as another tool you can add to your belt. As always, pick the best tool for the job.

Outline

This Linux tutorial is divided into 13 sections. In general I recommend you work through them in order but if you’ve come here just to learn about a specific topic then feel free to just go straight to that one.

You can now jump into section 1 and get started or keep reading below to learn a little more about this tutorial.

  1. The Command Line — What is it, how does it work and how do I get to one.
  2. Basic Navigation — An introduction to the Linux directory system and how to get around it.
  3. More About Files — Find out some interesting characteristics of files and directories in a Linux environment.
  4. Manual Pages — Learn how to make the most of the Linux commands you are learning.
  5. File Manipulation — How to make, remove, rename, copy and move files and directories.
  6. Vi Text Editor — Discover a powerful Linux based text editor.
  7. Wildcards — Also referred to as globbing, this is a means to refer to several files in one go.
  8. Permissions — Learn to identify and change the permissions of files and directories and what the consequences of these are.
  9. Filters — An introduction to various commands that allow us to mangle data in interesting and useful ways.
  10. Grep and Regular Expressions — Master a powerful pattern matching language that is useful for analysing and processing data.
  11. Piping and Redirection — Join commands together in powerful combinations.
  12. Process Management — See what is currently running on your Linux system and what state the system is in, learn how to kill programs that have hung and put jobs in the background.
  13. Scripting — Be happy. Get the computer to do tedious and repetitive tasks for you.
  14. Cheat Sheet — A quick reference for the main points covered in this tutorial.

Structure

The best way to learn the Linux command line is as a series of small, easy to manage steps. This tutorial is organised as such, with each section building upon the knowledge and skills learned in the previous sections. If you work through them in order, read them fully (there is a fair bit of material but it is important for getting a proper understanding) and practice on the command line as you go I believe you should have a fairly pleasant and smooth journey to Linux command line mastery.

99 times out of 100 when a student has troubles with this stuff I find that it is not that they are incapable but that they were lazy and didn’t read the material fully.

Each section is structured in the following format:

  • An introduction outlining what you will learn in that section.
  • Detailed material including extensive examples.
  • A summary of programs covered in that section and the most important concepts.
  • A set of activities to help you solidify your knowledge and skills.

Think of the activities not as tutorial questions (such as you may get in a class at school) but as direction on where to explore in the Linux environment to benefit from your new knowledge and skills. Treat the activities as a starting point for exploration. The further you take it, the better you will do. (How well you do and how far you go depends on how unlazy you are.)

This site is also designed to work well on tablets. I know a lot of students like to be at their computer doing work and have their tablet next to them with reference material on it. If that is you then this site works quite well with that set up. Another good approach is to have your browser on one half of the screen of your computer and a terminal on the other half so you can try out the examples as you go.

Читайте также:  Проигрыватель nero для windows 10

Some general house rules:

  • I’ll refer to Linux in the following pages, whenever I do, assume I’m actually saying Unix/ Linux. Linux is an offshoot of Unix and behaves pretty much exactly the same.
  • Whenever you see , what this means is that you are to replace this with something useful. Replace the whole thing (including the ). If you see something such as then it usually means replace this with a number.
  • Whenever you see [something] this usually means that this something is optional. When you run the command you may put in the something or leave it out.

Problem Solving and Creative Thinking

If you wish to succeed with the Linux command line then there are two things you need, Problem solving and Creative thinking. Here are some basic pointers to help you along the way.

  • Explore and experiment. Remember, you’re learning about a set of building blocks and with them you can build almost anything. The examples you will find are intended to be an illustration of how they work, not the only thing you can do with them. I encourage you to tweak the examples and see how they behave. This will give you a much better understanding on how they work. You will have a lot of questions along the way along the lines of «What if. » and «Can I . » to which I say, «Give it a go and see what happens.» The worst you can really get is an error message. In which case you read the error message to understand why it didn’t work, then have another go. Don’t hold back!
  • Read carefully and don’t skip over the fine details. I can’t stress this enough. The fine details are important and are often the difference between your command working and not working. If something isn’t working then re-read the material carefully and re look over what you have typed in to make sure you haven’t make a silly little typo.

So the general approach is:

  • Create an hypothesis.
  • Run your command to test this hypothesis.
  • Observe the output. If it is what you were expecting, great. If not then continue.
  • Analyse the output and adjust your understanding accordingly.
  • Rinse and repeat till you get what you are after.

Obtaining Linux

Learning Linux is like riding a bike, you can only become proficient by actually doing. So before getting started, make sure you have access to a terminal. Luckily, you have several options available to you here.

  • If you are on a Mac then you are in luck, you already have a terminal.
  • Another option is to run Linux. Linux is completely free and there are many good distros out there. Some I would recommend include Ubuntu (which is quite popular and easy to use) and OpenSuSe (My personal favourite). If you take this approach then there are a few ways you can go.
    • If you have a spare machine then you can just install it on that.
    • You can create a dual boot system (ie both Windows and Linux are installed on the computer, you choose which to run when you boot up.). Most modern Linux distros will handle creating this for you when you install it (resizing existing windows partitions as well). Do back up any important files before doing this method though (I’ve never seen it fail but better to be safe).
    • You can run Linux in a virtual machine. VirtualBox is a nice tool to use for this and it’s totally free too.
  • You may also have access to a machine remotely either at work or uni. If you do then remotely logging into these to access a terminal is an option as well.

About the Author

Hi. My name is Ryan Chadwick and I have been teaching Linux to students for over 10 years now. It’s something that I very much enjoy. In a world where we are increasingly hiding the complexities away from users (smart phones and tablets in particular), it is always satisfying to give that power back to people and allow them to do much more with their technology.

But teaching is only one of the things I do. I also develop and manage websites, and manage computer systems for a few different organisations. I feel that all my work is complementary and benefits from what I learn in the others. Combined, they give me a fairly good understanding of how technology works, and also an understanding of how people use technology, perceive technology, learn technology and work around technology.

This website is both for you, and for me. For you, it is a digital form of what I have been teaching my students over the years. For me, it is an opportunity to clarify and polish what I teach and how I deliver it. To these ends, if you have any feedback at all, be it to tell me you found a particular section confusing, or to let me know it was helpful, I would be more than happy to hear from you.

Drop us a message at

Using this material

Anyone may link to the content on this website.

If you are a teacher, academic, manager or trainer and wish to use this material in your classes or training you are more than welcome to link to these pages and refer your students here or show them in your classes, but please do not just copy my material.

I’ve put a fair amount of time and effort into creating this resource so please be cool and do the right thing.

Disclaimer

Unfortunately, in this crazy and litigious world we now live in, one has to keep themselves covered so here is my disclaimer.

To the best of my knowledge, the material contained within these pages is correct. I make no guarantees however. I also take no responsibility for any damage you may do based upon knowledge gained from here (even though the chances of doing so are relatively small at best). Please use common sense when using any of the knowledge and skills gained from using this material.

Источник

Linux Guide/How Linux Works

Contents

The Linux Philosophy [ edit | edit source ]

Linux is built with a certain set of unifying principles in mind. Understanding these principles is very helpful in understanding how the system works as a whole. They are known as the «Linux Way», which is derived from the philosophy behind the UNIX system.

Читайте также:  Аналог pro100 для mac os

The Linux Way can be summarized as:

  • Use programs that do only one task, but do it well.
  • To accomplish complex tasks, use several programs linked together.
  • Store information in human-readable plain text files whenever it is possible.
  • There is no «one true way» to do anything.
  • Prefer commandline tools over graphical tools.

Most traits of Linux are a consequence of these principles. In accordance with them, a Linux system is built out of small, replaceable components. We will examine the most important of them in more detail. Those are: the boot loader, the kernel, the shell, the X window server, the window manager and the desktop environment. After that, we will have a look at the file system in Linux. Finally, we will discuss the security of a computer running Linux.

Core components of a Linux system [ edit | edit source ]

Boot loader [ edit | edit source ]

This is the part of the system that is executed first. When you have only one operating system installed, it simply loads the kernel (see below). If you happen to have multiple operating systems or multiple versions of the Linux kernel installed, it allows you to choose which one you want to start. The most popular bootloaders are GRUB (GRand Unified Bootloader) and Lilo (LInux LOader). Most users don’t need to care about the boot loader, because it is installed and configured automatically. Actually, the boot Loader creates the boot sequence that the Linux Kernel requires, loading the kernel and some device drivers required for early boot process into memory (as part of so-called «initramfs»), and starting the kernel.

Kernel [ edit | edit source ]

The kernel is the central component of the system that communicates directly with the hardware. In fact, the name «Linux» properly refers to a particular kind of this piece of software. It allows programs to ignore the differences between various computers. The kernel allocates system resources like memory, processor time, hard disk space and external devices to the programs running on the computer. It separates each program from the others, so that when one of them encounters an error, others are not affected. Most users don’t need to worry about the kernel in day-to-day use, but certain software or hardware will require or perform better with certain kernel versions.

Daemons [ edit | edit source ]

In a typical Linux system there are various services running as processes in the background, taking care of things like configuring your network connection, responding to connected USB devices, managing user logins, managing filesystems, etc. They are often called «daemons», because they are running silently and are mostly invisible to the user.

One of these «daemons», started by the kernel after it finishes booting itself, is called init , and its role is to start the rest of the system, including all other «daemons» and graphical sessions.

Different Linux distributions use different init systems. The traditional init system used since the old Unix era, is Sys V init (referring to the System V Unix). But recently many distributions have switched to more modern init systems, such as systemd .

Shell [ edit | edit source ]

The shell, sometimes also called «command line», implements a textual interface that allows you to run programs and control the system by entering commands from the keyboard. Without a shell (or something that can replace it, like a desktop environment) making your system actually do something would be difficult. The shell is just a program; there are several different shells for Linux, each of which offering somewhat different features. Most Linux systems use the Bourne Again Shell (Bash). Linux shells support multitasking (running several programs at once).

X Window Server [ edit | edit source ]

The X window server is a graphical replacement for the command shell. It is responsible for drawing graphics and processing input from the keyboard, mouse, tablets and other devices. The X server is network transparent; that is, it allows you to work in a graphical environment both on your own computer and on a remote computer to which you connect across a network. The X server that is most used today is X.Org. Most graphical programs need only the X server to run, so they can be used under any window manager and desktop environment.

Window Manager [ edit | edit source ]

The window manager is a program that communicates with the X server. Its task is managing windows. It is responsible for drawing the window borders, bringing a window to the front when you click it, moving it on the screen and hiding it when you minimize its program. Examples of popular window managers are:

  • Metacity — GNOME Desktop Environment window manager
  • KWin — KDE window manager
  • Xfwm — Xfce window manager, a lightweight manager designed to consume as little resources as possible without compromising usability
  • Compiz Fusion — an advanced window manager with lots of eye candy like customizable window animations, multiple desktops placed on a cube that you can rotate with your mouse, transparent window borders, wobbling windows while dragging them, etc.

Desktop Environment [ edit | edit source ]

Desktop environments such as GNOME Desktop Environment, KDE and Xfce are collections of programs designed to present a consistent user interface for most common tasks. They are what most people mean when they say «operating system» even though they are only a piece of the whole operating system. Multiple desktop environments can coexist on the same machine. They can be easily installed and after installation the user will be given a way to select which DE to start the session with.

File System [ edit | edit source ]

There are several file systems that Linux-based distributions use. They are BTRFS, EXT3/4, VFS, NILFS, and SquashFS.

The hard drive of your computer has a rather simple interface. It only accepts commands like «read block no. 550923 and put it in memory address 0x0021A400». Suppose you are editing a piece of text and want to save it on the disk. Using block numbers (addresses) to identify pieces of data, like your text, is awkward: not only would you have to tell your program where to save the file using raw block numbers, you would have to make sure that these blocks aren’t already being used for family photos, your music collection, or even your system’s kernel. To solve this, files were introduced. A file is an area of the disk which stores data and which has a name (like «example.txt»). Files are organized in collections called directories. Directories can contain other directories, in a tree-like structure. Each file can be uniquely identified by a «path,» which describes its place in the directory hierarchy. For the remainder of this section, it will be assumed that you are familiar with files, directories, and paths.

In Linux, the top-level directory is called the root directory. Every file and directory in the system must be a descendant of the root directory. (It is common to talk about directories using the terminology of family relations, like «parent,» «child,» «descendant,» «ancestor,» «sibling,» and so forth.) Names of files and directories can contain all characters except the null character (which is impossible to enter from the keyboard) and the «/» character. An example path would be:

Читайте также:  Windows не видит фотоаппарат canon через usb

This path refers to a file called «error.log» which is found in a directory called «apache,» which is a subdirectory of a directory called «logs,» which is subdirectory of a directory called «var,» which is a subdirectory of the root directory. The root directory doesn’t have a name like the other; it is just denoted with a «/» character at the beginning of the path.

The root directory usually contains only a small number of subdirectories. The most important are:

  • bin — programs needed to perform basic tasks, i.e. change a directory or copy a file
  • dev — special files that represent hardware devices
  • etc — configuration files
  • home — contains private directories of users
  • media or mnt — Mount point for external drives connected to this computer, i.e. CDs or USB keys
  • tmp — temporary files
  • usr — programs installed on the computer
  • var — variable data produced by programs, like error logs

Devices as files [ edit | edit source ]

Just as files can be written to and read, devices in the computer system may send and receive data. Because of this, Linux represents the devices connected to the system as files in the /dev directory. These files can not be renamed or moved (they are not stored on any disk). This approach greatly simplifies application programming. If you want to send something to another computer through a serial port, you don’t even need another program — you simply write to the file /dev/ttyS0, which represents a serial port. In the same manner the file representing the sound card (/dev/dsp) can be read to capture the sound from an attached microphone, or written to in order to produce sound through the speakers.

Where are the drive letters? [ edit | edit source ]

If you have used Windows, you might be surprised that there are no drive letters in Linux. The root directory represents the drive on which the system is installed (C: in Windows). Other drives can be «mounted» or «unmounted» in any directory (preferably, an empty one) in the file system. By mounting a disk, you attach the root directory of this disk to a directory in the file system. After that, you can access the disk like it were a part of your system disk. For example: if you have a disk that contains a directory text, which in turn contains a file called linux-intro.tex and you mount this drive in the directory /media/usbkey, you can access the file linux-intro.tex through the path /media/usbkey/text/linux-intro.tex.

In most Linux distributions, USB keys and CDs are automatically mounted when they are inserted or attached, and the default mount directory is a subdirectory of /media or /mnt. For example, your first CD-ROM drive might be mounted at /media/cdrom0, while the contents of a USB key might be accessible through /media/usb0. You may manually change the mount directory, but you will have to learn two shell commands and know the device file that represents your drive to do that (the one we talked about in the preceding section — disks also get their file representation in the /dev directory). We will cover this subject later.

Users [ edit | edit source ]

The user is a metaphor for somebody or something interacting with the system. Users are identified by a user name and a password. Internally, each user has a unique number assigned, which is called a user ID, or UID for short. You only need to know your UID in some rare situations. Users can additionally be organized in groups. There is one special user in all Linux systems, which has the user name «root» and UID 0. It is also called the superuser. The superuser can do anything and is not controlled in any way by the security mechanisms. Having such a user account is very useful for administrative tasks and configuring the system. In some distributions (like Ubuntu) direct access to the root account is disabled and other mechanisms are used instead.

If you have more than one user account on a Linux system, you do not need to log out and back again to switch impersonations. There are special shell commands that allow you to access files and execute programs as other users, provided you know their user names and passwords. Thanks to this mechanism, you can spend most of the time as a user with low-privileges and switch to a higher-privileged account only if you need to.

The advantage of running as a non-privileged user is that any mistakes you happen to make are very unlikely to damage the system. System-critical components can only be altered by the root user.

File permissions [ edit | edit source ]

Users exist to control the extent to which people and programs using the system can control it. This is accomplished by a system of file permissions. Each file belongs to one of the users — that is, each file has an owner. Additionally, a file can be assigned to a group of users, but the owner must be a member of that group. Each file has three kinds of permissions: read, write and execute. These permissions can be assigned to three kinds of owner relations: owner, group and other. Other includes all users who are not the owner of the file and do not belong to the group which owns the file. Only the file owner or the superuser (root) can change the permissions or ownership of a file.

This system allows precise control over who can do what on a given computer. Users can be prevented from modifying system files by removing the «write» permission from them, or from executing certain commands by removing the «execute» permission. Notice that users may be allowed to execute programs but not alter them. This is very important, since most Linux systems include a compiler that allows you to create your own programs.

File permissions are usually given as three octal digits (each from 0 to 7). The digits represent the permissions for, respectively, owner, group and other users. Each digit is the sum of permission codes: 1 for execute, 2 for write and 4 for read. For example, «755» allows everyone to read or execute the file, but only its owner can write it. «400» allows the owner to read the file, and no one else is allowed to do anything. «540» allows the owner to read or execute the file, group members to only read the file and other users to do nothing.

chmod (change mode), chown (change owner), and chgrp (change group) are used to change file permissions.

Источник

Оцените статью