6.1.4 Introduction to Linux and basic commands

Linux Banner En

Linux is an operating system that, like Windows or macOS, runs a computer. However, it has its own characteristics that make it suitable for a variety of tasks, from servers to embedded devices and even desktop PCs. The main difference between Linux and most other operating systems is that it is open source, meaning the source code is available for study and modification.

It is based on UNIX, a family of operating systems that was developed in the 1960s and has had a major influence on the creation of other operating systems. Linux comes in different distributions, such as Ubuntu, Debian, CentOS, Fedora and many others. Each of them is slightly different, but the basic principles remain the same.

Variability of Linux Distributions – Which One to Choose?

One of the key aspects of Linux is the availability of many distributions. Each Linux distribution has its own characteristics and is designed for different purposes, from ease of use to maximum customization and optimization for servers. The choice of distribution depends on the user’s needs and level of knowledge.

Main distributions:

  • Ubuntu and its derivatives (Linux Mint, Zorin OS, etc.) - the most popular and convenient for beginners. They are user-oriented, providing a simple interface and availability of packages through package managers.
  • Debian - more stable and suitable for those who value security and durability, but require more time for configuration.
  • Fedora - a distribution focused on the latest technologies and the developer community. It is more “fresh” than Ubuntu, but may be less stable.
  • Arch Linux - for experienced users. Arch offers full customization, and installation on it is similar to setting up a system from scratch.
  • CentOS/RHEL — are server-oriented and offer high stability, making them ideal for servers and organizations.
  • Kali Linux — a distribution specializing in security and penetration testing.

For beginners, Ubuntu or Mint or Zorin OS (for learning) are recommended first, as they offer the most user-friendly interface and ease of setup.

The choice depends on your experience and what tasks you need to solve. Linux allows users to flexibly configure the system, but for beginners, simplicity and support are important.

Key differences

If you are used to working with Windows, the transition to Linux may seem unusual. Here are some key differences:

  • Command line — unlike Windows, where the interface and all actions are performed mainly through the graphical environment, Linux makes extensive use of the command line. Windows also has a command line (CMD or PowerShell), and Linux distributions often have graphical shell versions, but statistically, it is a much more basic way to interact with the system in Linux.

  • Flexibility and customization - Linux allows you to customize everything from the core of the system to each service. Windows usually limits the user’s ability to customize, providing an interface with predefined parameters.

  • Security - Linux is considered a more secure operating system compared to Windows. This is due to the fact that most users in Linux do not work as superuser (root) and a password is required to perform administrative actions.

  • Updates and installation of programs - Linux often installs programs through package managers such as apt or yum, rather than by downloading and installing files from a website. System updates are also centralized, and this can be a safer and more convenient way to keep the system up to date.

  • File system - unlike Windows, which uses the NTFS system and partitions C:, D:, E…, in Linux everything starts with a single root folder /. All files and directories can be organized in a tree, starting from the root.

In general, Linux family OSes are much more productive in the context of server work. Although Microsoft has its own server OS Windows Server, it is used rather in niche projects with certain dependencies or specific requests.

Advantages and disadvantages of Linux in comparison with Windows in detail

Advantages of Linux:

  • Openness and customization. Linux is open source software, which allows the user to change the source code, customize the system and install only those components that are necessary. Linux distributions provide a choice of settings that can customize the system to any requirements, from lightweight to maximum security.

  • Security. Linux uses a security model with user rights, where the average user does not have access to system files, which increases security. Linux is much less susceptible to virus attacks and has stricter access control mechanisms.

  • Lightweight and efficient. The Linux kernel does not require such resources as Windows and can run on old or weak computers. Due to the lightness of the system, you can set up a working environment that will work faster on the same resources.

  • Stability and performance. Linux is a system that is ideal for servers, as it can run smoothly for months and years.

For working with large amounts of data and multitasking, Linux provides a more stable and predictable environment

Free. Almost all Linux distributions are free, unlike Windows, where you need to buy a license.

Disadvantages of Linux:

Compatibility with programs. Many popular programs, such as Microsoft Office or Adobe Photoshop, are not available on Linux, and you have to look for alternatives (for example, LibreOffice or GIMP). Some professional applications can only run on Windows, and for this you have to use Wine or virtual machines.

  • Driver support. In some cases, hardware drivers may not be as well supported on Linux, especially for newer printers, video cards, and other devices. Although the situation has improved, users sometimes face difficulties when setting up drivers.

  • Gaming. While Linux is increasingly supporting gaming, many popular games and gaming platforms (like Steam) may not work as well as they do on Windows. To play games on Linux, you will need to either use Proton or find alternatives.

Difficulty for newbies. For Windows users, switching to Linux can be challenging, especially when it comes to the command line and manually configuring the system.

Now that we have the basics covered, we can move on to section two, where we will go into more detail on what a Windows user needs to know when switching to Linux.

What should a Windows user know when switching to Linux?

File System and Paths

Linux does not have partitions like Windows (C:, D:, etc.). Instead, the entire file system starts at the root (/). All devices (e.g. hard drives, flash drives) are mounted into this file system and are accessible through directories such as /mnt or /media. If you connect an external drive, it will be accessible through a directory such as /media/drive_name. It is important to understand that the entire file structure is viewed as a single tree, and even devices and partitions are integrated into this tree.

Example: In Windows, an external drive may be accessible as E:, but in Linux it will be accessible as /media/username/ExternalDrive.

User and Permissions

In Linux, every file or directory has an owner, group, and permissions that can be set separately for reading, writing, and executing. This is an important difference from Windows, where security attributes can only be changed through the graphical interface. In Linux, permissions are managed through commands such as chmod, chown, and chgrp.

Also, in Linux, it is common to use the root user to perform administrative tasks. In Windows, you can use the administrator account, but in Linux, it is recommended to run commands as root only when necessary, using the sudo command before the command.

Example: If you want to change system settings, you will need to use sudo to run commands with root privileges, such as sudo apt update to update the system.

Package Managers and Software Installation

In Linux there is no such thing as downloading installation files (for example, .exe in Windows). All programs are installed through package managers, which are a convenient tool for installing, updating and removing programs. This allows you to quickly install applications with minimal effort.

Examples of popular package managers:

  • APT (Advanced Package Tool) for Debian-based distributions (for example, Ubuntu). To install the program, simply run a command like sudo apt install firefox.
  • YUM/DNF for Red Hat-based distributions (for example, Fedora, CentOS). To install the program, use the command sudo dnf install firefox.
  • Pacman for Arch Linux and its derivatives. Install the program using the command sudo pacman -S firefox.

Installing via a package manager ensures that you get the latest stable version of the program and minimizes the risk of downloading malicious files.

System Updates

Updates in Linux are centralized through the package system. This means that you do not need to manually search for updates for each program, as is the case in Windows.

In Linux, updates often include not only updates for applications, but also for the operating system and kernel itself. In Windows, updates are carried out through Windows Update, and although this is also an automatic process, in Linux updates can be controlled using simple commands in the terminal, for example sudo apt update && sudo apt upgrade for updates in Ubuntu.

Using the Command Line

Unlike Windows, where the command line is used less often, in Linux it is the main tool for interacting with the system. Knowing basic Linux commands will greatly simplify the use of the system, because many actions can be performed faster and more efficiently using the terminal than through the graphical interface.

Example: To create a new directory in Windows, simply right-click and select Create Folder. In Linux, you can do this with the command in the terminal:

mkdir myfolder

To navigate through files in Linux, use the cd command, and to view the contents of a directory, use the ls command. In Windows, this is similar to Explorer, but via the command line.

Programs Process

In Windows, many programs start automatically when the system starts and can run in the background without your intervention using the Services system. In Linux, you will often manually start processes, control them using commands such as ps to view running processes and kill to terminate a program. A rough analogue of Services are Services.

Example: To see a list of processes running on your system, use the command:

ps aux

To terminate a process, you need to use the command:

kill [PID]

where [PID] is the process ID.

System Settings

On Linux, most system settings are accessible through text-based configuration files that can be edited using text editors such as nano, vim, or gedit. On Windows, settings are most often changed through a graphical interface or using a registry editor.

Example: To change network settings in Linux, you will need to edit files such as /etc/network/interfaces or use network management commands such as nmcli.

Software Compatibility

While Linux has many programs that replace popular Windows applications, some programs may only work on Windows. There are several solutions for running Windows programs on Linux:

  • Wine — allows you to run Windows programs on Linux.

  • VirtualBox or VMware — allows you to install Windows in a virtual machine inside Linux.

This approach will give you a more complete understanding of the practical aspects of switching from Windows to Linux. If you need to continue, I am ready to add more details!

Basic commands

Enough theory. Let’s go through the practice!

A small disclaimer before familiarizing yourself with the commands

Linux commands are executed through the terminal one way or another. This can be a direct terminal on your local PC, a remote connection to the same terminal via VNC or IP-KVM and so on. But in 90% of cases, this is implemented through a remote connection via the SSH protocol

Commands in Linux usually follow a certain syntax, which consists of several components. To understand how a command works, it is important to understand the role of each element. The average command in Linux looks something like this:

tar -czvf archive.tar.gz folder

Where:

  • tar is the name of the program or utility you want to run. In our example, it is tar – a utility for creating and extracting archives in Linux. In this case, it is used to create an archive from a directory.
  • czvf – after the command, there may be various arguments that specify how the program should work. Arguments usually begin with one or two hyphens and consist of letters (or words). In the example, -czvf is a whole set of arguments, and each of them performs a specific task and can be combined with each other.
  • archive.tar.gz and folder – after the command and its arguments, there are variables that represent data that you want the command to process. In the example, archive.tar.gz is the name of our future archive, and folder is the directory or file that will be archived.

As you can see, we have highlighted the variables separately. We will highlight them in the same way in all further examples.

How ​​to view detailed information about a command directly in the terminal?

The syntax for constructing commands in Linux is surprisingly variable – to describe all the parameters of even basic commands would certainly take a lot of time and text. If you want to get acquainted with all the parameters without searching for the corresponding documentation, you can do this directly in the terminal.

  • man and --help. To learn more about any command in Linux, you can use the man (manual) command. It displays a manual for using the command:

  • Example:

man ls

Will output a detailed manual for the ls command.

  • Alternatively, most commands support a --help flag, which also provides brief information about the command.
ls --help
Output
Usage: ls [OPTION]... [FILE]... List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuvSUX nor --sort is specified. Mandatory arguments to long options are mandatory for short options too. -a, --all do not ignore entries starting with . -A, --almost-all do not list implied . and .. --author with -l, print the author of each file -b, --escape print C-style escapes for nongraphic characters --block-size=SIZE with -l, scale sizes by SIZE when printing them; e.g., '--block-size=M'; see SIZE format below -B, --ignore-backups do not list implied entries ending with ~ -c with -lt: sort by, and show, ctime (time of last modification of file status information); with -l: show ctime and sort by name; otherwise: sort by ctime, newest first ...

There are several key commands used to navigate the file system in Linux. The basic command for moving between directories is cd (change directory).

Usage examples:

  • Go to the user’s home directory:
cd ~
  • Go to the parent directory (one level up):
cd ..
  • Go to a specific directory:
cd /home/user/documents
  • To find out what directory you are in, use the pwd (print working directory) command. This is useful if you are confused about the directory structure:
pwd

Will print the full path to the current directory, such as /home/user.

Managing Files and Directories

Linux provides several commands for working with files and directories. Here are the main ones:

  1. ls - displays the contents of a directory.
  • Simple usage:
ls
  • For a detailed list with permissions, owners and sizes:
ls -l
  • To display hidden files (start with a dot):
ls -a
  • ls is a good example of a command where combining arguments results in a significant improvement in usability. The ls -lha command will not only show all directories and files, but also their permissions and the user who owns them, along with the file weight in a human-readable format:
ls -lha
Output
total 140K drwxr-xr-x 23 root root 4.0K Dec 18 07:01 . drwxr-xr-x 23 root root 4.0K Dec 18 07:01 .. -rw------- 1 root root 13K Dec 6 2018 aquota.group -rw------- 1 root root 13K Dec 6 2018 aquota.user drwxr-xr-x 2 root root 4.0K Oct 16 06:53 bin drwxr-xr-x 3 root root 4.0K Dec 18 07:01 boot drwxr-xr-x 4 root root 4.0K Apr 5 2016 build -r--r--r-- 1 root root 11 Oct 12 2015 .codepage drwxr-xr-x 16 root root 3.8K Dec 13 06:45 dev drwxr-xr-x 147 root root 12K Jan 8 06:26 etc drwxr-xr-x 2 root root 4.0K Jun 17 2017 home lrwxrwxrwx 1 root root 33 Dec 18 07:00 initrd.img -> boot/initrd.img-5.4.0-204-generic lrwxrwxrwx 1 root root 33 Dec 18 07:01 initrd.img.old -> boot/initrd.img-5.4.0-200-generic drwxr-xr-x 22 root root 4.0K May 21 2024 lib drwxr-xr-x 2 root root 4.0K May 30 2024 lib64 drwx------ 2 root root 16K Sep 29 2015 lost+found drwxr-xr-x 3 root root 4.0K Sep 29 2015 media drwxr-xr-x 2 root root 4.0K Dec 12 2018 mnt drwxr-xr-x 3 root root 4.0K Apr 19 2021 opt dr-xr-xr-x 180 root root 0 Dec 2 14:18 proc drwx------ 7 root root 4.0K Jan 10 11:54 root drwxr-xr-x 33 root root 1.1K Jan 10 11:54 run drwxr-xr-x 2 root root 12K Oct 8 06:43 sbin drwxr-xr-x 3 root root 4.0K Oct 6 2015 srv dr-xr-xr-x 13 root root 0 Dec 2 14:18 sys drwxrwxrwt 14 root root 4.0K Jan 10 12:09 tmp drwxr-xr-x 12 root root 4.0K Oct 20 2023 usr drwxr-xr-x 14 root root 4.0K Dec 13 2023 var lrwxrwxrwx 1 root root 30 Dec 18 07:00 vmlinuz -> boot/vmlinuz-5.4.0-204-generic lrwxrwxrwx 1 root root 30 Dec 18 07:01 vmlinuz.old -> boot/vmlinuz-5.4.0-200-generic
  1. cp — copies files and directories.
  • Copying a file:
cp file.txt /home/user/Documents/
  • Copying a directory (with the -r option for recursive copying):
cp -r folder /home/user/Documents/
  1. mv — moves or renames files.
  • Move a file:
mv file.txt /home/user/Documents/
  • Rename a file:
mv oldname.txt newname.txt
  1. rm — deletes files or directories.
  • Delete a file:
rm file.txt
  • Delete a directory and all its files (with the -r option):
rm -r folder

5. touch — creates an empty file or updates the timestamp of an existing file.

  • Create a file:
touch newfile.txt

Managing Permissions

In Linux, an important part of working with files is managing permissions. Use the chmod command to change permissions, and chown to change the owner of files.

1. chmod — changes permissions to files and directories.

  • To give the owner full access (read, write, execute), group and other users — use:
chmod 755 file.txt

Here 7 means read, write and execute (rwx) permissions for the owner, 5 — read and execute (rx) permissions for the group, and 5 — for others.

2. chown — changes the owner and group of the file.

  • To change the owner and group of a file:
chown user:group file.txt

System Monitoring

There are several useful commands to monitor the system and current processes:

Tip: the issue of monitoring the load and processes is already described in more detail in our other article.

1. top — shows current processes, system load and memory.

  • Example:
top
TOP utility
Appearance of the TOP utility

To exit the monitoring mode, press q.

2. ps — displays a list of current processes.

  • To display all processes:
ps aux

3. df — displays information about available and used disk space. More details are described in the following article.

  • For disk information:
df -h
Output
Filesystem Size Used Avail Use% Mounted on udev 956M 0 956M 0% /dev tmpfs 198M 1.5M 196M 1% /run /dev/vda1 60G 12G 48G 19% / tmpfs 986M 0 986M 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 986M 0 986M 0% /sys/fs/cgroup

4. free — shows memory information.

  • For information about RAM and swap memory:
free -h
Output
total used free shared buff/cache available Mem: 1.9Gi 543Mi 222Mi 3.0Mi 1.2Gi 1.2Gi Swap: 0B 0B 0B

Advanced Commands

There are many more advanced commands with endless query options. We can’t cover them all in this introductory article, but the most common ones are worth mentioning:

1. su and sudo are commands for performing actions on behalf of another user, most often the superuser root. These are very important commands, and their use is often required to install packages or perform other actions that require superuser privileges.

  • su (substitute user) allows you to switch to another user, prompting for their password. Example:
su username

To switch to root, simply su and enter the root password.

  • sudo allows you to execute a single command on behalf of another user (root by default), prompting for a password to execute it. Example:
sudo command

2. grep и — search for text in files.

  • Example:
grep "search_term" filename

3. find — search for files in the system. It is described in more detail in the next article.

  • Example:
find /home/user -name "*.txt"

4. tar — archive and unarchive files. It is described in more detail in the next article.

  • Example for creating an archive:
tar -czvf archive.tar.gz folder
  • Example for unzipping:
tar -xzvf archive.tar.gz

5. wget — downloading files by URL.

  • Example:
wget http://example.com/file.zip

6. curl — sending HTTP requests and downloading data.

  • Example for getting the contents of a web page:
curl http://example.com

7. nano — a text editor for the command line.

  • Opening a file:
nano file.txt
NANO Terminal
nano text editor appearance

To save changes: Ctrl + O, to exit: Ctrl + X

8. alias — creating aliases for commands.

  • Example for creating an alias:
alias ll="ls -l"

9. history — viewing the history of entered commands.

  • Example:
history
Output
1 nginx -v 2 mc 3 ls 4 cd / 5 ls -a 6 ls -l 7 ls -a 8 top 9 ls --help 10 ls -lah 11 ls -lha 12 cd / 13 ls -lha 14 df -h 15 ip a 16 sudo systemctl restart mysql 17 history

10. shutdown and reboot — shutdown and reboot of the system.

  • To shutdown:
sudo shutdown now
  • To reboot:
sudo reboot

11. ip — network interface management.

  • Example to display current settings:
ip a
Output
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 52:64:00:ae:72:73 brd ff:ff:ff:ff:ff:ff inet 37.72.135.99/24 brd 37.72.135.255 scope global eth0 valid_lft forever preferred_lft forever inet6 2afc:f11::13:14/112 scope global valid_lft forever preferred_lft forever inet6 fe80::5064:ff:feae:7273/64 scope link valid_lft forever preferred_lft forever

12. mount and umount — mounting and unmounting file systems.

  • Mounting example:
sudo mount /dev/sda1 /mnt
  • Unmounting example:
sudo umount /mnt

Using sudo mount without arguments will print detailed information about the current mount structure:

Output
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime) proc on /proc type proc (rw,nosuid,nodev,noexec,relatime) udev on /dev type devtmpfs (rw,nosuid,noexec,relatime,size=978072k,nr_inodes=244518,mode=755) devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000) tmpfs on /run type tmpfs (rw,nosuid,nodev,noexec,relatime,size=201860k,mode=755) /dev/vda1 on / type ext4 (rw,relatime,quota,usrquota,grpquota,errors=remount-ro) securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime) tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev) tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k) tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755) cgroup2 on /sys/fs/cgroup/unified type cgroup2 (rw,nosuid,nodev,noexec,relatime,nsdelegate) cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,name=systemd) pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime) none on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime,mode=700) cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices) cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb) cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event) cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset) cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio) cgroup on /sys/fs/cgroup/rdma type cgroup (rw,nosuid,nodev,noexec,relatime,rdma) cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer) cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids) cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls,net_prio) cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpu,cpuacct) cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory) systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=29,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=12726) hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M) mqueue on /dev/mqueue type mqueue (rw,nosuid,nodev,noexec,relatime) debugfs on /sys/kernel/debug type debugfs (rw,nosuid,nodev,noexec,relatime) tracefs on /sys/kernel/tracing type tracefs (rw,nosuid,nodev,noexec,relatime) fusectl on /sys/fs/fuse/connections type fusectl (rw,nosuid,nodev,noexec,relatime) configfs on /sys/kernel/config type configfs (rw,nosuid,nodev,noexec,relatime)

13. rsync — file synchronization and backup. More details in our article.

  • Copying example:
rsync -av source/ destination/

14. mc — console file manager with Norton Commander-style interface that simplifies file and directory management.

  • Example:
mc
MC Terminal
MC File Manager Appearance**

Features:

  • Two panels for easy navigation through the file system.
  • Ability to copy, move, delete files, change access rights and edit text files.
  • Support for working with archives, FTP, and SSH.
  • Navigation is carried out with arrow keys and function keys (for example, F5 to copy, F8 to delete).

The terminal is a powerful tool for working with Linux, and the more you use it, the faster you will get the hang of it. In many cases, using commands in the terminal is much faster than through the graphical interface. Don’t be afraid of mistakes, they are easy to fix. The main thing is to start!

In conclusion

Linux is an endless ocean of possibilities, and there is no end to this journey.

Linux offers a high level of control and security, as well as the freedom to customize, making it an ideal choice for developers, system administrators, and enthusiasts. Easy access to powerful command line tools and utilities allows you to work faster and more efficiently.