LINUX FOR BEGINNERS

A STEP-BY-STEP GUIDE TO LEARN LINUX OPERATING SYSTEM. THE BASICS OF KALI LINUX HACKING BY COMMAND LINE INTERFACE.

TOOLS EXPLANATION AND EXERCISES INCLUDED

AXEL ROSS

Description

Introduction

Why Linux?

Can You Have Linux?

What are Linux Distributions?

What Comes with a Distro?

Things to Consider When Choosing Distros

Great Distros to Try

What is Linux and Why Choose Linux?

The Basic Components of Linux

The Installation of Linux

Linux Applications

The Linux Desktop

Ubuntu Desktop

Debian Desktop

Fedora Desktop

Mint Desktop

Basic Administration and Security

Using the Shell

Introduction to Command Line

Working with Links

File Editing Commands and Wildcards

Using the File Editing Commands and Wildcards

Discerning Commands

Linux Text Editors

The I/O Redirection

What Is I/O Redirection?

Over-writing & Appending

Special Redirection Commands & Operators

Redirection Features for Advanced Uses

File Manipulations

How to make a directory

Removing a directory

How to create a blank file

Copying a file or a directory

Moving a file or directory

Renaming files and directories

Removing a file

Practice activities

Programming in Linux using C++

Extremely Basic Editing and Creation of text files

Input and Output Streams

Input and Output Redirection

Piping of Input/Output Streams

Redirection of Input/Output Streams

cat

echo

tee

Conclusion

© Copyright 2019 - All rights reserved

No part of this book may be reproduced in any form without permission in writing from the author. Reviewers may quote brief passages in reviews.

Disclaimer

No part of this publication may be reproduced or transmitted in any form or by any means, mechanical or electronic, including photocopying or recording, or by any information storage or retrieval system, or transmitted by email without permission in writing from the publisher.

While all attempts have been made to verify the information provided in this publication, neither the author nor the publisher assumes any responsibility for errors, omissions, or contrary interpretations of the subject matter herein.

This book is for entertainment purposes only. The views expressed are those of the author alone and should not be taken as expert instructions of commands. The reader is responsible for his or her own actions.

Adherence to all applicable laws and regulations, including international, federal, state and local governing professional licensing, business practices, advertising, and all other aspects of doing business in the US, Canada, or any other jurisdiction is the sole responsibility of the purchaser or reader.

Neither the author nor the publisher assumes any responsibility or liability whatsoever on the behalf of the purchaser or reader of these materials.

Any perceived slight of any individual or organization is purely unintentional.

Description

Many technological empires are beginning to switch over to Linux as the basis for all their working mechanisms because it’s free and incredibly stable. Massive websites are being built and hosted on Linux operating systems, and people who are building their own smart homes on a budget are doing it with Linux operating system distributions and its supported coding languages! While it all might seem incredibly overwhelming, give yourself some credit: learning anything new comes with learning new words, new concepts, and new pieces of information to work with.

Currently, the user of a personal computer has a wide range of operating systems. Leading software manufacturers have made sure that the end user gets the most loyal and convenient way to work with a personal computer. Until recently, it was believed that Linux-based operating systems were quite difficult to manage and are suitable only for "confident" users. Is it so?

We should start with the fact that now on the market there are three of the largest companies developing software. This is 

1. Microsoft, and its Windows

2. Apple and its Mac OS

3. Linux and Linux distributions (the most popular is Ubuntu).

Note that the first two systems are paid software and their price starts from a few hundred dollars. Unlike Windows and Mac OS, Linux distributions are completely free.

It is also worth noting that Mac OS is distributed exclusively with Apple products. In other words, personal computer users cannot install this operating system. Only Mac computer and laptop owners can install this.

In addition to pricing, Linux also benefits from system security and stability. All of us have heard stories that a dangerous virus has appeared on the network, which can delete all the data of Windows users. For UNIX systems, viruses are practically non-existent. Downloading from the Internet or ordering a free disk with the Ubuntu distribution, you will receive a fully-fledged operating system. You will not need to download additional software: all the basic applications required for the average user are already included in the Ubuntu package.

All this said and done, what comes into the spotlight is the job profile of a Linux system administrator. There is a huge demand for this profile in all the major organizations worldwide, which work on Linux systems. This book provides a beginner’s course to the Linux system and we hope that it will encourage you to learn advanced Linux system administration in the future. 

This guide will focus on the following:

What are Linux Distributions?

What is Linux and Why Choose Linux?

The Basic Components of Linux

The Installation of Linux

Linux Applications

The Linux Desktop

Basic Administration and Security

Using the Shell

Working with Links

Discerning Commands

Linux Text Editors

The I/O Redirection

File Manipulations... AND MORE!!!

Introduction

Just like Windows 10 and Mac OSX, Linux is an operating system, or software that is designed to manage all resources that are associated with your desktop or laptop. However, the more important thing to answer is this: Why get Linux and learn how to navigate in a completely different environment in your computer?

Why Linux?

If you are struggling with your operating system, and you are consistently battling with the fact that you need to pay for licensing fees for every software that you have installed in your computer, the constant fear of having to lose data every now and then due to malware and viruses, and you are simply tired of your computer slowing down or crashing without reason, then you may have just stumbled on to the perfect desktop platform. Linux has now evolved into one of the most stable operating systems in the world, thanks to its continuous development by a huge network of programmers. 

What makes it even better is that it does not cost you anything to install it, no matter how many computers you have at home. It is also distributed through an open source license, which means that you have the freedom to run and study the program for whatever purpose, as well as the freedom to make any changes to the program to fit your personal usage. 

You will also have access to a wealth of programs that are designed to allow you to do everyday computing tasks, such as working on a document, watch or edit videos, play games, and so much more. In a nutshell, you can do everything that you do on the more common operating systems, such as Windows and Mac OS on Linux, minus the frills of having to deal with bloatware, fees, and other things that you wish licensed operating systems will get rid of.

Tip: If you are running a PC computer and you do not want to make a complete switch to Linux just yet, don’t worry – you can install and operate Linux on your computer on the same PC and switch operating systems from time to time.  

Can You Have Linux?

Linux can run on different types of computer systems, and because it is available on many distributions, you can choose the distribution that will allow you to install the operating system on the computer that you have available. Currently, Linux can be installed on computers with the following processors:

Hewlett-Packard HP PA RISC

Alpha AXPs

Motorola 68000 family

MIPS R5x00 R4x00

PowerPC and PowerPC64

64-bit AMD64 processors

Intel 80x86 processors

Pentium processors

What are Linux Distributions?

When you get Linux for your computer, you are essentially getting Linux distribution. Just like other popular operating systems, you get an installation program that consists of the kernel, a graphical user interface, a desktop, and a bunch of applications that you can readily use once you installed Linux in your computer. The added bonus is that you also get the opportunity to get your hands on the source code for the kernel and the applications that you get, which allows you to tweak them the way you want them to operate in the future.

While you can add desktop environments, apps, and drivers that don’t come with your distribution, you will need to find the distribution that will give you the ideal setup that you have in mind. Doing so will save you the time that you may need to spend on finding apps and other programs that will work best with the Linux that you have installed, which can get in the way of setting up the system just the way you want it.

What Comes with a Distro?

GNU software

Most of the tasks that you will be performing using Linux involve GNU software. These are utilities that you can access using the text terminal, or the interface that looks like a Windows command prompt where you enter commands. Some of the GNU software that you will be using are the command interpreter (also known as the bash shell) and the GNOME GUI.

If you are a developer, you will be able to make changes to the kernel or create your own software for Linux using a C++ compiler (this already comes with the GNU software that comes with your Linux distro) and the Gnu C. You will also be using GNU software if you edit codes or textfiles using the emacs or the ed editor.

Here are some of the most popular GNU software packages that you may encounter as you explore Linux utilities:

Applications and GUIs

Since you will not want to type string after string of commands on a command terminal just for your computer to do something, youw will want to navigate and use programs in your computer using a GUI or a graphical user intergace. A GUI  enables you to click on icons and pull up windows that will help you use a program easier. 

Most of the distros use the K Desktop Environment (KDE ), or the GNU Object Model Environment (GNOME). If you have both environments installed on your computer, you can choose which desktop will serve as the default, or you can switch between them from time to time. Both these desktops have a similar feel to Mac OS and Windows desktops. It is also worth taking note that GNOME comes with a graphical shell called Nautilus, which makes the Linux configuration, file search, and application loading easier. Should you need to use a command prompt, all you need to do is to click on the terminal window’s icon on both desktop environments.

Apart from GUIs, any average computer user will also need to to use applications, or programs that you can use to perform basic computing needs. While you may not have access to the more popular programs that you may have used in a Mac or Windows computer, Linux can provide open-source alternatives that you can try out. For example, instead of having to buy Adobe Photoshop, you can try out The GIMP, which is a program that works just as great when it comes to working with images.

Linux also offers productivity software packages which fulfills the bulk of an ordinary computer user’s needs. You can get office productivity apps that will allow you to do word procesing, create database, or make spreadsheets  from Libreoffice.org or OpenOffice.org.

Tip: If you want to install MS applications to Linux (e.g., Microsoft office), you can use CrossOver Office. You can download this app from www.codeweavers.com/products/crossover-linux/download).

Networks

Linux allows you to find everything that you need by using a network and exchange information with another computer. Linux allows you to do this by allowing you to use TCP/IP (Transmission Control Protocol/Internet Protocol), which allows you to surf the web and communicate with any server or computer out there. 

Internet servers

Linux supports Internet services, such as the following:

Email

News services

File transfer utilities

World wide web

Remote login

Any Linux distro can offer these services, as long as there is Internet connection, and that the computer is configured to have Internet servers, a special server software that allows a Linux computer to send information to another computer. Here are common servers that you will encounter in Linux:

in.telnetd – allows you to log in to a different system wia the internet, with the aid of a protocol called TELNET

sendmail – serves as a mail server which allows exchange of emails between two systems using the Simple Mail Transfer Protocol (SMTP)

innd – allows you to view news using the Network News Transfer Protocol (NNTP), which enables you to access a news server in a store-and-forward way.

Apache httpd – allows you to send documents to another system using the HyperText Transfer Protocol (HTTP).

vsftpd – allows you to send a file to another computer using the filetransfer protocol (FTP)

sshd – allows you to log-in to a computer securely using the internet, using the Secure Shell (SSH) protocol

Software Development

Linux is a developer’s operating system, which means that it is an environment that is fit for developing software. Right out of the box, this operating system is rich with tools for software developments, such as libraries of codes for program building and a compiler. If you have background in the C language and Unix, Linux should feel like home to you.

Linux offers you the basic tools that you may have experienced using on a Unix workstation, such as Sun Microsystems, HP (Hewlett-Packard), and IBM. 

Online documentation

After some time, you will want to look up more information about Linux without having to pull up this book. Fortunately, Linux has enough information published online that can help you in situations such as recalling a syntax for a command. To pull this information up quickly, all you need to do us to type in “man” in the command line to get the manual page for Linux commands. You can also get help from your desktop and use either the help option or icon. 

Things to Consider When Choosing Distros

What is the best Linux distro (short for distribution) is for you? Here are some things that you may want to keep in mind:

Package managers

One of the major factors that separate distros from one another is the package manager that they come with. Just like what you may expect, there are distros that come with features that allow them to be easier to use from the command line while you are installing the features that come with them.

Another thing that you need to consider apart from the ease of use is the package availability that comes with distros. For example, there are certain distros that are not as popular as the others, which means that there are less apps out there that are developed to be used with certain distributions. If you are starting out on Linux, it may be a good idea to install a distro that does not only promise easy navigation from the get-go, but also a wide range of apps that you may want to install in the future.

Desktop environment

You will want to have a distro that allows you to enjoy a desktop that works well with your computing needs – you will definitely want a desktop that has great customization options, and easy to find windows and menus. You will also want to ensure that your desktop have efficient resource usage, as well as great integration with the apps that you plan to use.

While it is possible for you to place another desktop environment in the future, you will still want the desktop that comes with your distro to resemble the desktop that you really want to have. This way, you will not have to spend too much effort trying to setup every app that you want to have quick access to and ensure that all your applications are able to work well as they run together.

Hardware Compatibility

Different distros contain different drivers in the installation package that they come from, which means that there is a recommended set of hardware for them to work seamlessly. Of course, you can check out other sources of drivers that will work best with your existing hardware, but that only creates more work when it comes to getting everything running right away from installation. To prevent this trouble, check the distro’s compatibility page and see whether all your computer peripherals work fine with your Linux distribution out of the box.

Stability and Being Cutting Edge

Different distributions put different priorities on stability and updates to get the latest version of applications and packages. For example, the distro Debian tends to delay getting some application updates to make sure that your operating system remains stable. This may not be suitable for certain users that prefer to always get the latest version of applications and get the latest features.

Fedora, on the other hand, performs quite the opposite – it is focused on getting all your programs and features up to date and ensures that you always have the greatest and the latest wares for your Linux. However, this may happen at the expense of stability of the app, which may prompt you to roll back to the previous version.

Community Support

Linux is all about the community that continuously provides support to this operating system, from documentation to troubleshooting. This means that you are likely to get the resources that you need when it comes to managing a particular distribution if it has a large community. 

Great Distros to Try

Now that you know what makes a Linux distribution great and you are about to shop for the distro that you are going to install, you may want to check these distributions that may just work well for you:

Ubuntu

Ubuntu is largely designed to make Linux easy to use for an average computer user, which makes it a good distribution for every beginner. This distro is simple, updates every six months, and has a Unity interface, which allows you to use features such as a dock, a store-like interface for the package manager, and a dashboard that allows you to easily find anything on the OS. Moreover, it also comes with a standard set of applications that works well with most users, such as a torrent downloader, a Firefox web browser, and an app for instant messaging. You can also expect great support from its large community.

Linux Mint

This distro is based on Ubuntu but is designed to make things even easier for any user that has not used Linux in the past – it features familiar menus and is not limited to just making you use open source programs. This means that you can get programs that are standard in popular operating systems such as .mp3 support and Adobe Flash, as well as a number of proprietary drivers. 

Debian

If you want to be cautious and you want to see to it that you are running a bug-free and stable computer at all times, then this is probably the distro for you. Its main thrust is to make Linux a completely reliable system, but this can have some drawbacks –Debian does not prioritize getting the latest updates for applications that you have, which means that you may have to manually search for the latest release of most software that you own. The upside is that you can run Debian on numerous processor architectures, and it is very likely to run on old builds.

However, this does not mean that going with Debian is having to remain outdated – it has a lot of programs available online and in Linux repositories.

OpenSUSE

OpenSUSE is a great distro that you may consider trying out because it allows you to configure your OS without having the need to deal with the command line. It usually comes with the default desktop KDE, but will also let you select between LXDE, KDE, XFCE, and GNOME as you install the distro package. It also provides you good documentation, the YaST package manager, and great support from the community.

One of the drawbacks that you may have when using this distro is that it can consume a lot of resources, which means that it is not ideal to use on older processor models and netbooks.

Arch Linux

Arch Linux is the distro for those that want to build their operating system from scratch. All that you are going to get from the installation package from the start is the command line, which you will use to get applications, desktop environment, drivers, and so on. This means that you can aim to be as minimal or as heavy in features, depending on what your needs are.

If you want to be completely aware of what is inside your operating system, then Arch Linux is probably the best distro for you to start with. You will be forced to deal with any possible errors that you may get, which can be a great way to learn about operating Linux. 

Another thing that makes this distro special is that it uses Pacman, which is known to be a powerful package manager. Pacman comes in a rolling release, which means that you are bound to install the latest version of every package that is included – this ensures that you are bound to get cutting edge applications and features for your Linux. Apart from this package manager, you also get to enjoy the AUR (Arch User Repository), which allows you to create installable version of available programs. This means that if you want a program that is not available in Arch repositories, you can use the AUR helper to install applications and other features like normal packages.

What is Linux and Why Choose Linux?

This book assumes that you are familiar with computers enough to want to explore using Linux. The Linux operating system (OS) is not something your average consumer realizes the extent to which it is the most utilized platform and is tailored to devices such as Android phones, Smart watches, refrigerators, washing machines, video game consoles and DVRs just to name a few.

Linux can be used to host a website, create a new and secure file or e-mail server, diagnose another system you own, and possibly recover crashed files. It can enhance Chromebooks. Even NASA, Dell, IBM, and Hewlett-Packard have tapped into the Linux OS.

It was first developed as a family extension of the various iterations of Unix. It is free, open-source code and released October of 1991 by Linus Torvalds. Torvalds is a Finnish-American Engineer who believes that open source is the only way to go. Thankfully he thought so.  At first, Linux was primarily for personal computers but as you can see it has a use that has expanded exponentially and now runs some of the largest super computers as well as the devices just named.

Since Linux release, other programmers have developed their own versions or distributions of Linux. These are also called distros. These next generation developers were able to do this because of the open sourcing of Linux. This is a good thing, but having many different versions has its challenges as you will see.

Technically speaking, Linux is not an operating system per se, as are the distros that are based on the Linux kernel. Linux supported by the larger, Free/Libre/Open Source Software community, a.k.a. FLOSS. This is also sometimes referred to as just Free Open Source Software, or FOSS. Linux kernel version 4.0 was released in 2015. The coding has increased in length exponentially since its development.

Tux is the penguin mascot of Linux. You will see him in his many versions. Some distros flash Tux in different garb or graphic styles. The most popular version of his creation says that he was first named after Linux creator, Linus Torvalds, (i.e., “Torvalds UniX)”, as an entry for a logo contest, which he did not win. Tux does quite well as a mascot, however and everyone who knows Linux associates Tux with great work.

Basic Components of Linux

The Kernel is the core, the lowest level of Linux that has control over everything in the system.

The Shell (or “sh”) is the user interface, the primary way to interact with servers. It provides the directives that are typed through Commands on the Command Line (or terminal) and relays them to the kernel to process between hardware and applications. (To note, Most Linux versions use a shell called Bash, which is “Bourne-Again Shell,” although you can use a different shell, but that is probably not for beginners).

The below diagram offers a simple view of how these layers of the Operating System work together.

————————————————————-

|       L I N U X     K E R N E L       |

|                                         |

|  ————————————————-— |

|  |      Applications / Services    |  |

|  |_______________________|  |

|  |    Drivers and HW Interfaces    |  |

|———————————————————-|

|       Input       |      Output         |

|      Hardware     |     Hardware      |

|———————————————————-|

|    End Users like you and users of    |

|             your services             |

|———————————————————-|

Why Choose Linux?

What makes Linux different from other operating systems, and why should you choose it? There are some differences which you should be familiar with if you chose to use Linux over other operating systems.

The things you can do with Linux are virtually endless. Jack of all trades. Some of the most common reasons for a beginner to use Linux include the following.

It is FREE. Free, as in it is Open Source, meaning that the code is open for anyone to use, replicate or change as they see fit. It also is free as in it does not cost money, however that is secondary. The other benefit is that the OS system, in all of its various distributions, are constantly being updated, added to, changed, or inspiring spin offs (the distributions, or distros as you will see), from Linux. Those distributions are also obligated to be open source based on anti-trust laws and licensing that requires any future “family members” to adhere to the same public sharing structure. Nothing is kept secret. Everything is open.

Due to this open sourcing there are communities that center around the development, use and feedback of the various Linux distros. These are advantageous to those newbies who need to know how to do something, how to troubleshoot, or just know how something works. Information exchanges are encouraged. There are many forums online where one can find this type of help, outside of looking at Commands and help pages in the operating system itself.

Another consideration of Linux fans is that you are not dealing with third party companies who may then own or use your data in some way. It is your data, in your storage and sometimes on your server.

One writer described the system as being advantageous to the developing world, in that its source code is offered to resource scarce populations. The possibility for learning technology is supported as well as the source codes can be examined and tinkered with.

Linux is alive. You can use and revitalize older systems. Linux can be installed on old systems. The best part is that you can create what you want or need, and leave the rest behind. You cannot do this with a Windows OS, for example. It is super flexible. You can choose from many environments (for the appearance).

Linux also takes up very little space. As you will see in this guide, you will have an option to run your software entirely off of the hard drive, or even in a virtual environment. You can partition the system and share it with another that you don’t want to part with (at all, or at least not quite now).

The applications and programs are on par with offerings of other operating systems such as Windows and MAC OS x. They are not lacking. In fact, something that is available with the Linux Ubuntu distribution is an mp3 player which out does Apple’s iPod, since the user runs into many restrictions in their use and portability. Ubuntu’s mp3 is freeing.

It is versatile. Depending on which version you choose, you can create a server for e-mail, website, or files. Again, this is a platform for media centers, kitchen appliances, DVR and Wii’s, Raspberry Pi’s, and international supercomputers. I think you get the point.

It runs other devices. Not only is it interesting to know how things work, but it is a sign of the technological future to come. Get it now.

It is Easy. With a few commands and navigation skills, you can turn your computer into a server or amp up your desktop with ease and speed.

It can be very secure, especially with the server edition which is ultra-secure. Virus software is rarely needed. That is unimaginable for anyone running another Operating System to fathom, but it is true. All of the software and executables are also coming from repositories that are part of the operating system. You won’t get that with other systems. These items are digitally signed so you know they are valid and you know where they came from.

You should also know that for as many benefits it has, and although it does have many strengths over other systems in comparison, Linux is not perfect. It is evolving and growing however, so have faith in knowing that glitches particularly in some of the distros are being addressed by developers of these various versions.

Some criticism has to do with glitches in certain distros, limited support, with questions of sustainability of that support, sometimes being oriented to enterprises over personal computers, mobile usage, and other things of that nature.

There are some issues with incompatibility with certain existing computer components (which usually can be patched or repaired). One example is a reported issue with wireless cards. If this happens, depending on the issue, you can do a little research and it is rectifiable in almost all cases.

As some users find that the reasons listed above appear to be “pro” Linux, other users can turn them into “cons”. One example is the customization. There are some users that just like the prepackaged features that come along with buying a Windows system, or a MAC system. You won’t have to worry about most features and programs having to be located and found. There are many right there to start with.

Some users fear the use of the CLI, and having to interact via a Command list that can be pages long, and scripts and arguments that can be ten times as long as the base Commands. It can be very intimidating.

Nevertheless, people overwhelmingly like it and find it useful for more than just a home computer operating system as you see. It has so much in terms of a track record, and so much future potential. Who knows how far it goes, or what innovations it will turn up in next. On that selling point, let it be said that you really should test run Linux. Try it out. Get the experience. You don’t have to stay with it, but from we what we know, many people do.

Which Version to Choose: Desktop or Server?

Desktop Version

This version will be easy for the beginner. It gives you a Graphical User Interface (GUI) that may be very much like what you see with Windows or MAC OS. You will see familiar icons, taskbars, menus and control panels. This is not true with the Server Version, as you will see.

You still have a learning curve but it will look more familiar and user friendly. It is recommended that you download it first to learn it until you are comfortable and/or need the Server version.

With this version you will get more graphics. You will also receive Open Office and Firefox as some of the programs that are already loaded in most of the distros. But you can easily fetch new brewers and other applications.

On the downside, there tend to be more security risks. It also takes up more space. As a desktop operating system it is not optimal and can be quirky. It still can be a great experience. Different from Windows where it needs constant updates, will slow down or crash, Linux rarely will crash. It has functionality that tends to play well with servers. If configured well it will work like a trooper, and virtually forever.

In the Desktop version you will be using a pointer and clicking as you would with Windows. This is an easy way to interact with the shell. In the server version, you are using a typed, command-line interface (or CLI) with the shell, to instruct the system what you would like it to do, or where to go. You can also use typed commands as a tool to automate things though scripts as you become more advanced.

With the Desktop version you will still have an option to use a Command line with the prompt however, which some people like. This helps for a quick comparison, but you will read more about the server version next.

Server Version

The server version of Linux is a pared-down version. It is super simple. However, unlike the desktop version you should know that you will not get all the bells and whistles and no GUI. Also, it is assumed that you already know what to use, what you need to install etc. You will have to know and use DOS to work with this version. It doesn’t mean that you should not use the server version. You may get frustrated, however. If you are up to the challenge, it just may move you to learn more about Linux.

The Line User Interface (LUI) in the server version is sometimes preferred over the GUI. Some persons like being able to tell their system what to do using Commands at DOS prompts. It can be more powerful, and this is one reason why many programmers prefer this. Again, you must understand that when you install, you only get prompts and you must know what to do next with the cursor.

It is also suggested to decide your reason for using Linux in the first place. Linux server version is for creating servers, for back-up, for email, files, websites, etc. It is not every day personal computer use necessarily. It happens to be the most secure version as well. This is another benefit.

Almost all of the distros that are currently available have both Desktop and Server versions. The ultimate choice is yours whether or not to use the desktop or the server version. You could also try the desktop version and move to the server version.

The Basic Components of Linux

We have already addressed some of the components of Linux, such as the kernel and the shell (or how the user of the Linux system interacts with the software), but there are a few things we have not yet addressed.

The Linux system library is a set of special programs that are used to access the operating system’s kernel features. These libraries aid in the implementation of some of the most basic functionalities the operating system executes, but you don’t have to do anything in order to get these to work. Just like you don’t have to think about breathing or blinking, you don’t have to toggle anything to tell the Linux system to do these things. Breathing and blinking simply happen involuntarily.

However, being aware of them will help you to picture how the entire Linux system is set up.

You also have the system utilities. These are the programs that are responsible for the specialized and individual level tasks. This is the type of software that helps maintain the entire infrastructure of the computer as well as its operating system.

In other words, this is what keeps Linux as stable as it is.

Within Linux, there are two different modes: user mode and kernel mode. If you are executing any sort of code or programming language that doesn’t require opening the kernel, then you’re in user mode. Using this mode means you have no access to the basic hardware of the system, so whatever you decide to execute doesn’t affect the low-level tasks stabilized by the kernel.

It’s the equivalent of allowing a toddler to get inside a cardboard box and color on the cardboard walls. Yes, the color is getting everywhere, but only inside that box. There is no color changing the main walls of your home, forever altering what it looks like until you can get a bucket of soapy water and scrub it down.

However, kernel mode gives you full access to every single resource the computer has to offer. This is a privileged mode that has the capability of allowing you to alter Linux at its base level. Using the metaphor above, this would be the equivalent of allowing a toddler to not only color on the walls, but take a tire iron to the plaster and pull the electrical wirings through the hole.

You can completely alter how Linux operates and how it interfaces with the user (a fancy way of saying “how it looks when you open the main screen after logging in”) in this mode if you want. However, as a beginner? I don’t recommend it.

Linux also has some basic features that come with it that not every operating system has. It’s portable, meaning you can transfer the type of operating system you use to any electronic device you wish, so long as it’s in a form that can be transferred (think a thumb drive or a burned disk). It’s also a multi-user operating system, which means multiple people can access very sensitive information about Linux (like the memory and the RAM) on one system.

It would be like a split-screen television, where one game player is off shooting a monster, and the other player has fallen off a cliff and landed in the water. Each person can do their own thing within this sprawling world without it affecting the other.

Linux also has the capability of being a multiprogramming system. This simply means you can run multiple applications at the same time without the system bogging down.

It also has a hierarchical file system, making things very easy to find once you learn the layout of your operating system, and it also has already-implemented security protocols, such as password protection of specific files and encrypted data. While it’s a multi-user system, the owner can lock it down, if they wish.

The greatest thing about the Linux operating system, however, is the open world it provides for people who want to learn how to code. You have the capability of accessing every single sensitive file of information, no matter where it’s located, and because it’s a free and open-source licensed operating system, you can tinker as you please without making someone upset with your tinkering. With other operating systems, tinkering usually avoids some sort of warranty. Have you ever heard the term “jailbreaking”? This is a term used when someone bypasses the limitations set on an operating system in order to access those base files to change the way they can interface (or interact) with it.

There is no jailbreaking or voided warranty when you tinker around with Linux, and this is the main reason why this operating system is the most popular when it comes to those who program, those who want to learn to program, and those who want to use their programming knowledge to take on DIY projects for various purposes.

Linux also supports most of the programming languages available. Python, Ruby, Vala, C++, Java, Perl, and HTML are just a few of the many that Linux not only understands how to execute, but also understands how to teach. The great thing about this operating system is that, within its own application store, you can download tutorials that run in the background that help you correct the source code you might be tinkering with.

Did I lose you there? Let’s try this: when you open that little black box you see all those computer whizzes in television shows typing in (called a terminal window), you can begin to type in little lines of code. Those are called “command lines,” and they have to be typed in a certain way with certain characters in order to work.

If any character is out of place or missing, the line itself won’t work.

There are programs you can run in the background on the operating system that will help you catch those errors. Some applications will automatically correct the error if it’s something simple, and some will step in and stop you from progressing to the next chunk of code until you have found the error and corrected it. There are a few that go a little more in-depth for beginners, such as flashing possible errors at them on the screen, and some applications can be opened and played like games to help beginners learn the basics before opening their own terminal windows and experimenting.

All of this is possible on a Linux operating system, which makes it the most sought-after system when someone expresses an interest in learning how to code.

Another great thing about Linux is how easy it’s to install. However, once the basic operating system is installed, there are specific steps that have to be taken in order to update, upgrade, and install certain packages in order to secure your operating system.

But don’t worry.

The Installation of Linux

There are a few different ways you can install the Linux operating system onto your technological device, but the most popular way is by downloading the program and burning a live CD version. Unless you are using some sort of netbook, this is probably the easiest way for you to get Linux onto your computer or desktop personal computer.

What burning a live CD requires is a computer that has disk-burning capabilities and that can connect to the internet. You’ll need to find a source online that has the version of Linux you have chosen, or you can download one of the more popular versions directly from the main Linux website.

Some of the versions you’ll find have both a 32-bit and 64-bit version available for each desktop environment. If you are in doubt, stick with the 32-bit version.

For those who are curious about the difference, here is the main one: the 64-bit versions have been optimized for better interaction and desktop environments. Think of it as an upgrade of sorts. With 32-bit operating systems, you are limited to 4096 MB of RAM (the overall memory capacity of your operating system). With this 32-bit system, all of the processes are given 4 GB of virtual memory to play with, which is then split into 2 GB of user space the application can utilize at a time. What all of this means is, even though your computer might allow for more RAM space, the 32-bit version of any Linux operating system is only going to be able to play around with so much memory.

So, if you are installing a 32-bit version of Linux onto a technological device that has 10 GB RAM, you are still only going to be able to utilize 4096 MB of it because that’s all the designed operating system can handle at once.

Not only does the 32-bit version of Linux operating systems limit the overall amount of memory it can use and address at any one time, but its other devices also take up room in that same space. The video card, the motherboard, and everything else like that within the realm of your computer steals even more of that 4096 MB space, meaning the original operating system has even less to work with.

Think of it this way: you are standing in a 10-acre field. That field is the overall memory of your technological device. Now, you want to build a barn for everything to function in, so you build a board that’s 4 acres in diameter. That barn is your entire operating system: it’s 4 acres, but it can’t utilize any of the other 6 acres that outside the walls of the barn.

Then, in come the animals, the feed, the tackle equipment, the office space, the whiteboards to keep the animals on schedule, and everything else the barn needs to run efficiently. The animals and the feed are like the video card and the motherboard—they fit inside of that barn (or the operating system), but they are only allowed to function within that barn. This means that the more things you add to the barn (or your operating system), the less space you have to move around in that barn (as in, your “walking space.”)

Overstuff your barn, and you can’t walk around in it any longer, even though you have 6 acres you can expand into.

Make a little more sense?

With the 64-bit versions of the Linux operating system, it can access 17.2 billion GB of system memory at a time. This effectively banishes all limits of computer access far into the future. This also means your video card, motherboard, and all other peripherally-working systems within your computer will no longer be taking up the much needed space within the memory of the operating system. Because of this massive upgrade, more people have switched to using 64-bit versions of all operating systems on the open market, and this has led to all of your favorite applications and programs being revamped so they work flawlessly on this type of operating system version.

The reason why we say to default to the 32-bit version if you aren’t sure is because these versions are perfect for low-level applications and programs. If you are a true beginner, this will allow you to tinker with the basics before getting ahead of yourself and clogging your computer up with programs you don’t know how to navigate yet.

A 32-bit version essentially puts a temporary muzzle on you and forces you to get to intimately know Linux and your computer before opening up the floodgates and submerging yourself entirely. However, if you want the best right out of the gate, go with the 64-bit version and don’t look back!

Now, once you have the version you want, download the main file. This is usually an ISO file that will download itself onto the computer you are using (and that has the ability to burn disks). After the initial file is done downloading (and it might take a while, so go get some coffee), open up the burning program you are going to use and burn that program onto a blank CD.

Then, after it’s done burning (and please make sure it’s before you do this), eject the CD and put it into the computer you want to install Linux onto. Make sure your computer is off when you insert the CD, but if your computer is on when you do, just restart it. When your computer begins to boot itself up (or reboot itself, if you had to), there will be a sign prompting you to “press any key to boot from CD.” Press a key and let the CD boot up your computer. After it does, it will give you a prompt screen that will ask whether you want to install Linux or try it out. Click the option to install it and wait for the launcher to pop up. Then, simply follow the command prompts in order to download it to your computer!

Now, this is already assuming you know you want this desktop environment. If you are still trying things out, simply click the option to try out the Linux program and it will load the operating system without actually installing it!

However, if you have chosen to download it, you can launch the installer right from your desktop. Once you have tried it out and found that you do wish to use this desktop environment, there should be a desktop icon that denotes the fact that a burned CD is within the computer. Right-click it and choose “download,” and follow the command prompts that pop up after that!

There is another way to download Linux that’s very easy, and this is via the live USB method. This way will also require a computer that’s not the computer you are loading Linux onto, so make sure you have one available that has at least one USB port. To begin, simply go to the main Linux website and find the version of the operating system you want. Download the .ISO file onto the computer, then open up the USB thumb drive on your computer.

If you don’t know how to open up a thumb drive on your computer, it’s usually pretty simple: if the window for the thumb drive doesn’t open up after automatically inserting it, then find the “file manager” program and open it. A window should pop up, and to the left of the window should be a listing of all the main files and folders for your computer. One should be labeled “thumb drive” or “USB,” and that’s the one you want to open.

Once the file is done downloading, click and drag the file from your computer desktop to the “thumb drive” or “USB” file you have opened in that previous window. Give it some time to transfer the file from the desktop to the thumb drive, and when it’s done, eject the thumb drive from the computer and go over to the technological device you want to install Linux onto.

Now, this way will take a couple more steps, but we will walk you through it. Insert your USB thumb drive into the computer in question and turn on (or restart) your computer. But, as soon as the computer restarts or begins booting up, hold down the “Delete” button. This will start your computer up in something called a BIOS setup. Once the bootloader screen pops up, there will be several prompts on it asking you what you want to do. Click on the “Boot” section of the BIOS setup and look for the section that says something to the effect of “change PC boot order.”

Once you choose it, you should have several different things that are set in a specific order. This boot order means that, upon booting up your computer, these ports are the first to register. Your CD drive should be near the top, which is why using the live CD doesn’t require these steps. Most computers are setup to quickly read what’s in the CD drive before it does anything else.

Find the option that says “USB hard drive” and move that to the top of the list. Save the settings, exit the BIOS, and then restart your computer, all while the thumb drive is still inserted. Once your computer reboots itself, it should take you to the main menu, where you can now boot into and choose to install the Linux operating system you have chosen!

Keep in mind, each distro (or distribution of a different Linux operating system desktop environment) will have slightly different needs once the installation process begins, but this is how you begin this process. All of the screens will prompt you and tell you what you need to do in order to continue the installation, so take a deep breath and try not to feel too overwhelmed.

Once you have Linux installed on your computer, it’s time to delve into the main purpose many people choose Linux for in the first place: coding and programming.

Linux Applications

Linux distributions come pre-installed with applications for your computing needs.

Office Applications

Libre-Offfice suite is Linux’s answer to Windows Office tools. The suite comes with a word processor, presentation application, spreadsheet, calendar, and calculator applications. If you are a Windows user, you might need some time to get familiar to the interface, but after a few times using the apps, you’ll eventually be familiar with it.

LibreOffice comes with the following applications:

Writer – word processor. Files are created with a .odt file extension. Documents written with Microsoft Word are compatible with Writer. 

How Writer Looks Like

Calc – spreadsheet program that works similar to Microsoft Excel. Default file has .ods file extension

Calc Looking Like Microsoft Excel

Impress – the counterpart of Microsoft PowerPoint. In Impress, you can make slide presentations based from existing templates or you can also customize the same way that you can do in Microsoft Office.

Made to Impress

All Libre-Office applications can be accessed from the Office option in the Main Menu.

Multimedia Applications

How about accessing multimedia? Linux distributions come with apps that allow you to open photos, listen to audio files, play videos, and burn CDs or DVDs. 

SUSE and Xandros distributions are pre-installed with digiKam, a digital camera software. You also have the option to access your photos as files from a USB drive. Simply click on the storage drive name and view the photos.

Both KDE and GNOME come with an audio CD player. Put your CD in and the default audio player will detect and play the audio. For other sound files like MP3s, you can use players such as XMMS or Rhythmbox. Depending on the distro that you are using, you can go to the Music Player application, Multimedia or Sound & Video category to open the players.

Imaging Applications

Linux also ensures that you get the photo editing and graphics creation applications that you need. The two most popular in the Linux world is The GIMP (GNU Image Manipulation Program) and GNOME Ghostview (GGv).

The GIMP is the equivalent of Adobe Photoshop. Users can perform image manipulation, composition, and creation. If you cannot find GIMP in the Graphics category from the main menu, check if you need to install the package first. Refer to the steps in the section Installing Additional Software to download and install The GIMP package. The application can read most image formats: JPEG, TIFF, PNG, PCX, and GIF. For more information about GIMP, visit their website at www.gimp.org  

GNOME Ghostview can read a PostScript or PDF documents and has similar functionalities as Acrobat Reader. To open Ghostview on a Fedora computer, click on Graphics, then PostScript Viewer.

Explore the pre-installed applications and gauge if these suit your needs. Remember, there are plenty of Linux applications that you can use, so go ahead and find the best one for you.

The Linux Desktop

Now that your Linux system has been installed or you have booted into the LiveDVD mode we will examine the desktop environment.  Even though this is a book about the Linux command line, most Linux distributions come with a graphical user interface (GUI) desktop that you will need to navigate in order to get to the command line interface (CLI).

The following desktop versions of Linux will be covered in this chapter:

Ubuntu Desktop

Debian Desktop

Fedora Desktop

Mint Desktop

This is not a complete list of every version of Linux but rather a listing of the most popular distributions.  Some of the Linux distributions, such as Ubuntu, Debian, and Fedora have server versions that do not some with a GUI and all configurations are done on the CLI.

Ubuntu Desktop

Ubuntu Unity desktop right after the first boot.  Unity is the name of the default Ubuntu desktop manager.  There are other desktop managers that can be used with Ubuntu, but Unity is the most popular.

When logging into Ubuntu for the first time you will be presented with a Keyboard Shortcuts window.   Clicking the X in the upper left hand corner of the Keyboard Shortcuts window will close the window.  If you want to see the Keyboard Shortcuts again just hold the Super button, also know as the Window button, for 2-3 seconds.  The Super button is normally found at the bottom of the keyboard on the left hand side to the left of the Alt key.  

The Ubuntu Desktop - Keyboard Shortcuts

One shortcut that is missing from the Keyboard Shortcuts menu is Ctrl+Alt+T which will open up a terminal window.

The Ubuntu Desktop - Terminal window

The very top icon on the Launcher is the Unity Dash search application which will bring up a search box that will let you search for any application installed on your Ubuntu system, Figure 3-3.  

Unity Dash Icon

You can also bring up the search box by pressing, not holding, the Super key.

Searching for Applications

Typing Terminal in the search box will bring up the Terminal application which can then be launched by clicking on the Terminal icon,  

Terminal Application

Once the Terminal application is open a Terminal icon will appear in the Launcher on the left-hand side of the screen.  You can lock the Terminal icon to the Launcher so that the icon will always be available to launch to the Terminal application by right clicking on the icon and selecting Lock to Launcher.

Terminal Application

Debian Desktop

Gnome is the default Debian desktop manager.  There are other desktop managers that can be used with Debian but Gnome is the most popular.

Debian Gnome Desktop

The very top icon on the right of the desktop is Activities which will bring up a search box at the top of the desktop that will let you search for any application installed on your Debian system and a Favorites bar on the left-hand side,

Debian Gnome Desktop - Search and Favorites

Typing Terminal in the search box will bring up the Terminal application which can then be launched by clicking on the Terminal icon, Figure 3-5.

Debian Gnome Desktop - Terminal Application

Right clicking on the Terminal icon will allow you to add the icon to the Favorites bar for easy access in the future,.

Debian Gnome Desktop - Add to favorites

shows the Debian Terminal.

Debian Gnome Desktop - Terminal

Fedora Desktop

Fedora Gnome desktop right after the first boot.  Gnome is the default Fedora desktop manager.  There are other desktop managers that can be used with Fedora, but Gnome is the most popular.

Fedora Gnome Desktop

The very top icon on the right of the desktop is Activities which will bring up a search box at the top of the desktop that will let you search for any application installed on your Fedora system and a Favorites bar on the left-hand side. 

Fedora Gnome Desktop - Search and Favorites

Typing Terminal in the search box will bring up the Terminal application which can then be launched by clicking on the Terminal icon,

Fedora Gnome Desktop - Terminal Application

Right clicking on the Terminal icon will allow you to add the icon to the Favorites bar for easy access in the future.

Fedora Gnome Desktop - Add to favorites

Fedora Terminal.

Fedora Gnome Desktop - Terminal

Mint Desktop

Mint Linux Cinnamon desktop right after the first boot.  Cinnamon is the default Mint Linux desktop manager.  There are other desktop managers that can be used with Mint Linux but Cinnamon is the most popular.

. Mint Linux Cinnamon Desktop

Like Ubuntu with Mint Linux is based upon, Ctrl+Alt+T which will open up a terminal window,.

Mint Linux Cinnamon Desktop - Terminal

You can also access the Terminal by clicking on the Terminal icon on the Panel at the bottom of the desktop.

Mint Linux Cinnamon Desktop - Terminal icon

The Terminal can also be accessed by clicking on Menu and then selecting Terminal icon on the Panel on the left side of the Menu window.

Mint Linux Cinnamon Desktop - Menu - Terminal icon

Basic Administration and Security

Your system is now up and running. The next thing you should think about is securing it. System administrators consider two aspects of security– host security and network security. If multiple users are using a computer, user directories and files should be secured and should not be accessed by any unauthorized person. Since your computer is connected to the internet, you have to protect it from access over the internet too. Let’s discuss these in the next sections.

Basic System Administration

Similar to popular operating systems like Windows and Mac OS, Linux distributions also come with the GUI tools that can be used for performing administrative tasks. Adding and removing user accounts, performing software upgrades, managing hardware, installing new applications, maintaining the system’s performance, and setting up and monitoring security are some of the activities that an administrator executes.

SUSE YaST for Administrative Tasks

These functionalities are also available in Ubuntu and Fedora distributions. 

Settings Screen for Ubuntu

Settings Screen for Fedora

Monitoring System Performance

To effectively monitor your computer’s performance, the following aspects should be checked:

CPU and Memory Usage

To see the processes that are consuming the most CPU resources and memory allocation, use the top command. This command displays the CPU load and used memory averages, the process IDs, the percentage of CPU used by the process, and the percentage of the memory used. The top command results are refreshed every 5 seconds. To exit the top command output display, press Q.

top command

To get a snapshot of the system status at the time the command was issued, use uptime. This command prints the load average for the last one, five, and fifteen minutes.

Hard disk space

Monitor the hard disk space to ensure that there is enough space for the system to perform tasks such as logging and backups. Use thedf -h command to validate the disk space. 

Here’s a sample output: 

In the monitoring, set specific thresholds at which you, as the administrator will take an action. For example, once the used disk space percentage reaches a certain threshold, like 80%, do a file cleanup to free up disk space. If the CPU reaches the allowed threshold, investigate which processes are using up the resources and do the necessary action (e.g. wait for a process to finish, kill a process, etc.). This is similar to killing processes in windows using the Task Manager.

User Management

Linux automatically creates multiple user accounts upon installation, even if you are the only one using your computer. The system uses these accounts for running programs. Different accounts safeguard the system, including files and directories, from unauthorized access. Users can be assigned to groups for easier facilitation.

To add, modify, or delete a user or group account, you can either use the GUI or do it via the command line. As a beginner, it would be good for you to try out both so you can see which one the best method for you is.

Managing Users and Groups Via GUI

Open YaST if you are using SUSE or the equivalent Settings Menu in your distribution. Click on the Security and Users or any similar User Management category.

YaST Add User

Click on the Add user button and supply the necessary information such as the user’s full name, preferred username, and password. You can explore and configure additional information such as login attempt limit, password settings, and user groups. Once done, click on the OK button to continue creating the user account.

You can also modify or delete an account using the GUI. Perform the necessary account modifications and click on the OK button to proceed with the changes.

To create, modify, or delete a group, select Groups instead of users. The photo below shows the YaST screen for adding a new group. Provide the necessary information and click on the OK button to finish creating the group.

Add Group

Managing Users and Groups via CLI

Adding a new user via CLI consist only of a few lines of command. First, login as root by using the commandsu – 

Use the command below to create a new account:

Next, set the password. Once you issue the command below, you will be prompted twice to enter and confirm the password. 

To modify an account, use theusermod command, paired with the option that pertains to the information that you want to modify. To delete the user account, use the/usr/sbin/userdel username command.

To add a user group, you need to use the commandgroupadd groupname

For example, let’s create a group named office. To create this group, enter the command below.

Since Kevin is a colleague at work, we will add him to the office group. To do this, use the command below:

To delete the group, use the commandgroupdel office

Again, I encourage you to use themancommand to know more about the options that can be used for a specific command.

File Ownership

A user and group account owns a Linux file or directory. To see the owner of a particular file, use the command 

Here is a sample output of the command. Choose a filename and try it on your terminal too!

The first set of letters stands for the permission settings (execute, read, write). The second part with the value of kjones office signifies the user account and the group account that owns the file.

In case you want to change the ownership of the file fromkjones to another userrbentley, login as root and use the command below:

Also, to change the group owner of the file, input the command: 

Basic Security in Linux

Setting-up Passwords

When creating an account, make it a point as an administrator to create strong passwords that are difficult to crack. Remember to stay away from passwords formed from personal information (such as birthdays, street address, or names), single words that can be found in the dictionary, and simple combinations of alphanumeric numbers.

Use a password that contains mixed case (upper and lower- case letters), has numbers or punctuations, or is written in reverse order. Also implement other preventive mechanisms such as prompting the user to change his password every X number of days and to lock an account after Y number of login attempts.

Files Protection

To protect files from unauthorized access (viewing and modifying), revisit your file permissions setting. In the preceding section, we talked about assigning the user and group owner for a file. Next, we need to specify the correct file permissions for the owner, the group, and global (all other users).

Let’s go back to the result of an ls command: 

The first set of letters (in green) signifies the file permissions for the user. The next set (in blue) is for the group, while the section in orange stands for the global permission.

r – permitted to read the file contents

w – permitted to write on the file

x – permitted to execute (if the file contains a bash script)

This means that kjones has read and write permissions to the file. This is the same permission as the office group account. All other users (global) will only be allowed to read the file. 

To change permissions, use the octal representation of the permission and specify the value for the 3 levels (user, group, and global).

Permission

Representation

rwx

7

rw-

6

r—

4

r-x

5

—x

1

Table 11: Permission Values

Let’s now try to remove the write access from the group. 

When you list the details for file1.txt again, the write access for the group should be already removed.

There are several ways to secure your system such as setting up firewalls, securing internet services, encrypting files, and using digital certificates.

Using the Shell

Effective Linux professional is unthinkable without using the command line.

The command line is a shell prompt that indicates the system is ready to accept a user command. This can be called a user dialogue with the system. For each command entered, the user receives a response from the system:

1. another invitation, indicating that the command is executed and you can enter the next.

2. error message, which is a statement of the system about events in it, addressed to the user.

Users who are accustomed to working in systems with a graphical interface, working with the command line may seem inconvenient. However, in Linux, this type of interface has always been basic, and therefore well developed. In the command shells used in Linux, there are plenty of ways to save effort, that is, keystrokes when performing the most common actions:

Automatic addition of long command names or file names

Searching and re-executing a command that was once performed before

Substitution of file name lists by some pattern, and much more

The advantages of the command line are especially obvious when you need to perform similar operations on a variety of objects. In a system with a graphical interface, you need as many mice dragging as there are objects, one command will be enough on the command line.

This section will describe the main tools that allow you to solve any user tasks using the command line: from trivial operations with files and directories, for example, copying, renaming, searching, to complex tasks requiring massive similar operations that occur as in the user's application work, when working with large data arrays or text, and in system administration.

Shells

A command shell or command interpreter is a program whose task is to transfer your commands to the operating system and application programs, and their answers to you. According to its tasks, it corresponds to command.com in MS-DOS or cmd.exe in Windows, but functionally the shell in Linux is incomparably richer. In the command shell language, you can write small programs to perform a series of sequential operations with files and the data they contain — scripts.

Having registered in the system by entering a username and password, you will see a command line prompt – a line ending in $. Later this symbol will be used to denote the command line. If during the installation a graphical user interface was configured to start at system boot, then you can get to the command line on any virtual text console. You need to press Ctrl-Alt-F1 - Ctrl-Alt-F6 or using any terminal emulation program, for example, xterm.

The following shells are available. They may differ depending on the distributor:

bash

The most common shell for Linux. It can complement the names of commands and files, keeps a history of commands and provides the ability to edit them.

pdkdh

The korn shell clone, well known on UNIX shell systems.

sash

The peculiarity of this shell is that it does not depend on any shared libraries and includes simplified implementations of some of the most important utilities, such as al, dd, and gzip. Therefore, the sash is especially useful when recovering from system crashes or when upgrading the version of the most important shared libraries.

tcsh

Improved version of C shell.

zsh

The newest of the shells listed here. It implements advanced features for autocompletion of command arguments and many other functions that make working with the shell even more convenient and efficient. However, note that all zsh extensions are disabled by default, so before you start using this command shell, you need to read its documentation and enable the features that you need.

The default shell is bash Bourne Again Shell. To check which shell you're using, type the command: echo $ SHELL.

Shells differ from each other, not only in capabilities but also in command syntax. If you are a novice user, we recommend that you use bash, further examples describe the work in this particular area.

Bash shell

The command line in bash is composed of the name of the command, followed by keys (options), instructions that modify the behavior of the command. Keys begin with the character – or –, and often consist of a single letter. In addition to keys, after the command, arguments (parameters) can follow – the names of the objects on which the command must be executed (often the names of files and directories).

Entering a command is completed by pressing the Enter key, after which the command is transferred to the shell for execution. As a result of the command execution on the user’s terminal, there may appear messages about the command execution or errors, and the appearance of the next command line prompt (ending with the $ character) indicates that the command has completed and you can enter the next one.

There are several techniques in bash that make it easier to type and edit the command line. For example, using the keyboard, you can:

Ctrl-A

go to the beginning of the line. The same can be done by pressing the Home key;

Ctrl-u

delete current line;

Ctrl-C

Abort the execution of the current command.

You can use the symbol; in order to enter several commands in one line. bash records the history of all commands executed, so it’s easy to repeat or edit one of the previous commands. To do this, simply select the desired command from the history: the up key displays the previous command, the down one and the next one. In order to find a specific command among those already executed, without flipping through the whole story, type Ctrl-R and enter some keyword used in the command you are looking for.

Commands that appear in history are numbered. To run a specific command, type:

! command number

If you enter !!, the last command typed starts.

Sometimes on Linux, the names of programs and commands are too long. Fortunately, bash itself can complete the names. By pressing the Tab key, you can complete the name of a command, program, or directory. For example, suppose you want to use the bunzip2 decompression program. To do this, type:

bu

Then press Tab. If nothing happens, then there are several possible options for completing the command. Pressing the Tab key again will give you a list of names starting with bu. For example, the system has buildhash, builtin, bunzip2 programs:

$ bu

buildhash builtin bunzip2

$ bu

Type n> (bunzip is the only name whose third letter is n), and then press Tab. The shell will complete the name and it remains only to press Enter to run the command!

Note that the program invoked from the command line is searched by bash in directories defined in the PATH system variable. By default, this directory listing does not include the current directory, indicated by ./ (dot slash). Therefore, to run the prog program from the current directory, you must issue the command ./prog.

Basic commands

The first tasks that have to be solved in any system are: working with data (usually stored in files) and managing programs (processes) running on the system. Below are the commands that allow you to perform the most important operations on working with files and processes. Only the first of these, cd, is part of the actual shell, the rest are distributed separately, but are always available on any Linux system. All the commands below can be run both in the text console and in graphical mode (xterm, KDE console). For more information on each command, use the man command, for example:

man ls

cd

Allows you to change the current directory (navigate through the file system). It works with both absolute and relative paths. Suppose you are in your home directory and want to go to its tmp / subdirectory. To do this, enter the relative path:

cd tmp /

To change to the / usr / bin directory, type (absolute path):

cd / usr / bin /

Some options for using the command are:

cd ..

Allows you to make the current parent directory (note the space between cd and ..).

cd -

Allows you to return to the previous directory. The cd command with no parameters returns the shell to the home directory.

ls

ls (list) lists the files in the current directory. Two main options: -a - view all files, including hidden, -l - display more detailed information.

rm

This command is used to delete files. Warning: deleting the file, you cannot restore it! Syntax: rm filename.

This program has several parameters. The most frequently used ones are: -i - file deletion request, -r - recursive deletion (i.e. deletion, including subdirectories and hidden files). Example:

rm -i ~ / html / *. html

Removes all .html files in your html directory.

mkdir, rmdir

The mkdir command allows you to create a directory, while rmdir deletes a directory, provided it is empty. Syntax:

mkdir dir_name

rmdir dir_name

The rmdir command is often replaced by the rm -rf command, which allows you to delete directories, even if they are not empty .

less

less allows you to page by page. Syntax:

less filename

It is useful to review a file before editing it; The main use of this command is the final link in a chain of programs that outputs a significant amount of text that does not fit on one screen and otherwise flashes too quickly . To exit less, press q (quit).

grep

This command allows you to find a string of characters in the file. Please note that grep searches by a regular expression, that is, it provides the ability to specify a template for searching a whole class of words at once. In the language of regular expressions, it is possible to make patterns describing, for example, the following classes of strings: “four digits in a row, surrounded by spaces”. Obviously, such an expression can be used to search in the text of all the years written in numbers. The search capabilities for regular expressions are very wide. For more information, you can refer to the on-screen documentation on grep (man grep). Syntax:

grep search_file

ps

Displays a list of current processes. The command column indicates the process name, the PID (process identifier) ​​is the process number (used for operations with the process — for example, sending signals with the kill command). Syntax:

ps arguments

Argument u gives you more information, ax allows you to view those processes that do not belong to you.

kill

If the program stops responding or hangs, use this command to complete it. Syntax:

kill PID_number

The PID_number here is the process identification number, You can find out the process number for each executable program using the ps command. Normally, the kill command sends a normal completion signal to the process, but sometimes it does not work, and you will need to use kill -9 PID_number. In this case, the command will be immediately terminated by the system without the possibility of saving data (abnormal). The list of signals that the kill command can send to a process can be obtained by issuing the command kill -l.

File and Directory Operations

Here we consider utilities that work with file system objects: files, directories, devices, as well as file systems in general.

cp

Copies files and directories.

mv

Moves (renames) files.

rm

Removes files and directories.

df

Displays a report on the use of disk space (free space on all disks).

du

Calculates disk space occupied by files or directories.

ln

Creates links to files.

ls

Lists files in a directory, supports several different output formats.

mkdir

Creates directories.

touch

Changes file timestamps (last modified, last accessed), can be used to create empty files.

realpath

Calculates absolute file name by relative.

basename

Removes the path from the full file name (i.e., shortens the absolute file name to relative).

dirname

Removes the file name from the full file name (that is, it displays the full name of the directory where the file is located).

pwd

Displays the name of the current directory.

Filters

Filters are programs that read data from standard input, convert it and output it to standard output. Using filtering software allows you to organize a pipeline: to perform several sequential operations on data in a single command. More information about standard I / O redirection and the pipeline can be found in the documentation for bash or another command shell. Many of the commands listed in this section can work with files.

cat

combines files and displays them to standard output;

tac

combines files and displays them on standard output, starting from the end;

sort

sorts rows;

uniq

removes duplicate lines from sorted files;

tr

performs the replacement of certain characters in the standard input for other specific characters in the standard output, can be used for transliteration, deletion of extra characters and for more complex substitutions;

cut

systematized data in text format can be processed using the cut utility, which displays the specified part of each line of the file; cut allows you to display only the specified fields (data from some columns of the table in which the contents of the cells are separated by a standard character — a tabulation character or any other), as well as characters standing in a certain place in a line;

paste

combines data from several files into one table, in which the data from each source file make up a separate column;

csplit

divides the file into parts according to the template;

expand

converts tabs to spaces;

unexpand

converts spaces to tabs;

fmt

formats the text in width;

fold

transfers too long text lines to the next line;

nl

numbers file lines;

od

displays the file in octal, hexadecimal and other similar forms;

tee

duplicates the standard output of the program in a file on disk;

Other commands

head

displays the initial part of the file of the specified size;

tail

outputs the final part of a file of a given size, since it can output data as it is added to the end of the file, used to track log files, etc.;

echo

displays the text of the argument on the standard output;

false

does nothing, comes out with a return code of 1 (error), can be used in shell scripts if an unsuccessful command is being attempted;

true

does nothing, comes out with a return code of 0 (successful completion), can be used in scripts if a successful command is required;

yes

infinitely prints the same line (by default, yes) until it is interrupted.

seq

displays a series of numbers in a given range of successively increasing or decreasing by a specified amount;

sleep

suspends execution for a specified number of seconds;

usleep

suspends execution for a specified number of milliseconds;

comm

compares 2 pre-sorted (by the sort command) files line by line, displays a table of three columns, where in the first are lines unique to the first file, in the second are unique to the second, in the third they are common to both files;

join

combines lines of two files on a common field;

paste

For each pair of input lines with the same common fields, print the line to standard output. By default, the general field is considered first, the fields are separated by whitespace.

split

splits the file into pieces of a given size.

Calculations

In addition to simple operations with strings (input/output and merging), it is often necessary to perform some calculations on the available data. Listed below are utilities that perform calculations on numbers, dates, strings.

test

returns true or false depending on the value of the arguments; The test command is useful in scripts to check conditions;

date

displays and sets the system date, in addition, it can be used for calculations over dates;

expr

evaluates expressions;

md5sum

calculates checksum using MD5 algorithm;

sha1sum

calculates checksum using SHA1 algorithm;

wc

counts the number of lines, words, and characters in the file;

factor

decomposes numbers into prime factors;

Search

The search for information in the file system can be divided into a search by file attributes (understanding them extensively, that is, including the name, path, etc.) and content search. For these types of search, the programs find and grep are usually used, respectively. Thanks to convenient interprocess communication tools, these two types of search are easy to combine, that is, to search for the necessary information only in files with the necessary attributes.

Attribute search

The main search tool for file attributes is the find program. A generalized call to find looks like this: find path expression, where path is a list of directories in which to search, and expression is a set of expressions that describe the criteria for selecting files and the actions to be performed on the files found. By default, the names of found files are simply output to standard output, but this can be overridden and the list of names of found files can be transferred to any command for processing. By default, find searches in all subdirectories of directories specified in the path list.

Introduction to Command Line

So far you have seen the use of command line for installation purposes. From now I on, I will explain not only the directory structure of any UNIX based system but also the perks of command line. You might be wondering what UNIX is, Is simpler words, UNIX is an operating system and all the modern Linux distributions are based on UNIX. You can say that UNIX is the back bone of all the operating systems that we see today. Many of the things that were introduced in UNIX were refined in later years to create modern day operating systems.

Command Line in Linux can be described as a platform that is used to do almost everything possible in Linux. Most developers or advanced Linux users prefer using command line over graphical user interface because of the level of control the command line provides. Words like bash, terminal, shell scripting and command line are used interchangeably. You can imagine the power of a terminal by the fact that you can create or rename hundreds or more files and folders with a single command using the terminal. Doing so with the graphical user interface can be so tedious. Developers and advance Linux users tend to use the terminal for running scripts of Python and Perl. Python and Perl are programming languages. You can connect to other computers remotely by using the secure shell (SSH) connection. Secure shell connection allows you to use the command line of another system remotely. You can practically do anything if you have the root privileges, using the command line. 

You can copy, move, create files not only onto different drives of your computer but also you can download files over the network using the terminal. In Linux, there are many programs that only work in the terminal. For example, tools like nmap, metasploit etc. work only inside the terminal. By using a terminal, you can change the privileges of a file, like you can change whom can edit or delete a particular file. You can also encrypt your files using the terminal. These were some of the uses of the command line that I recalled over the top of my head. I’m sure you can find other ways in which command line is useful.

In order to understand the shell, you must first learn a few things about the directory structure or LINUX. In order to see the directory structure in Linux you should use the ls command.

By default when you open a terminal, your default location is the Home folder.

In order to move around other directories and folders you should use the cd command. The following example shows that how you can use the cd command in the terminal.

cd //

The command above will change your directory to the system folder. In order to list the contents of this directory see the following example:

Example:

ls

Output:

bin dev home lib64 mnt  proc run srv tmp var boot etc lib lost+found opt root sbin sys usr

Each term or keyword shown in the output of the aforementioned example, is the name of a folder. For example bin and dev are two different directories and they serve a different purpose in the Linux World. 

The initial directory that we were in was the root directory. That directory will always be considered whenever you open a terminal window. In order to move in to other folders, you need to tell command line the path where you want it to switch too. Changing directories allows you to perform task on files available inside those directories. A general example of Linux path is:

/etc/somedir/anotherdir/Textfile.txt

The directory structure in Linux is like a tree. The directory etc in the example above will be at the top of the tree. Somedir will be a sub branch of etc and it will contain anotherdir. Inside anotherdir, a text file could be present. The name of that fictitious text file can be Textfile.txt. I used the tree analogy because it’s very simple and it makes things a bit easier to understand.

In order to check the current directory, you can use the pwd command. Passing the pwd command will print out the full path of the directory in which your terminal is open.

Example:

root@archserver ~]# pwd

Output:

/root

In the example above, you are seeing [root@archserver ~]#. This is basically the username and the name of my Linux machine. You might see something different if you were to log in as a different user, or the name of your Arch Linux Machine is different. The tilde sign ~ in the signature, means that I’m in the Home directory. If I change my working directory, the name of the current working folder will replace the ~ sign. For example, I am going to first list the contents of my home directory using the ls command. Then I will change my directory using the cd command.

Example:

[root@archserver ~]# ls

archcinnamon  Desktop  Downloads  PySonar  PySyft  ql_secure_installation

[root@archserver ~]# cd Downloads/

[root@archserver Downloads]#

The second line in the example above shows the name of all the folders and Files present in my Home directory. I wanted to change my directory from Home folder to Downloads folder. So I used the cd Command. Linux Command Line is case sensitive so Downloads and downloads can be two different things, as far as the terminal is concerned.

[root@archserver ~]# cd downloads/

bash: cd: downloads/: No such file or directory

See the example above, you will find that the terminal returned an error stating that it doesn’t recognize a directory named: downloads. Another thing you must know about the terminal is that is keeps a history of every command, whether correct or incorrect that you use. If you go on and press the up-arrow head key on your keyboard, you will see the last command that you entered. The more times you press the up-arrow key, the older command will be presented to you. Using the tab button on your keyboard you can complete a term, a name of folder/file or a command. It’s like a built in auto complete feature available in the shell. Go back to your home directory by using the following command.

[root@archserver Downloads]# cd ..

[root@archserver ~]#

Now that you have returned to the home Directory, try going back to the Downloads directory, but don’t write the entire word. Write only cd Down and then press tab. You will see that the command line automatically completed your command to cd Downloads/. If you want to see all the commands that you entered in the terminal use the history command. The output will be similar to the following example:

Example:

[root@archserver ~]# history

1  nano /etc /local.gen

2  No

3  clear

4  nano /etc/locale.gen

5  locale-gen

6  nano /etc/locale.conf

7  nano /etc/locale.conf

8  ls /usr/share/zoneinfo

9  ls -s /usr/share/zoneinfo/Asia/Karachi /etc/localtime

10  hwclock—systohc—GMT+5

11  hwwwclock—systohc—GMT

12  hwclock—systohc—gmt

13  hwwwclock—systohjhc—utsc

14  passwd

15  nano /etc/hostname

16  systemmmsesectl enables msjsdhcpcd

17  pacmansss -Ssa gsrub os-prober

18  grub-install /dev/sd

19  grub-install /dev/sda

20  grubb - msakcsonfig -o /boost/grsub/grusb.cafg

21  reboot

22  reboot

23  exit

24  $ sudooo paacmaan -Syuuuu

25  sudo pacman -Syu

26  sudo pacman -S bash-completion

27  sudo pacman -S xorg-server xorg-xint xorg-xutils xorg-server-utils mesa

28  sudoooo paacmaaaan -Ss xorgs-sservers xsorsg - sxisnsist xorg-utils xorg-server-utils mesa

29  sudo pacman -S xorg - server xorg - xinit xorg – server - utils mesa

30  sudo pacman -S xorg - server xorg - xinit xorg - apps mesa

31  sudo pacman -S xorg - server xorg - xinit xorg - apps mesa

32  sudo pacman -S xorg - server xorg - xinit xorg - apps mesa

33  shutdown

34  sudo pacman -S xorg - server xorg - xinit xorg – a pps mesa

35  sudooo paaacmaaan -Ssss xxxorg - tttwm xxxterm xxx org - xclock

36  sudooo paaacmaaan -Sss xf8346 – inputs - sssynaptics

37  lsssspcis | gaarep VGAaaa

38  sudoooo paaacmaaaan -Sssss | grrrep xrrrf86 - video

39  sudo pacman -S  

40  sudo pacman -S xf86-video-intel

41  sudo startx

42  sudo startx

43  exit

44  sudo startx

45  shutdown

46  pacman -Rsc xorg-server

47  pacman -Rsc xorg-apps

48  sudo pacman -S xorg-server xorg-xinit mesa

49  sudo pacman -S xorg-apps mesa

50  startx

51  shutdown

52  exit

53  sudo pacman -S mesa

54  sudo pacman -S mesa xf86-video-vesa

55  pacman -S xf86-input-synaptics

56  startx

57  var/log

58  var/log/Xorg.o.log

59  /var/log/Xorg.0.log

60  sudo /var/log/Xorg.0.log

61  ls -l /var/log/Xorg.0.log

62  /var/log/Xorg.0.log

63  /usr/share/X11/xorg.conf.d

64  clear

65  pacman -Rn xorg

66  pacman -Rsc xorg-apps

67  pac

68  sudoooo paaaacmaan -Ss xorg - servesrs xsosrsg - sxinit xorgs - u tils xsa org –a psps mesa

69  pacman -Rsc mesa

70  pacman -Rsc libgl

71  pacman -Rsc xorg-twm

72  pacman -Rsc xorg-xclock

73  pacman -Rsc

74  pacman -Rsc xf86-video-intel

75  sudoooo paacamaan –Sass | gsarep x fs 8s6 - vsasideo

76  sudooao pfdsacman - Ssdsayu[dA

77  ssusdsos pascsmsasn -sSs sxosrg - sesrsver xsosrg - xsisnit xsosrsg - asssppss mesa

78  sudo pacman -S axsosrsgs - stswm xstsesrsm xsosrgs - xscslsock

79  sudo pacman -S mesa xf86-video-vesa

80  pacman -S xf86-input-synaptics

81  suod pacman linux-headers

82  sudo pacman linux-headers

83  susdsos spsascsmans -sSs slisnsusx - hsesasdesrs

84  sudo mount /dev/cdrom /mnt

85  cd /mnt

86  ls

87  sudo ./VBoxLinuxAdditions.run  

88  susdsos psascsmasn s - sSsyu

89  startx

90  susdso psascsman -sSs cisnsnasmsons nsesmo -  sfilesrsoller

91  ssusdso spsascmsan s-sS sgdms

92  sssusdo ssysstsemctl sensasble gdsms

93  sssudso syssstesmctsl stsarst gsdsm s

94  sudo pacman -S net-tools

95  sxudxo pxaxcxmaxn -xSx nxetxwork –xmaxnxaxger -axpxpxlet

96  ssusdsos sssysstemcstl sstsop dshscp @ esnss3s3.ssesrvsice

97  susdos sysstemcstl stsosp dhcpssscsd @ enss33.sservicse

98  susdso systsemscstsl dissasbsle dshscpscd @ essnss33.ssesrvice

99  susdso ssyssstsesmctl sstsops dshscpscsd .ssesrsvsice

100  ssusdso ssyssstsemscstl dsissasbsle dshscpscsds.sssersvsice

101  ssusdso ssyssstsesmcstl ssstasrts Nestwsosrsk Msanasgsser

102  susdsos ssysstsedmcftl ensasable Nesatwsoarsk Masaanager

103  sudo systemctl start dhcp@ens33.service

104  susdso ssysstsemctsl sstsart sNetswsork Masnsasger

105  susdsos syssstesmsctsl esnsabsle dshcspscsd. ssesrsvice

106  ssusdos ssysstsesmctl esnasbsle dshscpscd @ sessnsss33.ssse rvsice

107  sxuxdxo ssyssstemctl esnsasble Nsestwsosrsks Mansasger

108  ssusdo ssysstesmctl sstsarst dhscpscd. ssersvsice

109  susdsos syssstsemsctsl stsasrst dhcspscsd @ essnsss33.ssersvsice

110  sudo systemctl start dhcpcd@ens33.service

111  sussdos ssysstesmscstl sstsasrt NetworkManagerc

112  clear

113  ssusdso syssstesmctl sstsop dhscspcsd  @ sesnss33. service

114  sudo systemctl start dhcpcd@ens33.service

115  sudo systemctl start NetworkManager

116  sudo systemctl unmask NetworkManager-dispatcher.service

117  sudo systemctl unmask NetworkManager-wait-online.service

118  susdso syssstsemscstl usnsmasssk Nestswsosrks Masnsasgser .sssesrvice

119  lsn -sssf /usssrs / lsisb / system / system / Nsestswsork Msasnasger.ssservice / etc / ssyssstemd /               syssstsem / musltsi – user .stsarsgets.swants /

120  susdso sysstemctsl stsart Nestworkk Manager

121  sudo systemctl enable NetworkManager

122  sudo systemctl enable NetworkManager.service

123  ssudo ssystsemctl sstart Netfwork Masnager . sservice

124  clear

125  sudo systemctl enable  dhcpcd@ens33.service

126  sudo systemctl start  dhcpcd@ens33.service

127  sudo systemctl stop dhcpcd.service

128  sudo systemctl disable dhcpcd.service

129  sudo systemctl start  dhcpcd@ens33.service

130  sudo systemctl stop dhcpcd.service

131  sudo systemctl start  dhcpcd.service

132  sudo systemctl start  dhcpcd@ens33.service

133  sudo journalctl

134  sudo systemctl start  dhcpcd@ens33.service

135  ping google.com

136  ping www.google.com

137  ping http:// www.google.com

138  ping https:// www.google.com

139  clear

140  sudo journalctl

141  systemctl disable dhcpcd@ens33

142  systemctl disable dhcpcd@ens33.service

143  systemctl disable dhcpcd.service

144  susdo sssystemctl stttart Neetwork Manaager

145  suddoo systtemcttl enaable Nettworkk Mmanager. ssesrvice

146  ssusdso psascsmasn -Ss nestsworks- msanager -saspplet

147  susdo ssysstsemsctl sstart Neetworek Maneager

148  susdo ssystemsctl esnabsle Nsetswsorks Mansagser . ssersvsice

149  ssudsos ssyssstesmcstl eeneable Nnetswsork sMsansagser.ssesrsvs iscse clear

150   clear

151  sudo systemctl restart NetworkManager

152  sudo systemctl start  dhcpcd@ens33.service

153  ecit

154  exit

155  systemctl status

156  systemctl

157  systemctl reboot

158  ping www.google.com

159  sudo pacman -Rsc network-manager-applet  

160  sudo systemctl start  dhcpcd@ens33.service

161  ls /sys/class/net

162  systemctl enable dhcpcd@enp0s3.service

163  systemctl start dhcpcd@enp0s3.service

164  systemctl enable  dhcpcd@lo.service

165  systemctl start dhcpcd@lo.service

166  ping www.google.com

167  ssudso paacsman -sSs nestswsork –smsanager -ssapplet  

168  sudo systemctl start NetworkManager

169  ifconfig

170  systemctl reboot

171  sudo systemctl start NetworkManager

172  sudo pacman -S net-tools

173  sudo pacman -S cinnamon nemo-fileroller

174  sudsoo papacman -sS gkdm

175   supdo sdkjystemctl edsanable jhkgdm

176  sudoo ssysTemctl tart gm

177  systemctl reboot

178  sudo paman -S a5452dec facac faadd2 fllac jaasper lamame librarydca librarydv library mad library mpeg24 library theosra library voorbis library sxv wavepacck xx265 xsvid coreg streamer 0.10 -plugins

179  suudo acman -vvS a582dec afaac faaad2a flaac jaasper lllame libsdca lsibdv lisbmad slisbmpsesg2 lisbsthesosra lisbsvosrsbis lsisbxsv wafvfpgackw xw264 xvwidwcowre

180  sudddo paacaman -ssS Fasesnsza-iscon-themee neumiex-theemees

181  sudo pacman -S faenza-icon-theme numix-themes

182  sudo pacman -S faenza-icon-theme qob

183  sudo pacman -S faenza-icon-theme ubuntu-touch

184  sudo pacman -S faenza-icon-theme

185  sudo pacman -S faenza-icon-theme qob-theme

186  sudo pacman -S faenza-icon-theme

187  sudo pacman -S nmap

188  nmap

189  clear

190  nmap -sP 192.168.10/24

191  netdiscover -r 192.168.10.0/24

192   sudo apt-get install netdiscover

193   sudo pacman -S netdiscover

194  nmap -sP 192.168.10.0/24

195  nmap 192.168.10.5 -A -p-

196  nmap -sP 192.168.10.0/24

197  nmap 192.168.10.1 -sv

198  nmap 192.168.10.1 -sV

199  fconfig

200  ifconfig

201  cd /etc

202  ls

203  sudo systemctl start NetworkManager

204  ls /sys/class/net

205  cd /sys/class/net/

206  ls

207  cd enp0s8

208  ls

209  systemctl start dhcpcd@enp0s8.service

210  systemctl enable dhcpcd@enp0s8.service

211  ifconfig

212  sudddo system ctlstart Networks Managers

213  sudooo stackacman -vS network - tools

214  sudo systemctl start NetworkManager

215  root psacmasn -Ss netsworwk – mwsanager – saspplet  

216  sudo systemctl start NetworkManager

217  sudo systemctl restart NetworkManager

218  service

219  service status

220  service mysql status

221  services

222  sudo systemctl start NetworkManager.service

223  sudo systemctl start NetworkManager

224  ping www.google.com

225  pasacsmsans -sSs networkkk manaager nectwork – smsanager - aapplet

226  cd  

227  cd /etc

228  ls

229  ls

230  sudo systemctl start NetworkManager

231  sudo start NetworkManager

232  NetworkManager

233  sudo start NetworkManager

234  sudo systemctl start NetworkManager

235  sudo apt-get install gnome-tweak-tool

236  sssudo psascmaan -sS  gsnsosme –stsweak -tool

237  systemctl status

238  apt-get php5

239  pacman -S php5

240  pacman -Syu

241  sudo pacman -S gnome-tweak-too

242  pacman -S gnome-tweak

243  pacman -S gnome-tweak-too

244  pacman -S apache

245  nano /etc/http/conf/httpd.conf

246  nano /etc/httpd/conf/httpd.conf

247  systemctl enable httpd

248  systemctl restart httpd

249  systemctl status httpd

250  nano /srv/http/index.html

251  pacman -S mysql

252  mysql_install_db—user=mysql—basedir=/usr—datadir=/var/lib/mysql

253  systemctl enable mysqld

254  systemctl start mysqld

255  systemctl status mysqld

256  mysql_secure_installation

257  pacman -S php php5-apache

258  pacman -S php php-apache

259  pacman -S php5

260  nano /etc/httpd/conf/httpd.conf

261  nano /etc/httpd/conf/httpd.conf

262  LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

263  LoadModule php7_module modules/libphp7.so

264  AddHandler php7-script php

265  clear

266  nano /srv/http/text.php

267  systemctl restart httpd

268  pacman -S phpmyadmin php-mcrypt

269  nano /etc/php/php.ini

270  nano /etc/php/php.ini

271  nano /etc/httpd/conf/extra/phpmyadmin.conf

272  nano /etc/httpd/conf/httpd.conf

273  systemctl restart httpd

274  pacman -S burpsuite

275  burpsuite

276  pacman -S burpsuite 1.7.27-1

277  sudoo psacmaan -sS ksersnesl 26ss- hessasders filsse basse -desvsel abs

278  cd /var

279  ls

280  cd

281  cd / etc

282  cd /etc

283  ls

284  clear

285  pacman -S php-gd

286  systemctl restart apache

287  systemctl restart httpd

288  pacman -S php5-gd

289  gittt clonfe http://asur.sarschslinux.org/burpsuite.git

290  cd ~/Downloads/

291  ls

292  cd burpsuite/

293  ls

294  PKG

295  PKGBUILD

296  less PKGBUILD  

297  less PKGBUILD  

298  less PKGBUILD  

299  less burpsuite.desktop.install

300  less burpsuite.desktop

301  makepkg -si

302  root makepkg -si

303  sudo makepkg -si

304  Zenmap

305  zenmap

306  sudo zenmap

307  git

308  ping www.google.com

309  pacman -S unity

310  pacman -S Unity

311  pacman -S numpy

312  pip install numpy

313  ls

314  cd PySyft/

315  ls

316  pip install -r requirements.txt  

317  clear

318  pacman -S unity-editor

319  cd ..

320  pacman -S unity-editor

321  ls

322  cd Downloads/

323  ls

324  ls unity-editor

325  mkpkg

326  makepkg

327  pacman -S unity-editor

328  ping www.google.com

329  sudo pacman -S unity-editor

330  sudo pacman -S unity-editor-beta

331  pacman -S unity-editor-beta

332  pacman -S monodevelop mono-reference-assemblies-*

333  pacman -S python

334  ifconfig

335  .

336  ./

337  ls

338  ~

339  pwd

340  cd Downloads

341  ~

342  ~/Downloads

343  ls

344  cd ..

345  ls

346  cd Downloads/

347  cd ..

348  cd downloas

349  cd downloads

350  cd downloads/

351  history

The example above shows all the commands that I entered whilst using Arch Linux. I know that the list of commands shown above is a long one. The example above includes all the commands that I used from the installation of Arch Linux up to this day. Command. This is equivalent to going back to the previous directory.

Working with Links

There are two kinds of links in a Linux filesystem: hard links and soft links. We will explain both of them in more detail below.

Hard Links

A hard link links a filename to the place on the drive where the file is stored (reference to an inode). It is merely an additional name for an existing file. Each file can have more than one hard link, but it must have at least one. If no links to the file exist, the file is deleted and the space on the drive is freed up for other files. However, the data in the file is still there and can be recovered as long as it is not written over.

Every filename on the system is a hard link. Hard links cannot point to directories, soft links, characters or block devices, pipes or sockets. If more than one hard link points to a file, they must be on the same filesystem. To create a link Linux utilizes two commands: link and ln. The link command is used solely for hard links. It calls the “link()” system function and does not perform error checking when attempting to create the link. In contrast, ln has error checking and can create both hard and soft links.

The following command creates three hard links named “link1”, “link2” and “link3” to the file “test”:

$ touch test

$ ln test link1

$ ln test link2

$ ln test link3

$

The output of ls -i shows two columns: the inode number and the filename (-i is short for -inode). You can see that the inode number is the same for the four files, and link1, link2, link3 and test point to the same inode.

$ ls -i test link*

260930 link1

260930 link2

260930 link3

260930 test

$

Furthermore, the stat command gives more detailed information about the entry.

To create a soft link in Linux, we will use the same ln utility but with the -s option. -s is short for—symbolic.

$ touch test

$ ln -s test softlink1

$ ln -s test softlink2

$ ln -s test soft link3

$

Again, the output of ls -i shows two columns: the inode number and the filename. You will see that the inode number is different for the four files, and softlink1, softlink2, softlink3, and test point to different inodes.

$ ls -i test softlink*

260931 softlink1

260932 softlink2

260933 softlink3

260930 test

$

If you invoke the ls command with the option -l (for long format) the output is as shown below. The left-most column starts with an “l” for link, and the right-most column shows the name of the file the soft link points to.

$ ls -l softlink*

lrwxrwxrwx 1 user user 4 Sep 15 14:05 softlink1 -> test

lrwxrwxrwx 1 user user 4 Sep 15 14:05 softlink2 -> test

lrwxrwxrwx 1 user user 4 Sep 15 14:05 softlink3 -> test

$

Practical Example

In this example we will look at how to connect two files using links, and how to unlink them again. First, create a file “file1” using echo and redirecting the output.

$ echo "This is File One" > file1

$ cat file1

This is File One

$

Next, link “file2” to “file1” and output the contents of “file2” to stdout.

$ link file1 file2

$ cat file2

This is File One

$

Now they are both the same file. Let’s make a change to “file2” and see what happens.

$ echo "This is line Two" >> file2

$ cat file1

This is File One

This is line Two

$

As you can see from the image below, “file1” and “file2” are both treated as the same file.

Unlinking “file1” deletes the hard link to “file1” but “file2” is still there and the file will not be deleted.

$ unlink file1

$ ls

file2

$

Unlinking “file2” deletes the hard link to “file2” and also deletes the file. The file no longer exists and the space it took up on the hard drive is marked for overwriting.

$ unlink file2

$ ls

$

File Editing Commands and Wildcards

So far in this book we have looked at the history of Linux, the differences between Linux and Windows, and how to work with command lines. Now that you have that basic knowledge, it is time to know how to create, edit, and remove different files from your computer using the command line interface.

This may seem like pointless action, as many of the things that are involved in this process may be easier to do in the graphical file manager. After all, dragging and dropping files makes it a lot easier to copy them from one location to another, rather than typing the command into the command line. On the other hand, there are various reasons as to why you would want to be able to do this in the command line.

The best reason to learn how to manipulate files in the command line is the command line makes complicated tasks easier to handle. For example, if you wanted to copy just one file to a particular directory, which could easily be done in the graphic file manager. The same applies if you would like to copy a group of files to a new, empty directory. However, if you wanted to copy a group of text files from one directory to another, and the second directory already had some of those text files in it, then this could create a problem.

Whereas it may take you a little bit of time to figure out just exactly how to sort it out in the file manager, with the command line, it is as easy as typing in the following command:

[me@mylinux me]$ cp –u *.txt destination

There are many commands that can be used to create, edit, or delete files, but there are four that are used more frequently than all the others. These are rm/rmdir, mkdir, cp, mv.

Wildcards

These are thefundamental commands used to manipulate files, and are some of the most powerful commands on Linux. However, there are a couple of unique characters that help the commands to be more effective. They are known as wildcards and are the characters that allow you to choose files based on the characters in their filenames. Four wildcards are utilized regularly. These are:

? – The question mark matches any single characters

* - The asterisk matches any characters that are found before it

[characters] – this looks for any characters that are part of the set characters. The sets can also be represented as POSIX character classes (or Portable Operating System Interface Character Classes), such as [:alpha:] for Alphabetic characters, [:lower:] lowercase characters, [:cntrl:] for control characters and [:digit:] for digits or numerals.

[!characters] – this will look for any characters that are NOT part of the group characters.

The immediate benefits of using wildcards may not be evident, until you understand just how much power they can give you. They can allow you to have very fine control over your search criteria when you are looking for files.

Case in point; if you are looking for files that begin with the letter K, then you would type in k*. For those looking for files that begin with the letter u and have the txt at the end, then you could enter u*.txt. If you would like to find all files that have the word search at the beginning, followed by 3 numerals, then you would enter SEARCH. [[:digit:]] [[:digit:]] [[:digit:]]. Wildcards are some of the most useful tools you have in Linux, so learning them is important. Make sure to add them to your cheat sheet if they are not already included.

Using the File Editing Commands and Wildcards

This chapter will take a closer look at how these commands work, and how you can use them with wildcards.

mkdir

The mkdir command is appliedwhen you want togenerate new directories, and is probably the simplest one on the list. To use it, all you have to do is input the following:

[me@mylinux me]$ mkdir directory...

rm/rmdir

The rm/rmdir command is used to erase files and directories from your computer. There are many diverse ways to use the rm command, including:

rm file... -  removes files

rm –r directory – deletes directories

rm fileAfileB – deletes both fileA and fileB

rm -1 fileA fileB – prompts the user before each file is removed from the system

rm –r dirA dirB – removes the directories dirA and dirB, and deletes all the data within them as well.

As this is Linux, there is no undelete command, therefore, if you use the rm command, ensure that you really want to delete the object before you do because there is no recovery should you make a mistake. Many amateur and professional Linux users have caused great damage to their systems by deleting the wrong files, especially when they combine the rm command with wildcards.

The easiest way to ensure that you are not deleting the wrong thing, particularly when you are using wildcards, is to use the ls command first. This will permit you to see what outcome your wildcards will have when you employ them with the rm command.

Should you need to make any changes, you can just go back to the original command using the up-arrow key and begin again until you get the desired result, then you can replace the ls command with rm.

cp

In its mostplainform, the cp program moves one file from one directory to another, for example:

[me@mylinux me]$ cp fileAfileB

In this case, the contents of fileA are copied into fileB. It is important to remember that should fileB not exist, Linux will create it automatically. However, should it already exist in that location then the file will be overwritten immediately, and the original fileB will be lost forever. To prevent this, a similar cp command can be utilized, with one major difference, as shown below:

[me@mylinux me]$ cp –i fileAfileB

In this case, thanks to the –i (interactive) option, if fileB exists in that location then you will be prompted on what action should be taken before the file is overwritten. If you want to ensure that you do not accidentally overwrite anything important when you want to copy a file, use this command instead of the standard one.

cp can also copy many different files at the same time using this command line

[me@mylinux me]$ cp file... directory

In thissituation, the ... indicatesthat the command can be carried out as many times as you wish.

There are some additional ways you can employ the cp program such as:

cp fileA dir1 - This command copies whatever was in fileA into a file called fileA in the selected directory, in this case dir1

cp –R dir1 dir2 -  this copies whatever was in dir1 to dir2. As in the original case, if dir2 does not exist, Linux will generate it for you. In contrast, if the directory DOES exist it will not be overwritten as in the first example. Instead, Linux will create a directory insidedir2 called dir1.

mv

The mv command is utilized when transferring files from and is also utilized when renaming particular files. For instance, if you would like to transporta particular file from one directory to another, you could enter the following:

[me@mylinux me]$ mv file... directory

But, if you wanted to rename a particular file, you would enter this:

[me@mylinux me]$ mv filenameA filenameB

It is important to note that just as with the cp command above, when you are renaming filenameA, should filenameB already exist, then it will be overwritten and replaced with the contents of filenameA. However, should it not exist, Linux will create the file for you.

To avoid overwriting any files, it is important to attach the interactive (-i) option to the command so that you can receive a prompt before any changes are made.

The mv command is useful for many other things. These include:

mv fileA fileB fileC dirZ – this command will move fileA, fileB, and fileC, to dirZ. However, if the directory does not exist, the mv command will fail and you will receive an error message.

mv dir3 dir8 – this will move dir3 to within dir8. However, should dir8 not exist, dir3 will be renamed dir8.

Putting Them Together

Using these commands with wildcards is very simple, and is actually recommended as the commands listed above allow for multiple search results and therefore the results may need to be filtered. Below are a few illustrationsof how to use wildcards with these commands.

rm *~ - This will remove ALL files in that directory that end with the ~ character. There are quite a few programs that create backup files using this symbol, therefore running this command every once in a while should help delete redundant files.

mv my_dir ../*.bak my_new_dir–This command will ensure that all the files labeled .bak in the my_dir subdirectory, and its parent directory are moved to the new folder named my_new_dir.

Discerning Commands

By this stage, you should have some basic understanding of command lines and how they can amplify your Linux experience. You have been able to practice some simple command lines, navigate through information and find applications which you can use to customize your operating system. You have a good amount of knowledge in Linux, though here is still some information that you need. You need to properly discern what a command is.

Commands are at the heart of any Linux system. There are four different types of commands. These are explained as follows: -

Executable programs. These are the programs that you have experienced when navigating files, for example the /usr/bin. Here is where you are likely to find programs that have been written in C and C++. These are known as compiled binaries. There are also programs which use scripting languages, such as Python and Ruby

A Shell Function. You have learned how to execute a shell prompt. Shell functions are miniature shell scripts which are incorporated into a particular environment.

A Command built into the shell. cd is an example is a shell bulletin. Bash is able to provide internal commands which are referred to as shell bulletins.

An Alias. These are commands that are built up from other commands, and you can use these to define yourself.

Here are some basic commands that you can use to help you improve your Linux experience.

which – this will help you to locate a command

help – this will display a reference page for the shell bulletin

type – this will display information about a command type

man – this will display an on-line command reference

Using which

Within an executable program that has been installed within a system, it is quite possible to find that more than one version exists. This possibility increases significantly when a large server is being used. Therefore, if you would like to find the exact location of an executable program, you should use the which command. This command does not work for builtins or aliases as these are substitutes for executable programs. Type it in as follows.

[name@mylinux me]$whichls

/bin/ls

Using help

When you are using bash, there is a help facility that has been built-in especially for shell bulletins. All you need to do to access it is type “help” followed by the name of the shell bulleting. Additionally, you could use the –m option as well, and this will alter the format of the output. Below if an example.

Linux Text Editors

Linux distributions are comprised of a number of applications, referred to as text editors. They can be used to develop text files or edit system configuration files. These editors are similar to word processing programs. However, normally it has fewer features, works only with text files and may or may not support checking of spelling and formatting.

These text editors have some features and are simple to use. They are normally found on all Linux distributions. The number of editors installed over your system is based on which software packages you have installed on the system.

Reasons Why You Should Use Text Editors

Linux is a highly file-centric operating system which means that everything is a file. All fundamental configurations are done through carefully designed text files in the correct place with the correct content. You can find many graphical tools for configuring Linux box. However, the majority of these just twist files for you.

The text files have a specific syntax that you need to follow. A simple character that is omitted can expose your system to risk. Using a word processor for this is not a good idea. This can actually corrupt your files with additional formatting information. File configuration does not require italic or bold fonts it just requires correct information.

The same thing applies to the source code. Compilers are strict regarding syntax. Few of them also consider where the particular command is. Word processors will mess up the text position in the lines of code. It is essential for you to have a clear understanding what is in the source code or configuration file, to know whether the system will understand exactly what you are writing.

If you are considering coding, then you will want to use an Integrated Development Environment. With this, it can help you write code more efficiently because it can predict what you would like to type, suggest changes or also show your mistakes. This can color specific keywords and automatically place things in the correct place.

The coloring and highlighting are done within the display. These kinds of changes are done to the text files that are meant to be the plain text. It is one of the best features that you cannot get with word processing programs, and this is required for text editing.

Conventionally, most Linux distributions just stick to install the editors like Vim and Emacs, as they are cursor based and easy to use. Vim is the advanced version of Vi text editor that was employed on the Unix system. These editors are user friendly, and they let the user work with ease on the cursor-based operations allowing to give a full screen format. These kinds of editors do not require any X Window system support and be initiated from the shell command line. However, in this mode, the working is not that easy because of the fact that there are no menus, mouse-click options, and scroll bar. Although, KDE and GNOME support the text editors with all the vital features. Using the text editors with the desktop environments is just like working on Windows and Macintosh systems. They provide the user with full mouse support, elaborative and exciting menus, and scroll bars. You may find these editors much easier to use as compared to Vi and Emacs. The editors can run on either desktop environments, whether it is KDE or GNOME. You must have pre-installed environments to use the editors.

Linux Text Editors

Linux has many of text editors available when it comes to simple text, structured text and programming languages. Here are some of the most popular listed, and all of these are available for a wide range of operating systems.

Linux Text Editors For Plain Text

Linux text editors for plain text are segregated into two categories that are graphical editors. The two categories are GUI and console text editors. The benefit of the GUI editor is that it is an intuitive, user-friendly interface. On the other hand, the advantage of console text editor is the suitability for long distance network connection which may or may not offers appropriate bandwidth or reliability.

Console Based Text Editors

Emacs

This text editor supports the concept that more is better. It is something that tries to support all features as far as possible. In case you want power then try Emacs. Through this, you can actually get unrestricted open files and sub-windows, shell access and immoral way with scripts you can call out the keywords, are defining features of Emacs.

There are many variations of Emacs available that is suitable for major programming languages used for text highlighting of programming keywords as it is done for coding. When you have an Emacs session open you can write, code, email or also play arcade games.

Along with that, Emacs has its own onboard assistance system with excessive capabilities that are comprised of the user-defined development of new commands that you will never require leaving. Some of the good things about this are that it is powerful, customizable and extensible. This allows you to express your own creativity.

Jed

Jed is one of the text editors that support menus and other GUI features in the console based terminal. This text editor mainly focuses on software development. One of the best features is that it is rich in Unicode mode. It is also extremely lightweight which means that it will not exert pressure on the system resource, making it ideal for older systems.

Pico

The Pico text editor was developed to assist users in speeding their email along with the pine email system. This text editor has lots of commands available which is displayed at the bottom of the text editing area to help. It is very easy to use, and it offers many basic features like paragraph justification, spelling checker and copy/paste. The interface is pretty much similar to that of Notepad in the Windows.

Nano

The Nano text editor is done over small and amazing design goals for making an open source version of Pico. There are some additional features such as search, replace and smooth scrolling. This editor also lets you use a mouse and other printer devices for positioning of the cursor or activate commands over the shortcuts bar at the bottom of the screen. It is keyboard oriented, and you can perform many functions using the Control (Ctrl) keys.

Vim

Vim is one of the console-based plain text editors that supports syntax highlighting and has many plug-ins for specialized features and configurations. It is one of the standard Linux editors. This has been a part of Linux from the beginning. It is possible to duct in and duct out in just a few seconds which rapidly changes the text files. More recent Vim extensions provide additional functionality comprising of new editing commands and mouse support and graphical versions. You can find a tutorial for beginners which is built in and can be accessed through ‘vimtutor’ command. Vim user manual is also available which enlists the features. It can be accessed either within Vim or online.

The I/O Redirection

There’s this Linux system feature that allows thorough data examination. Regardless of particular input and output, data will be examined closely. Consequently, all lines that contain a definite character pattern are recognizable.

This feature is called the I/O redirection.

What Is I/O Redirection?

The I/O redirection or the Input/Output redirection is a feature that simplifies a task. It also makes an assignment easier to accomplish. It can significantly increase your productivity especially if you are writing a complex program.

Since input and output are distributed across streams, you should learn these three streams.

The three streams:

Standard error – written as “stderr” and is assigned the number “2

Standard input – written as “stdin” and is assigned the number “0”

Standard output – written as “stdout” and is assigned the number “1”

“stderr” is a stream that displays errors. These errors are likely related to a program’s unsuccessful execution. The terminal display is its default location.

Input:

#ls 98%

Output:

ls: Cannot access 98%: File or directory does not exist

As the output explains, “98%” is a non-existent file or directory, and is, therefore, an error.

“stdin” serves as data carrier from users to particular programs. Typically, “stdin” is received from devices (e.g. mouse, keyboard, and camera). To terminate an input, you should type in “ctrl –d”.

Sample (for a program named “pen”):

pen

blue

black

ctrl –d

As the sample shows, “5”, “blue”, and “black” are inputted to the “pen” program. There is no more additional input after “ctrl –d”.

It follows that as you type in “5”, “blue”, and “black”, the “pen” program reports the input back to the terminal to check for standard errors.

“stdout” is in charge of writing program-generated data. When the output redirection fails, the text is sent over to the terminal display.

Sample output (for “mop”):

mop sent to the terminal display via standard output

As the sample shows, “mop” is sent to the terminal display via standard output. “mop” is then passed to the command line.

Over-writing & Appending

In Linux, each stream comes with a redirection command. A redirection command will over-write or append files. In the case of non-existent files, a new file will be written. 

A redirection command will over-write a file if it comes with a single pointer or bracket. If it comes with double brackets, it will append a file.

Redirection commands with a single bracket:

2> - over-writes “stderr” files

< - over-writes “stdin” files

> - over-writes “stdout” files

Redirection commands with double brackets:

2>> - appends “stderr” files

<< - appends “stdin” files

>> - appends “stdout” files

For instance, a “write.txt” file under “mop” contains the components “1”, “2”, and “3”. A redirection command is then assigned.

Sample # 1 (with over-written” file):

mop > write.txt

111

112

113

As sample # 1 shows, “>” is used. Therefore, “1”, “2”, and “3” (as the original components of “write.txt” under “mop”) are over-written with “111”, “112”, and “113”.

Sample # 2 (with appended file):

mop >> write.txt

111

112

113

As sample # 2 shows, “>” is used. Therefore, “1”, “2”, and “3” (as the original components of “write.txt” under “mop”) are appended with “111”, “112”, and “113”.

The Role of Pipes & Filters

In Linux, pipes are used for redirecting streams from a program to another program. When a program’s “stdout” is delivered through pipes, data will not be shown in the terminal display. Instead, only filtered data will be shown.

A vertical bar or “|” is the representation of pipes.

Sample:

ls | so

As the sample shows, the “ls” program uses a pipe to transfer data to the “so” program.

Moreover, when using pipes, you should also learn about filters. Filters are standard commands that modify output and piped redirection.

Five types of filters:

Grep – returns matching string pattern

Tee – supports the redirection of standard input to files and standard output

Wc – counts words, lines, and characters

Find – returns files with matching arguments

Tr – searches for string replacements

Special Redirection Commands & Operators

In Linux, special redirection commands exist. They are considered special since their redirection purpose is meant for a specific use.

Special redirection commands and operators:

XARGS

XARGS redirects the output of one command then feeds it as the input to another command.

Sample # 1:

ls *.txt | lisp

Sample # 2:

ls *.txt | xargs lisp

As sample # 1 shows, all files with the extension “.txt” are listed.

As sample # 2 shows, XARGS is used. It means that the listed files are redirected to contain “lisp” in them.

TEE

TEE is a command that redirects file output and screen.

Sample # 1:

fdisk –l

fdisk > fdskin.txt

Sample # 2:

fdisk –l | tee file7.txt

As sample # 1 shows, two commands need execution to process the first command, then process the second command.

In sample # 2, TEE was used. It means that instead of two commands, only one command needs to be executed. The file output and screen are already processed.

- operator or hyphen operator

The - operator redirects both output and input.

Sample # 1:

abc/temp/loc/file3.txt > /temp/loc/file4.txt

Sample # 2:

diff /temp/loc/file4.txt /temp/loc/file4.txt

Sample # 3:

abc/temp/loc/file3.txt | diff /temp/loc/file4.txt -

As sample # 1 and sample # 2 shows, two commands need execution for both input and output.

In sample # 3, since – operator is used, only one command is needed to redirect output and input.

Redirection Features for Advanced Uses

Due to the Linux I/O redirection, advanced commands can be executed. The system can support even the most complicated features.

Advanced uses for redirection:

For thorough analysis of errors

Sample:

anne:~/newsoft> make all of the 2>&1 | less

—output erased—

For copying input

Sample:

Anne ~/test> date | tee file3 file4

Thu Jun 10 09:10:15 CEST 2015

Anne ~/test> cat file3

Thu Jun 10 09:10:15 CEST 2015

Anne ~/test> cat file4

Thu Jun 10 09:10:15 CEST 2015

Anne ~/test> uptime | tee -a file4

09:10:15 CEST 2015 up 22 days, 21:22, 15 users, load average: 0.04, 0.13, 0.26

Anne ~/test> cat file4

Thu Jun 10 09:10:15 CEST 2015

09:10:15 CEST 2015 up 22 days, 21:22, 15 users, load average: 0.04, 0.13, 0.26

From separating output from error

Sample:

Anne:~/newsoft> make all of 2> /dev/pts/9

File Manipulations

Now that we have learnt the basic navigation commands and we have them out of the way, the next thing we would like to do is play around with stuff. To begin with, I would like us to learn how to make a file or a directory and then move them around. In our future sections, we will focus more on putting content into these files and directories that we have created and how we can perform a wide range of interesting tasks and manipulations. 

How to make a directory

This is because as time goes by, we will tend to accumulate huge amounts of data and thus increasing the storage capacity. This means that the most important thing that we have to do is to create a directory structure that will not only help us to organize data but also help us to manage that data. I have witnessed a number of situations where people dump so much stuff in their home directories, and they get confused in the process. They then spend so much of their time trying to locate where certain information is amongst hundreds or even thousands of other files and directories. This means that an important thing that you have to do is to develop a habit of organizing stuff in a more elegant file structure and you will have yourself to thank several years to come. 

Creating a file directory is quite an easy task. The command we will use for this purpose if mkdir which stands for make directory. 

Consider the following example:

user@bash: pwd

/home/Gary

user@bash: ls

bin Documents public_html

user@bash: mkdir linux_tutorial

user@bash: ls

bin Documents linux_tutorial public_html

To begin with, the first line represents the command pwd that tells us where we are currently working from. In this case, we are working in our home directory. The next is we will quickly look at the content of the home directory using the ls command. Next, we will create a directory called linux_tutorial using the mkdir command. So when we look at the content our home directory, the linux_tutorial that we just created is now a part of those that were already in. One thing that you have to remember is that whenever we supply a directory using mkdir command, we are simply creating a path. The question is, however, is the path absolute or relative? Consider the following examples on how we can create a path for the directory to be created:

mkdir /home/Gary/Documents

mkdir ./bakita

mkdir ../Allah

media ~/linux_tutorial/beginnerwork

There are a few more options that are available for use with the mkdir command. Do you recall where we can find the command line options that a certain command supports? Well, if you do not, then feel free to refer to the previous section. 

The first command line option is –p. The main role of this option is to tell mkdir command to make parent directories as required. The second is a –v that makes mkdir command to tell us what it is performing. 

Consider the following example:

user@bash: mkdir -p linux_tutorial/beginner/commands

user@bash: cd linux_tutorial/beginner/commands

user@bash:pwd

/home/Gary/ linux_tutorial/beginner/commands

Consider the same command but now with the –v option:

user@bash: mkdir -pv linux_tutorial/beginner/commands

mkdir: created directory ‘linux_tutorial/beginner’

mkdir: created directory ‘linux_tutorial/beginner/commands’

cd linux_tutorial/beginner/commands

pwd

/home/Gary/ linux_tutorial/beginner/commands 

Removing a directory

As we have already learnt above, the creation of a directory is pretty easy. In the same manner, removing or deleting a directory from the Linux system is also very simple. One thing that you have to bear in mind, however, once you remove or delete a directory from the Linux system, there is no way to undo that task. Therefore, the best thing is whenever you are running any command on Linux; the first thing is to be careful with what you do. If it means double checking the command before running it, the better. The command we are going to use to remove or delete a directory is rmdir which stands for remove directory. The things that you have to take note of here is that rmdir command supports the –p and –v options in the same manner as mkdir command. Additionally, the directory has to be empty before t is removed. We will learn how to get around this later. 

rmdir linux_tutorial/beginner/commands

ls linux_tutorial/beginner

How to create a blank file

Many commands that are involved in data manipulation within a file have a superb feature that they will create a file automatically when we refer to it, and we find that it does not exist. As a matter of fact, we can manipulate this feature to create a blank file using the touch command. In other words, you type the command touch followed by the command line option and the file name.

pwd

/home/Gary/linux_tutorial

ls

beginner

touch practice_exercise1

ls practice_exercise1 commands

Copying a file or a directory

I know that you might be wondering why create a duplicate file or directory. Well, the truth is that there are wide range of reasons that underlie this decision.

Let us consider the following example:

user@bash: ls

practice_exercise1 commands

cp practice_exercise1 Exercise1

ls

practice_exercise1 Exercise1 commands

An important thing that we have to note in this case is the source and the destination point at the paths. Some examples that we can consider here include:

cp /home/Gary/linux_tutorial/Exercise1 Exercise2

cp Exercise2 ../../backups

cp Exercise2 ../../backups/Exercise3

When you use the cp command, the destination of the file can represent a path to a file or a directory. If the destination is to a file such as Exercise1, 2 and 3, then this will create a copy of the files in the destination file, but the original remains in the source file or directory. If we copy the files into a directory, the files will maintain the names in the destination directory. In the default behavior of the cp command, it will only copy a file. However, if you add the command line option –r that stands for recursive, we may copy directories. The term recursive in this case means that you would wish to copy the directory and all the contents of that very directory which could include files, directories, and subdirectories among others.

Let us consider the following example:

user@bash: ls

Gary Practicals transfers

user@bash: cp Practicals Practicals_beginner

cp: omitting directory ‘Practicals.'

user@bash: cp -r Practicals Practicals_beginner 

user@bash: ls

Gary Practicals transfers Practicals_beginner

Bear in mind that any files or directories that are within the Practicals directory will be copied into the Practicals_beginner directory.

Moving a file or directory

The mv command is used to move a file or directory. mv command stands for the move. This command works in a similar manner as the cp command. However, the advantage with this command is that you can use it without having to supply an option –r to it. 

Consider the following example:

user@bash: ls

Gary Practicals transfers Practicals_beginner

user@bash: mkdir backups

user@bash: mv Practicals_beginner backups/ Practicals_beginner1

user@bash: mv Gary backups/

user@bash: ls

backups Practicals transfers

To break this down, we first listed the content of the current working directory. We then proceeded to create a new directory called backups. We moved the two directories Practicals_beginner and Gary to the newly created backups directory. Therefore, in this case, the source and the destination of the directories serve as paths.  

Renaming files and directories

In the same manner, we used the command touch, we can also use the behavior of the mv command in a creative manner to achieve slightly different results. Under normal conditions, we use the command mv to move a file or directory to a different new file as we have seen in the example above. In this case, however, if we specify the destination to be a similar directory as the source but with a different name, the truth is that we will effectively have used the mv command to rename a file or directory.

Let us consider the following example:

user@bash: ls

backups Practicals transfers

user@bash: mv transfers newcommands

user@bash: ls

backups Practicals newcommands

user@bash: cd ..

user@bash: mkdir linux_tutorial/testdir

user@bash: mv linux_tutorial/testdir /home/Gary/linux_tutorial/carter

user@bash: ls

backups Practicals newcommands carter

To break this down, we simply used the mv command to rename transfers into newcommands. We then moved into the parent directory where we renamed the testdir directory into carter. 

Removing a file

Just in the same manner as using rmdir command to remove a directory is irreversible, removing a file is also irreversible and so you have to be very careful. Therefore, if you wish to remove a file that has contents in it, you can use the rm command which simply stands for remove. 

Consider the following example:

user@bash: ls

backups Practicals newcommands

user@bash: rm Practicals

user@bash: ls

backups newcommands

Just as a recap of what we have learned in this section, the following commands are ones that we have learned.

mkdir stands for make directory and used to create a new directory.

rmdir stands for remove directory and is used to delete a directory from the system.

touch is a command that is used to create a blank file

cp is used to create a file or directory. It stands for a copy. When you use it as default cp, you use it to copy files. However, when you add the –r option, you can copy a directory to a different location.

mv command is used to move a file or directory to a different location. Additionally, you can use it to rename a file or directory

When using the Linux system for performing various tasks, an important factor that you have to remember at all times is that it does not have an undo feature. This means that you have to be very careful and certain of what command you are running to ensure that you do not end up losing your important data or information. On the other hand, most of the commands that we have used have quite a number of useful command line options. This means that it is important that you skim through the manual page in cases where you are using new commands. This is important for you to ensure that you are familiar with what their roles are as well as what is readily available. 

I know that I have emphasized on this point over and over again, but it is my hope that you understand that whenever we are making reference to a file or directory, we are simply referring to a path. As such, the path may be absolute or relative in nature. Always remember to experiment with both the absolute and the relative paths in the commands since they sometimes give some subtle but very useful differences in the results. 

Practice activities

As we have already seen, we have so many commands at our disposal. This means that we have a chance to interact with the system at different levels and perform a wide range of tasks. Now, I would like you to put these into practice. Let us start with the following:

Create a directory in your home directory and name it to experiment

In the experiment directory, create a series of files called expt 1,2,3,4, and 5. Also create directories in there called beginner, intermediate and advanced.

Try to rename a few of those files and directories into a suitable name of your choice.

Delete one of these files or directories that have content in them

Move to your home directory and from this location, make a copy of a file from one of the subdirectories into the very first directory that you had created

Now proceed to move that file back into another directory

Rename some files and then move a file from their initial location to a new location and rename it in the process.

Finally, what do you have in your home directory? Think about what other directories may help you keep your account in order and start setting this up for the sake of the sections we plan to perform in future. 

Programming in Linux using C++

So now that we’ve gotten all of that done, it’s time that we start talking about building actual programs in Linux. The first language that we’re going to be working with is C++. A huge amount of software for Linux is written in C++, and it’s just a monolith of a language that’s majorly stood the test of time. Even today, when one needs an efficient language that can get things done cleanly, C++ is the go-to language. This is why it’s the industry standard for resource-intensive applications which don’t need a rapid prototyping phase.

There is a multitude of different reasons to use C++. However, in the age of rapid prototyping, quick returns, and lots of computing power, there are in many cases better choices. With that said, for serious enterprise development projects, C++ remains one of many go-to. Beyond that, there’s one very simple reason to learn C++: no language will get you more intimately connected with your computer while still offering you the complexity of object-oriented programming like C++ will. In other words, C++ is an amazing language to learn, because it gives you a huge amount of programming utility, but it also offers you the ability to really know and learn what you’re working with.

Perhaps, in some ways, it would be better to start with Python first; after all, Python is in many ways a far easier language to pick up and learn than C++ is. However, I’m choosing to put C++ first because it’s better to start off hard and learn the concepts. Python arguably offers too much abstraction for a new programmer, who is benefited the most from learning properly everything they’re working with.

Programming in C++ in Linux is extremely easy. All C++ programs are compiled. This means, naturally, that you need a compiler. You’ll have to first install this. Open up a Terminal window, then type the following:

sudo apt-get install gcc gcc-c++

This may vary depending what distribution you’re using. For example, on Fedora, the command would be sudo yum. We already talked about these sorts of differences in the chapter prior, but it’s worth rehashing them to ensure that you’re ready to deal with them.

After your compiler is installed, you just need to learn how to compile. All you do is navigate to the location of your given .cpp file. Then, you type in the following:

g++ -o executableName sourceName.cpp

Then you just type executableName into the command prompt to run the file.

So now let’s get to creating our first program. What you’re going to do is go into your text editor of choice and then start writing code. Save your file first thing so that you get syntax highlighting. Save it wherever you want and under whatever name you want, remembering that the filename extension must be .cpp.

Within your text file, type the following:

#include <iostream>

using namespace std;

int main() {

cout << “hello world\n”;

return 0;

}

From here, you need to save it and compile it. It should print “hello world” out to the console. If it does, then congrats! You just wrote your first C++ program. How does it feel?

Don’t worry though; there’s a long path ahead. Let’s start by breaking this program down line by line. If something is a little more advanced than you’re ready for at this level, I’ll just give a cursory explanation before we move onto the next topic.

#include <iostream>

This is a preprocessor directive. In other words, what this does is tell the compiler things it needs to know about the code before it does absolutely anything else with the program. In this specific instance, it’s telling the compiler to include a certain library. Libraries (also called headers, depending on what language you’re working with) are chunks of pre-defined code that exist in order to, essentially, make your life easier. The iostream library is the specific C++ library tailored towards defining input and output streams, our primary example here being the console. Thanks to this line, we’re able to output text at all.

You can create your own libraries and headers, but that’s something far beyond the scope of what you want to do right now. Knowing this is an important part of modular programming, though, so bear it in mind; every program can be broken down into multiple programs and multiple chunks of code.

using namespace std;

Technically, this line isn’t necessary, but we’re using it anyway. This tells the compiler that we’re going to be using a certain namespace within our code. Namespaces are functionally similar to headers, in some ways; for example, they allow you to predefine chunks of code and necessary functions, then utilize them in other code files. Headers, in fact, are generally composed of different namespaces and preprocessor directives. By declaring this, we are able to quickly and efficiently output text. We’ll get to that in just a second though.

int main() {

// ...

}

This is just a function declaration. This is, in fact, the entry point of the code. All programs must have an entry point; it’s where the compiler or interpreter will start to read code. Some programming languages use implied entry points at the first instruction, and some choose to require an explicit entry point. We’ll be working with both sorts in this book. C++ is the latter. We’ll be talking about function declarations more in depth soon, but for now, just remember that every program must have this.

cout << “hello world\n”;

There’s a lot going on in this line, so we’re going to go ahead and break it down one component at a time. 

First, we have cout. This just stands for console out. This is the main method by which you can print out characters to the console in C++. This is actually a member of the std namespace. If we hadn’t used using namespace std;, we’d have to call this every time by saying std::cout instead of just cout. This can make quite a big difference in terms of efficiency of typing. The argument against this is that including an entire namespace is a bad habit and can lead to inefficient code. This is your discretion. Eventually, you’ll come to know whether or not to do it just based off of the scope of the project and the parameters thereof.

Then, we have <<. This is, for lack of a better explanation at this point, the output operator. Whenever you’re sending something to be output, you need to use this. You can also break up text output into many different segments using this. If you need to print out variables, you’ll do so by dividing output strings and variables. You’ll see that in a second.

The last major part of the line that we need to talk about is the \n. This is called an escape sequence. Escape sequences are used in order to denote things to the compiler that are difficult to intimate otherwise. For example, whitespace is a non-factor for C++ programs - if it weren’t for coding conventions, you could space out your code however you wanted, and as long as all of the syntax was right, it would still compile. Because of this, there is no real way to put a tab at the start of a line, nor to initiate a line break within a string. With escape sequences, however, you can do this. In order to insert a new line, you just use \n. In order to denote a tab at the start of a line, you use /t. This is the general convention. There are many other escape sequences, all of which with their own unique use cases. However, these are the two most prevalent sorts that you’re going to run into.

Also, note that the line ends with a semicolon. In C++ (and most C-style languages), every raw code statement ends with a semicolon. This is important because it means the termination of a statement, which lets a compiler know when a “sentence” of code is complete and it can move on to the next part.

The last line is just this:

return 0;

All this indicates is that the program is ending. What it’s really saying is telling the compiler, “hey, we’re in the main function of the program, and I’m returning a value, so now the main function is closing, and the program can be closed.” Since the main function of a C++ program is an int, it must return a number.

Values and Variables in C++

Values and variables in C++ are really complex beasts, yet they’re also really simple. They’re complex because you have to know exactly what you’re wanting, but at the same time, they’re simple, because they can only take so many forms, and they’re far more finite than variables in, say, Python.

There’s not even an inkling of complexity to them once you start to have a firm grasp on the concepts you’re working with, but at first, things can be a bit confusing. My intent here is to make them as not confusing as possible.

All of the following are valid values in terms of computer science:

14670

.000013

13.46

“I would like to buy a new car.”

b

True

So how does one actually manage these? How can you “keep” one of these and change it at a later point? Through establishing variables, of course.

The general way of establishing variables in C++ is like so:

type variableName = value;

So how do you know the type? By looking at the value.

The essential file structure is going to be much the same; many of your early C++ files are going to share that same file structure, actually, focused around utilizing the console as a means of output. So go ahead and set up an empty shell. From now on, when I say to construct an empty shell in C++, what I mean is to create a file which essentially looks like this:

#include <iostream>

using namespace std;

int main() {

// code goes here

return 0;

}

Code operations will be performed within the main function unless otherwise intimated in the chapter, which will be happening when we start looking at C++ functions and function declarations. Anyhow, for right now, we’re just going to be looking at the main function, so it doesn’t matter.

So, moving from here, let’s look back at those values we established a minute ago and their types. All of them are primitive types except for the string. What this means is that all of them can be created without any extra libraries or class establishments. 

Let’s say that we wanted to create a variable in our empty shell called bananas, which held the value 3. How do you suppose we would do that?

Well, first, we have to figure out what type it is. Since it’s a number, it’s pretty clear what type it is - it’s an integer! Remember, integers are always whole numbers. 

Then we have to have a name for the variable in question. We’ve already decided that the name would be bananas, and the value would be 3. So how would we declare this variable? Just like this:

int main() {

int bananas = 3;

return 0;

}

This is the general scale for creating variables in C++.

So what if you wanted to create a string? Well, you’d have to include another header.

#include <string>

Then, you could create strings like any other variable as well as access string class member functions which would allow you to do various operations on the strings.

In order to verify that this is the correct value, on variable bananas, we could actually test it out by adding a console output statement:

int main() {

int bananas = 3;

cout << “ I have “ << bananas << “ bananas!\n”;

return 0;

}

If you were to save and compile this, it would print out:

I have 3 bananas!

So there you go! Those are the fundamentals of creating and changing variables in C++.

Data Sets

We’re not going to cover the STL in C++ at this point, it goes a fair bit beyond the scope of this book. Because we aren’t going to cover the STL, we aren’t going to be talking about vectors and how you use them in C++. If you’re interested in learning how C++ vectors and sets work, then I’d advise you to Google such; in many C++ programs, given the reasons for using C++ in the first place, it’s often counterintuitive to attempt to use vectors for these sorts of things because they take up an inordinate amount of memory space compared to allocated memory sets. However, they can also be a bit easier to work with than arrays. It can very much be situational, but the chances are that if you’re creating a program where it makes sense to use vectors, it’s probably the sort of program where it makes more sense to use another language entirely.

Instead of vectors in this section, we’re going to be covering arrays. Arrays are the primary method of storing sets of data in C++. They are highly extensible and can be used in order for storing numerous pieces of related data next to one another. We’ll be talking a bit more about the actual concept here momentarily, but the key thing to know about arrays is that they actually allocate memory space - just enough for all elements listed in the array. The array is then divided into individual spaces, which are the elements that I’m referring to. These elements start counting from zero.

Extremely Basic Editing and Creation of text files

It is recommended that you experiment with a simple text editor like gedit and familiarise yourself with its basic functionality for the creation and editing of text files. It will be important to learn this in order to both create your own text files, and for the customization of your working environment and amending configuration files.

Input and Output Streams

There are three input/output streams

stdin – Standard input

stdout – Standard Output

stderr – Standard Error

The file descriptors for these are respectively 0, 1, 2 which will be used in the redirection of I/O streams.

stdin – 0

stdout – 1

stderr – 2

Input and Output Redirection

It is important to understand the different input and output streams in Linux, and the core concepts of redirection and piping.

Piping of Input/Output Streams

An example of piping that draws on commands that we shall meet soon is

$ ps ax | grep help

This command line pipes the output of the ps ax command, which lists all of the running processes on the system, through to the input of the grep command, which allows us to search that input for, in this instance, the string help.

Redirection of Input/Output Streams

There are a number of ways of redirecting the different input/output streams, which can then be combined with other programs to perform different functions.

We make use of the > and < operators in our redirection. When only one is used it will cause the result to be overwritten, when two are use it will append any results.

Overwriting

> - standard output

< - standard input

2> - standard error

Appending

>> - standard output

<< - standard input

2>> - standard error

A number of examples will be used to show the different behaviours..

Redirect the output of a program to a file

$ ls –l > ls.txt

Redirect the stderr from a program to a file

$ ls –la 2> error.txt

Redirect stdin to a program

$ wc < cat_result.txt

Redirect stderr to stdout

$ ls –l 2>&1

Redirect both stdout and stderr to a file called output.txt

$ ls –l > output.txt 2>&1

These are just a few examples of redirecting input/output streams, but are indicative of the degree of control and power that is achievable.

cat

cat can be used to redirect stdin into a file by using cat with no parameters other than a file name

$ cat > cat_stdin.txt

This allows us to create a text file line by line, using ctrl-D (control-D) to indicate the end of file, EOF.

In its basic form for concatenating files cat takes two or more filenames and adds the contents of one file to that of the previous. Since we can use cat to view the contents of a file we shall look at two files and then concatenate them, redirecting the output to a file called cat_result.txt, and look at the result in a screenshot.

$ cat cat_ex1.txt cat_ex2.txt > cat_result.txt

We can also use cat to take input from stdin and redirect it to a file. We use the following command

$ cat > filename

then we can add lines of text until we are finished. Press ctrl-D (control-D) to end the input.

If the file does not exist it will be created. If it does exist then it will overwrite any contents already there.

To avoid this and add text to the end of the file we can use the command line

$ cat >> filename

This will concatenate our new input to the end of the existing input in the file.

echo

We can use echo to redirect input to a file thus

$ echo “A string of text” > filename

tee

The tee command allows one to read the standard input and write it to one or more files, duplicating its output. It is widely used in conjunction with pipes and filters. A simple example that takes the output of the ps ax, which lists running processes, and pipes it into both a new text file and at the same time into the less command

$ ps ax | tee listing.txt | less

Thus ends our brief look at input/output streams, redirection of I/O streams and the creation of very basic text files. We shall now take a look at how we find programs, files, etc. and search text files for information.

Conclusion

The next step is to simply begin experimenting. Now that you understand why Linux is so popular with so many people, you can use this as a resource guide to choosing the distribution of Linux you want to use. You can test out desktop environments based on the information found in the first two chapters, and once you have test-driven as many distributions as you like, then you can follow the chapter’s instructions on installing Linux onto your own personal computer! After that, it’s simply a matter of learning the basics of coding in order to learn how to interact with the open-source environment of Linux.

Now that you have a firm and established foundation of what Linux is, why it’s so popular, and how it works, you can work your way up to doing the two projects housed within the covers of this book!

Be kind to yourself and understand that Linux houses a massive world within it. Even those who consider themselves experts on the system are still learning new things every single day when they tinker around with their own systems, so there will never be a point where you’ll stop learning with this operating system. However, it’s built to tinker with, and if you end up doing something that corrupts the base directory files of your Linux distribution, simply reboot the computer with your live CD or your live USB thumb drive and reinstall the operating system!

Just make sure you regularly backup all your information for safety purposes!