KEMBAR78
Cloud Computing - Chapter 5 | PDF | Operating System | File System
0% found this document useful (0 votes)
79 views65 pages

Cloud Computing - Chapter 5

Uploaded by

nadah4197
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views65 pages

Cloud Computing - Chapter 5

Uploaded by

nadah4197
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 65

Operating System Basics

Foreword

⚫ The operating system (OS) plays an important role in the interaction


between the user and the computer. But what exactly is an OS? What are
the types of OSs? What are the basic commands of the Linux system? This
course explores these questions, and more, to help you better understand
OSs.

2 Huawei Confidential
Objectives

⚫ Upon completion of this course, you will understand:


 The definition and components of OSs.
 Different types of OSs.
 Basic Linux operations.

3 Huawei Confidential
Contents

1. Operating System Basics


◼ Definition
 Components of an OS
 Different Types of OSs

2. Linux Basics

4 Huawei Confidential
Operating System Definition and Functions
⚫ An operating system (OS) is a computer program (system software) that manages and
controls computer hardware and software resources.

User
Core functions:

Application ⚫ System call interface


software ⚫ Process management
⚫ Memory management
Operating
File system management
system

⚫ Driver management

Hardware

5 Huawei Confidential

• An operating system is a special computer program that controls the computer,


connects the computer and the user, and coordinates and manages hardware
resources, including the CPU, drive, memory, and printer. These resources are
required for running programs.

• Mainstream OSs:

▫ From the perspective of application field, OSs are classified into the
following types:

▪ Desktop OS, server OS, host OS, and embedded OS.

▫ Based on whether an OS is open source, it is classified as:

▪ Open source OS (Linux and Unix) or close source OS (Windows and


Mac OS).
Contents

1. Operating System Basics


 Definition
◼ Components of an OS
 Different Types of OSs

2. Linux Basics

6 Huawei Confidential
Components of an Operating System
⚫ From the perspective of users, an OS consists of a kernel and various applications, that is, the kernel space and
user space.
⚫ The user space is where upper-layer applications run.
⚫ The kernel is essentially a software program used to manage computer hardware resources and provide a system
call interface to run upper-layer application programs.

Applications
and shells
Function
libraries

System Calls

Kernel

7 Huawei Confidential

• System calls: The execution of applications depends on resources provided by the


kernel, including the CPU, storage, and I/O resources. To enable upper-layer
applications to access these resources, the kernel must provide an access
interface, that is, the system call interface.

• Library functions: System calls are encapsulated as library functions to provide


simple service logic interfaces to users. Simple access to system resources can be
completed using system calls. Library functions allow for complex access to
system resources.

• Shell: A shell is a special application program, which is also called the command
line interface. It is a command interpreter in essence. It can execute texts (scripts)
that comply with the shell syntax. Some shell script statements encapsulate
system calls for convenient use.
• The kernel controls hardware resources, manages OS resources, and provides a
system call interface for applications.
▫ Process scheduling and management: The kernel creates and destroys
processes and handles their input and output.
▫ Memory management: The kernel creates a virtual address space for all
processes based on limited available resources.
▫ File system management: Linux is based on the concept of file system to a
large extent. Almost anything in Linux can be seen as a file. The kernel
builds a structured file system on top of unstructured hardware.
▫ Device driver management: Drivers of all peripherals in the system, such as
hard drives, keyboards, and tape drives, are embedded in the kernel.
▫ Network resource management: All routing and address resolution
operations are performed in the kernel.
• Summary: User-mode applications can access kernel-mode resources using the
following:
▫ System calls
▫ Shell scripts
▫ Library functions
Contents

1. Operating System Basics


 Definition
 Components of an OS
◼ Different Types of OSs

2. Linux Basics

9 Huawei Confidential
Common Server OSs
A multi-user and multi-process OS. It supports large-scale file Common Unix OSs:
HP-UX, IBM AIX, Solaris,
UNIX system services and data service applications, provides powerful and A/UX.
functions, and ensures high stability and security.

Linux is a general term for Unix-like OSs. Linux runs with high Common Linux OSs:
GNU/ SUSE Linux, Kylin, Red Flag
Linux security and stability and has a complete permission control Linux, CentOS, RHEL, and
openEuler.
mechanism.

Windows Server is a server OS released by Microsoft. It is mainly Common Windows


Server versions:
Windows used on servers and provides a user-friendly GUI. 2000, 2003, 2008, 2012,
2016, and 2019.

10 Huawei Confidential

• Relationship between Linux and Unix:

▫ Linux is a Unix-like OS with optimized functions and user experience. Linux


mimics Unix in terms of appearance and interaction.

▫ The Linux kernel was initially written by Linus Torvalds for a hobby when
he was studying at the University of Helsinki. Frustrated by MINIX, a Unix-
like OS for educational purposes, he decided to develop his own OS. The
first version was released in September 1991 with only 10,000 lines of code.

▫ Unix systems are usually compatible only with specific hardware. This
means that most Unix systems such as AIX and HP-UX cannot be installed
on x86 servers or PCs. On the contrary, Linux can run on various hardware
platforms.

▫ Unix is commercial software, while Linux is open source and free of charge.

• The GNU Project:

▫ The GNU Project was publicly announced on September 27, 1983 by


Richard Stallman, aiming at building an OS composed wholly of free
software.

▫ GNU is a recursive acronym for "GNU's Not Unix". Linux provides a kernel,
and GNU provides a large amount of free software to enrich the various
applications run on the kernel.
Contents

1. Operating System Basics

2. Linux Basics
◼ Introduction to Linux
 Introduction to openEuler
 Introduction to File Systems on openEuler
 Basic openEuler Operations

11 Huawei Confidential
Features of Linux
⚫ Multi-platform design
 Linux can run on multiple hardware platforms. The Linux kernel is also used in embedded systems
that run on devices such as handheld computers and set-top boxes.
⚫ Multi-user and multitasking
 System resources can be used by different users. Multiple programs can run simultaneously and
independently.
⚫ Free to use
 The source code of Linux is available for free. Users can edit and modify the source code as
required.
⚫ Fully compatible with the POSIX.1 standard
⚫ Inherits the design concept of Unix
 Everything is a file.

12 Huawei Confidential

• The Portable Operating System Interface (POSIX) is a family of standards


specified by IEEE. POSIX defines the application programming interfaces (APIs) of
software runs on Unix. The family of POSIX standards is formally designated as
IEEE 1003 and the ISO/IEC standard number is ISO/IEC 9945. The name of POSIX
consists of the abbreviation of Portable Operating System Interface and an X that
indicates the inheritance of Unix APIs.
• Linux is a popular multitasking and multi-user OS with the following features:
▫ Multitasking: Linux is a multitasking operating system that allows multiple
tasks to run at the same time. DOS is a single-task OS and cannot run
multiple tasks at the same time. When the system executes multiple tasks,
the CPU executes only one task at a time. Linux divides the CPU time into
time slices and allocates them to multiple processes. The CPU runs so
quickly that all programs (processes) seem to be running at the same time
from the user's perspective.
▫ Multi-user: Linux is a multi-user OS that allows multiple users to use it at
the same time. In Linux, each user runs their own or public programs as if
they had a separate machine. DOS is a single-user OS and allows only one
user to use it at a time.
▫ Pipeline: Linux allows the output of a program to be used as the input of
the next program. Multiple programs are chained together as a pipeline. By
combining simple tasks, you can complete complex tasks, improving the
operation convenience. Later versions of DOS learned from Linux and
implemented this mechanism.
▫ Powerful shells: Shells are the command interpreters of Linux. Linux
provides multiple powerful shells, each of which is an interpreted high-level
language. Users can create numerous commands through programming.
Linux File Directory Structure
⚫ Linux OS adopts "Everything is a file" design.
⚫ Linux directories are organized in a tree structure, where / indicates the root directory.
[root@localhost ~]# ls /
bin dev home lib64 media opt root sbin sys usr
Root directory /
boot etc lib lost+found mnt proc run srv tmp var

/bin /dev /lib /media /opt


Directory for all Device file System library Removable media Directory for
user program directory directory device directory storing application
binary files software

/boot /etc /lib64 /mnt


Directory for Configuration 64-bit system Mount
boot loader files file directory library directory
directory

13 Huawei Confidential

• The core philosophy of Linux is "everything is a file", which means that all files,
including directories, character devices, block devices, sockets, printers, processes,
threads, and pipes, can be operated, read, and written by using functions such as
fopen(), fclose(), fwrite(), and fread().
• After logging in to the system, enter the ls / command in the current command
window. The command output similar to the figure is displayed. The directories
are described as follows:
▫ /bin: short for binary. This directory stores the frequently used commands.
▫ /boot: stores some core files used for booting the Linux OS, including some
links and images.
▫ /dev: short for device. This directory stores peripheral device files of Linux.
The method of accessing devices on Linux is the same as that of accessing
files.
▫ /etc: stores all configuration files and subdirectories required for system
management.
▫ /lib: stores basic shared libraries of the system. A library functions similarly
to a dynamic link library (DLL) file on Windows. Almost all applications
need to use these shared libraries.
▫ /mnt: temporary mount point for other file systems. You can mount the CD-
ROM drive to /mnt and then go to this directory to view the contents in the
CD-ROM.
▫ /opt: stores additional software installed on the host. For example, if you
install an Oracle database, you can save the installation package to this
directory. By default, this directory is empty.
Contents

1. Operating System Basics

2. Linux Basics
 Introduction to Linux
◼ Introduction to openEuler
 Introduction to File Systems on openEuler
 Basic openEuler Operations

14 Huawei Confidential
Background of openEuler
⚫ EulerOS is a server OS that runs on the Linux kernel and supports processors of multiple
architectures, such as x86 and ARM. It is ideal for database, big data, cloud computing,
and artificial intelligence (AI) scenarios.
⚫ Over the past decade, EulerOS has interconnected with various Huawei products and
solutions. It is respected for its security, stability, and efficiency.
⚫ Cloud computing, in addition to Kunpeng processors, has sparked the growth of EulerOS
to become the most powerful software infrastructure in the Kunpeng ecosystem.
⚫ To develop the Kunpeng ecosystem and build prosperity of the computing industry in
China and around the world, the open source version of EulerOS was officially released as
openEuler at the end of 2019.

15 Huawei Confidential
Introduction to openEuler
⚫ openEuler is a free open source Linux distribution that supports multiple processor
architectures including x86, ARM, and RISC-V.
⚫ All developers, enterprises, and business organizations can simply use the openEuler
community version, or use it to build, develop, and release their own OS versions.

https://openeuler.org/

https://gitee.com/openeuler/

16 Huawei Confidential
Relationship Between openEuler and Mainstream OSs
Linux
Kernel
Community edition
Fedora • The upstream community
Red Hat Commercial edition Free edition of openEuler, SUSE,
RHEL CentOS Debian, and Red Hat is
the kernel community
www.kernel.org.
Debian Ubuntu • The openEuler
community releases free
long-term support (LTS)
Commercial edition versions, enabling
SLES
SUSE operating system vendors
Free edition
openSUSE (OSVs) such as Kylinsoft,
iSoft, Sinosoft, and
Kylin V10 GreatDB to develop
Community edition
openEuler openEuler Commercial
iSoft V5.1 commercial releases.
releases
EulixOS 1.0
17 Huawei Confidential
Contents

1. Operating System Basics

2. Linux Basics
 Introduction to Linux
 Introduction to openEuler
◼ Introduction to File Systems on openEuler
 Basic openEuler Operations

18 Huawei Confidential
File System Overview
⚫ A file system is a method and a data structure used by an OS to identify files on a storage
device or a partition, that is, a method of organizing files on a storage device.
⚫ In an OS, a software structure that manages and stores file data is referred to as a file
management system, or file system for short.

User-friendly interfaces File system APIs

Disk management software, Software stack for object


similar to middleware control and management File system

Underlying storage
hardware, such as drives and Objects and properties
partitions

19 Huawei Confidential

• Function: The file system organizes and allocates the space on file storage
devices, stores files, and protects and retrieves the stored files. Specifically, it is
responsible for creating files for users, saving, reading, modifying, and dumping
files, controlling access to files, and canceling a file that is no longer in use.
Functions of a file system include: manages and schedules storage space of a file,
and provides the logical structure, physical structure, and storage method of the
file; maps file identifiers to actual addresses, controls and accesses files, shares
file information, provides reliable file confidentiality and protection measures,
and provides file security measures.
File Systems on openEuler
⚫ The openEuler kernel is derived from Linux. The Linux kernel supports more than 10 types of
file systems, such as Btrfs, JFS, ReiserFS, ext, ext2, ext3, ext4, ISO 9660, XFS, Minix, MSDOS,
UMSDOS, VFAT, NTFS, HPFS, SMB, SysV and PROC. The following table describes the
common file systems.
⚫ The default file system on openEuler is ext4.
Common File System Description
Ext File system specially designed for Linux. The latest version is ext4.
A high-performance log file system developed for the IRIX OS by Silicon Graphics
XFS in 1993. Later ported to the Linux kernel, it excels in large-file processing and
provides smooth data transfer.
On Linux, VFAT is the name of the FAT (including FAT16 and FAT32) file systems
VFAT
in DOS and Windows.
The standard file system for optical disc media. Linux supports this file system,
ISO 9600
allowing the system to read CD-ROMs and ISO image files, and burn CD-ROMs.

20 Huawei Confidential
Contents

1. Operating System Basics

2. Linux Basics
 Introduction to Linux
 Introduction to openEuler
 Introduction to File Systems on openEuler
◼ Basic openEuler Operations

21 Huawei Confidential
Contents

Basic openEuler Operations


◼ Basic Knowledge of Linux Commands
 Basic openEuler Commands
 Text Processing on openEuler
 Network Management on openEuler

22 Huawei Confidential
Linux GUI and CLI
⚫ A graphical user interface (GUI) presents all elements as graphical. The mouse is used as the
main input tool, and buttons, menus, and dialog boxes are used for interaction, focusing on
ease of use.
⚫ All elements on a command line interface (CLI) are character-based. The keyboard is used as
the input tool to enter commands, options, and parameters for executing programs,
achieving high efficiency.

23 Huawei Confidential

• Example:

▫ Start the calculator on the Windows GUI. Choose Start > Programs >
Windows Accessories > Calculator. In the calculator, click buttons to enter
an expression. Similarly, a small keyboard is displayed when a certain
program requires you to enter a password, asking you to click the numbers.
This method is very user-friendly, and the calculator looks similar to the
input device used at bank ATMs all around the world. The difference here is
that you click it using a mouse, rather than using your own hands.

▫ In the Linux CLI, enter bc to start the calculator. Enter the calculation 1 + 1
and press Enter. Result 2 is obtained.
Why We Use CLIs
⚫ Higher efficiency
 On Linux, it is faster to perform operations on a keyboard than using the mouse.
 A GUI-based operation cannot be repeated, while a CLI script can be used to complete all required
tasks, for example, deleting outdated log files.

⚫ Lower overheads compared with a GUI


 Running a GUI requires a large amount of system resources. With the CLI, system resources can be
released and allocated to other operations.

⚫ Sometimes, the only choice


 Most servers choose not to install a GUI.
 Tools for maintaining and managing network devices do not provide a GUI.

24 Huawei Confidential
Linux CLI Shortcuts
⚫ Tab completion
 Use the Tab key to complete a command or file name, which is time-saving and accurate.
 When no command is entered, press Tab twice to list all available commands.
 If you have entered a part of the command name or file name, press Tab to complete it
automatically.
⚫ Cursor control
 ↑: Press ↑ several times to display historical commands for quick execution.
 ↓: Press ↓ together with ↑ for choosing a historical command.
 Home: Press Home to move the cursor to the beginning of the line.
 Ctrl+A: Press Ctrl+A to move the cursor to the beginning of the line.
 Ctrl+E: Press Ctrl+E to move the cursor to the end of the line.
 Ctrl+L: Press Ctrl+L to clear the screen.

25 Huawei Confidential
Login to Linux
⚫ You can log in to Linux in either of the following ways:
 Local login

 Remote Login
◼ Using clients such as PuTTY and Xshell to remotely log in to openEuler.

26 Huawei Confidential

• After you log in to the system as the root user, # is displayed in the command
prompt.
Changing the Password
⚫ Passwords are used to ensure the security of system and data.
⚫ To ensure system security, you should:
 Change the password upon the first login.
 Change passwords periodically.
 Set a complex password, for example, a password containing more than eight characters and at
least three types of the following characters: uppercase letters, lowercase letters, digits, and special
characters.
⚫ You can run the passwd command to change the password.
[root@openEuler ~]# passwd # Change the password of the current user.
Changing password for user root.
New password: # Enter the new password.
Retype new password: # Enter the new password again.
passwd: all authentication tokens updated successfully
[root@openEuler ~]# passwd test1 # Change the password of a common user as the root user.
Changing password for user test1.
New password:
BAD PASSWORD: The password is a palindrome
Retype new password:
passwd: all authentication tokens updated successfully.

27 Huawei Confidential

• For security purposes, openEuler does not display the password when you enter it
and does not use any placeholders to indicate the number of characters.
Types of Linux Users
⚫ On Linux, a UID is used to uniquely identify a user.
⚫ Based on different UIDs, there are three types of users in Linux (openEuler is used as an
example):
 Super user
◼ The super user is also called the super administrator. Its UID is 0. The super user has all system permissions.
It is similar to the administrator in Windows.

 System user
◼ System users, also called program users, have UIDs ranging from 1 to 999. A system user is created by a
program and is used to run the program or service.

 Common user
◼ Common users are generally created by the super administrator (the root user) to perform limited
management and maintenance operations on the system. UIDs of common users range from 1000 to 60000.
28 Huawei Confidential
Creating and Deleting a Linux User
⚫ Creating a user (common user by default): useradd username
⚫ Viewing user information: id username
⚫ Switching users: su - username
⚫ Deleting a user: userdel username

[root@openEuler ~]# useradd user01 # Create user user01.


[root@openEuler ~]# id user01 # View information about user01 as the root user.
uid=1001(user01) gid=1001(user01) groups=1001(user01)
[root@openEuler ~]# su - user01 # Switch to the user01 user. The command prompt changes to $.
[user01@openEuler ~]$ id # Use the id command to view information about the current user
by default.
uid=1001(user01) gid=1001(user01) groups=1001(user01)
[user01@openEuler ~]$ exit # Log out of the current user.
logout
[root@openEuler ~]# userdel user01 # Delete user user01.

29 Huawei Confidential
Contents

Basic openEuler Operations


 Basic Knowledge of Linux Commands
◼ Basic openEuler Commands
 Text Processing on openEuler
 Network Management on openEuler

30 Huawei Confidential
Power Supply Commands: shutdown and reboot
⚫ shutdown is used to shut down the computer, which requires root permissions.
 Main options:
◼ -h: powers off the computer after it is shut down.
◼ -r: powers on the computer after it is shut down. (This operation is equivalent to restarting the computer.)
◼ -p: explicitly indicates that the system will be shut down and the main power supply will be cut off.

⚫ reboot is used to restart the computer, which requires system administrator permissions.
 Main options:
◼ -w: writes records to the /var/log/wtmp file. It does not restart the system.
◼ -d: does not write records to the /var/log/wtmp file.
◼ -i: restarts the system with network settings disabled.

31 Huawei Confidential

• The shutdown command can safely shut down the system. It is dangerous to shut
down the Linux system by directly powering off the system.

• Different from Windows, Linux runs many processes in the background.


Therefore, forcible shutdown may cause loss of process data, making the system
unstable and even damaging hardware in some systems.

• If you run the shutdown command to shut down the system, the system notifies
all users who have logged in that the system will be shut down and the login
command will be frozen, prohibiting new user logins.
File Paths
⚫ Absolute path: a path starting from the root directory (/), for example, /root/Desktop.
⚫ Relative path: a path starting from the current path, for example, ./Desktop.
 ./ or . indicates the current path. ../ or .. indicates the upper-level directory of the current path.

⚫ pwd: Viewing the current path


⚫ cd: Switching paths
[root@localhost ~]# pwd # View the current path.
/root
[root@localhost ~]# cd /root/Desktop # Go to the Desktop directory using the absolute path.
[root@localhost Desktop]# cd # Run the cd command without a parameter to go to the home directory
of the current user by default.
[root@localhost ~]#
[root@localhost ~]# cd ./Desktop # Go to the Desktop directory using a relative path.
[root@localhost Desktop]# pwd
/root/Desktop
[root@localhost Desktop]# cd ~ # Switch to the home directory of the user. ~ indicates the home
directory of the current user.
[root@localhost ~]# pwd
/root

32 Huawei Confidential

• The cd command is used to change the current working directory.

• Syntax: cd [directory]

▫ cd /usr: goes to the /usr directory.

▫ cd ..: goes to the upper-level directory. Double dot indicates the upper-level
directory.

▫ cd.: goes to the current directory.

▫ cd: goes to the home directory by default if no parameter is added.

▫ cd -: goes to the previous directory. This command is used to quickly switch


between two directories.

▫ cd ~: goes to the home directory.


Viewing Files
⚫ ls: Viewing the content of a directory
[root@localhost ~]# ls –a # List all files and directories.
ifcfg-lo ifdown-eth ifdown-isdn ifdown-routes
[root@localhost ~]# ls –l # Display detailed information about types, permissions,
owners, and sizes of the files.
total 228
-rw-r----- 1 root root 86 Jun 15 19:03 ifcfg-eth0
-rw-r----- 1 root root 254 Jun 15 19:03 ifcfg-lo

⚫ cat, tail, or head: Viewing the content of a common file


[root@localhost ~]# cat ifcfg-eth0 # View all contents of the file.
DEVICE="eth0"
BOOTPROTO="dhcp"
ONBOOT="yes"
TYPE="Ethernet"
PERSISTENT_DHCLIENT="yes"
[root@localhost ~]# tail -2 ifcfg-eth0 # View the last two lines of the file.
TYPE="Ethernet"
PERSISTENT_DHCLIENT="yes"
[root@localhost ~]# head -2 ifcfg-eth0 # View the first two lines of the file.
DEVICE="eth0"
BOOTPROTO="dhcp"

33 Huawei Confidential

• The ls command is used to view contents of a directory.

▫ -a: lists all files including hidden files.

▫ -l: displays file details in long format.

▫ -R: lists files in the subdirectories recursively.

▫ -t: lists files by modification time.

• The cat command is used to view contents of a small file. This command displays
all lines in a file.

• The tail command is used to view the last 10 lines of a file by default.

▫ -n: followed by a number, for example, 5, indicating that the last five lines
of a file are viewed. You can also enter a number directly without the -n
option.

▫ -f: dynamically displays file changes. This option is commonly used for
viewing log files.

• The head command is used to view the first 10 lines of a file by default.

• The less and more commands are used to view large files page by page. Enter q
to exit. Enter a slash (/) and a keyword to search for the keyword in the file.
Creating Files
⚫ mkdir: Creating directories (folders)
 -p: cascades to create multiple directories recursively.
[root@localhost ~]# mkdir my_dir_01 # Create a my_dir_01 directory.
[root@localhost ~]# ls
anaconda-ks.cfg my_dir_01
[root@localhost ~]# mkdir -p my_dir_02/sub_dir # Create a my_dir_02 directory and its subdirectory sub_dir.

⚫ touch: Creating common files

[root@localhost ~]# touch test01.log test02.log # Create files test01.log and test02.log.
[root@localhost ~]# ls -lt
total 0
-rw-------. 1 root root 0 Jul 29 15:06 test01.log
-rw-------. 1 root root 0 Jul 29 15:06 test02.log

34 Huawei Confidential
Copying Files
⚫ cp: Copying files or directories
 -a: copies the files of a directory while retaining the links and file attributes.
 -r: If the source file is a directory, all subdirectories and files in the directories are copied recursively
and the attributes are retained.
[root@localhost ~]# ls
test01.log test02.log
[root@localhost ~]# cp /etc/passwd passwd.back # Copy the /etc/passwd file to the current directory and rename the
file to passwd.back.
[root@localhost ~]# cp -r /var/log/audit ./ # Copy the audit directory and all files in it to the current directory.
[root@localhost ~]# ls
audit passwd.back test01.log test02.log
[root@localhost ~]# cp -s /etc/passwd passwd_link # Create a symbolic link passwd_link of the passwd file.
[root@localhost ~]# ls
audit passwd.back passwd_link test01.log test02.log
[root@localhost ~]# ls -l
total 8
drwx------. 2 root root 4096 Jul 29 15:24 audit
-rw-------. 1 root root 2546 Jul 29 15:24 passwd.back
lrwxrwxrwx. 1 root root 11 Jul 29 15:25 passwd_link -> /etc/passwd
-rw-------. 1 root root 0 Jan 2 19:20 test01.log
-rw-------. 1 root root 0 Jul 29 19:20 test02.log
[root@localhost ~]#

35 Huawei Confidential

• The cp command is used to copy files and directories. You can copy one or more
files at a time. Exercise caution when running this command because data loss
risks are involved.
• Syntax: cp [OPTION]... SOURCE... DIRECTORY
▫ -a: copies the files of a directory while retaining the links and file attributes.
▫ -p: copies the file content, modification time, and access permissions to the
new file.
▫ -r: if the source file is a directory, all subdirectories and files in the
directories are copied recursively.
▫ -l: creates a hard link of the source file instead of copying it.
▫ -s: creates a soft link of the source file instead of copying it.
• cp f1 f2: copies file f1 and renames it to f2.
• cp f1 d1/: copies f1 to the d1 directory without renaming it.
• cp f1 f2 f3 d1/: copies multiple files to a directory.
• cp -i f1 f2: waits for the user's confirmation before overwriting f2 if f2 already
exists.
• cp -r d1 d2: copies a directory recursively if the -r option is added.
• cp -a f1 f2: if the -a option is added, the attributes of the source file are retained.
This option is used to copy block devices, character devices, and named pipes.
• By default, the cp command does not ask the user before overwriting files.
Therefore, many shells have made cp as an alias for cp -i. The -f option in the cp
command does not indicate forcible overwriting.
Moving and Renaming Files
⚫ mv: Moving or renaming a file
 The mv command is used to move a file or directory. Exercise caution when running this command
because data loss risks are involved.
 If the source file and target file are in the same directory, the mv command is used to rename the
file.

[root@localhost ~]# ls
passwd_link test01.log test02.log
[root@localhost ~]# mv test02.log test03.log #Change the name of the test02.log file to test03.log
[root@localhost ~]# ls
passwd_link test01.log test03.log
[root@localhost ~]# mv test01.log /root/test # Move the test01.log file to the /root/test directory.
[root@localhost ~]# mv –f test01.log test03.log # Forcibly overwrite the test03.log file with the content of
the test01.log file.

36 Huawei Confidential

• The mv command is used to move a file or directory. Exercise caution when


running this command because data loss risks are involved.

• If the source file and target file are in the same directory, the mv command
renames the file.

• Syntax: mv [option] source_file_or_directory target_file_or_directory

▫ -b: backs up a file before overwriting it.

▫ -f: forcibly overwrites the target file without asking the user.

▫ -i: overwrites the target file after obtaining the user's consent.

▫ -u: updates the target file only when the source file is newer than the
target.
Deleting Files
⚫ rm: Deleting files or directories
 The rm command is a high-risk command. No tool can guarantee recovery of files deleted by the
rm command, which does not move a file to a recycle bin like in GUIs. Therefore, you cannot undo
the deletion.
[root@localhost ~]# ls
audit_back passwd.back test01.log test03.log
[root@localhost ~]# rm test01.log # Delete the test01.log file with a prompt
before deletion.
rm: remove regular empty file 'test01.log'? yes
[root@localhost ~]# rm -rf test03.log # Forcibly delete the test03.log file.
[root@localhost ~]# rm -rf audit_back/ # Delete the mail.bak directory, including all
files and subdirectories in it.
[root@localhost ~]# ls
passwd.back
[root@localhost ~]#

37 Huawei Confidential

• Syntax: rm [OPTION] file_or_directory

▫ -f, --force: ignores the files that do not exist and does not display any
message.

▫ -i, --interactive: performs interactive deletion.

▫ -r, -R, --recursive: recursively deletes all directories listed as arguments and
their subdirectories.

▫ -v, --verbose: displays the detailed progress.


Obtaining Help Information About a Command
⚫ help: Obtaining simple help information about a command
 To navigate the massive number of commands on Linux, you can run the help command to obtain
help information.

 Syntax: [command] --help or help [command].


[root@localhost ~]# help pwd
pwd: pwd [-LP]
Print the name of the current working directory.
Options:
-L print the value of $PWD if it names the current working directory
-P print the physical directory, without any symbolic links

By default, `pwd' behaves as if `-L' were specified.

Exit Status:
Returns 0 unless an invalid option is given or the current directory cannot be read.
[root@localhost ~]# systemctl --help
systemctl [OPTIONS...] {COMMAND} ...

Query or send control commands to the systemd manager.

-h --help Show this help


--version Show package version
--system Connect to system manager
-H --host=[USER@]HOST……

38 Huawei Confidential

• The Linux system has so many commands that it is impossible to remember


them all. However, you can run the help command to obtain help information.

• Syntax:

▫ help [option] [command]

• The options are as follows:

▫ -d: displays a brief description of the command topic.

▫ -s: displays a brief description of the command syntax.


Contents

Basic openEuler Operations


 Basic Knowledge of Linux Commands
 Basic openEuler Commands
◼ Text Processing on openEuler
 Network Management on openEuler

39 Huawei Confidential
Linux Text Editor - Vim
⚫ Vim is a customizable text editor derived from Visual Editor (vi) that inherits, improves and
adds many features to vi's original base.
⚫ Common Vim modes:
 Normal mode: used to copy, paste, and delete text, undo previous operations, and navigate the cursor.
 Insert mode: used to edit and modify text.
 Command line mode: used to save, exit, search for, or replace text. Enter a colon (:) to switch to this mode.

Normal mode

Esc Esc

: or / a, i, o, or s

Command Insert mode


line mode

40 Huawei Confidential

• Vim is not installed on openEuler 20.03 LTS by default. You need to manually
install it.
Normal Mode of Vim
⚫ By default, Vim begins to run in normal mode after you open a file with the vim command.
vim [options] [file]... Edit specified files.
vim [options] - Read text from standard input (stdin).
vim [options] -t tag Edit the file where the tag is defined.
vim [options] -q [errorfile] Edit the file where the first error occurs.

⚫ Common options:
 -c: runs a specified command before opening a file.
 -R: opens a file in read-only mode but allows you to forcibly save the file.
 -M: opens a file in read-only mode and does not allow you to forcibly save the file.
 -r: recovers a crashed session.
 +num: starts at line num.

41 Huawei Confidential
Common Operations in Vim Normal Mode
⚫ Cursor control
 Arrow keys or k, j, h, and l keys move the cursor up, down, left, and right, respectively.
 0: moves the cursor to the beginning of the current line.
 g0: moves the cursor to the leftmost character of the current line that is on the screen.
 :n: moves the cursor to line n.
 gg: moves the cursor to the first line of the file.
 G: moves the cursor to the last line of the file.

⚫ Data operations
 yy or Y: copies an entire line of text.
 y[n]w: copies 1 or n words.
 d[n]w: deletes (cuts) 1 or n words.
 [n] dd: deletes (cuts) 1 or n lines.
42 Huawei Confidential
Insert Mode of Vim
⚫ Use the vim filename command to open a file and enter the normal mode by default. Type i,
I, a, A, o, or O to enter the insert mode.
⚫ If the filename file exists, the file is opened and the file content is displayed; otherwise, Vim
displays [New File] at the bottom of the screen and creates the file when saving the file for
the first time.
⚫ Press Esc to exit the insert mode and return to the normal mode.
[root@openEuler ~]# vim test.txt # Enter the normal mode by default.
~
~
"test.txt" [New File]
[root@openEuler ~]# vim test.txt # Press i, I, a, A, o, or O to enter the insert mode.
~
~
-- INSERT --

43 Huawei Confidential
Command Line Mode of Vim
⚫ Search
 :/word or /word: searches for a word string after the cursor. Press n to continue to search forwards or press Shift+n to search
backwards.

⚫ Replace
 :1,5s/word1/word2/g: replaces all occurrences of word1 in lines 1 to 5 with word2. If g is not specified, only the first occurrence
of word1 in each line is replaced.
 %s/word1/word2/gi: replaces all occurrences of word1 with word2. i ignores the case of matches.

⚫ Save and exit


 :w: Save the file and do not exit.
 :wq: Save the file and exit.
 :q: Exit without saving the file.
 :q!: Exit forcibly without saving changes to the file.
 :wq!: Forcibly save the file and exit.

44 Huawei Confidential
Contents

Basic openEuler Operations


 Basic Knowledge of Linux Commands
 Basic openEuler Commands
 Text Processing on openEuler
◼ Network Management on openEuler

45 Huawei Confidential
Important Network Concepts in openEuler
⚫ Host network device: a network adapter on the
host.
⚫ Interface
 Interfaces on devices are created by drivers for the
system access.
⚫ Broadcast address
 An IP address used to send packets to all hosts on the
network segment
⚫ Subnet mask
 A number that distinguishes the network address and
the host address within an IP address
⚫ Route
 Next-hop IP address when IP packets are transmitted
across network segments
⚫ Link: connection between the device and the
network.
46 Huawei Confidential
Commands for Querying IP Addresses
⚫ ip and ifconfig commands are used to view IP addresses of the current host.
⚫ Viewing information about all network adapters on a host.
[root@openEuler ~]# ifconfig –a
[root@openEuler ~]# ip addr show

⚫ Viewing information about a specified interface on a host.

[root@openEuler ~]# ifconfig enp0s3


[root@openEuler ~]# ip addr show enp0s3

47 Huawei Confidential

• Viewing the current IP addresses and subnet masks of all interfaces: ip addr
Configuring Static IP Addresses Using Network Adapter Configuration Files
⚫ Query the path of the network adapter configuration file:
[root@openEuler ~]# ls /etc/sysconfig/network-scripts/ifcfg-*
/etc/sysconfig/network-scripts/ifcfg-enp0s3 /etc/sysconfig/network-scripts/ifcfg-enp0s8
⚫ Parameter description: Parameter Description
TYPE Interface type
BOOTPROTO Boot-time protocol
ONBOOT Whether to activate the device at boot-time
IPADDR IP address
NETMASK Subnet mask
GATEWAY Gateway address
BROADCAST Broadcast address
MAC address. Only one MAC address needs to be set. New MAC addresses
HWADDR/MACADDR
cannot share the same name as another when they are set at the same time.
Whether to specify the DNS server address. If the DHCP protocol is used, the
PEERDNS
default value is yes.
DNS{1, 2} DNS server addresses
USERCTL User permission control
NAME Network connection name
DEVICE Physical interface name

48 Huawei Confidential
Configuring the IP Address - Configuration File Example
⚫ Set the static IP address of the enp0s3 interface to 192.168.56.100/24.

TYPE=Ethernet
BOOTPROTO=static
NAME=enp0s3
DEVICE=enp0s3
ONBOOT=yes
IPADDR=192.168.56.100
NETMASK=255.255.255.0

⚫ Restart the network.


[root@openEuler ~]# nmcli connection reload enp0s3
[root@openEuler ~]# nmcli connection up enp0s3
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/12)

49 Huawei Confidential

• Sometimes, too many configuration items increase the difficulty of network


troubleshooting.
Configuring the Static IP Address Using the nmcli Command
⚫ Check network connections of the current host.
[root@openEuler ~]# nmcli connection show
NAME UUID TYPE DEVICE
enp0s3 3c36b8c2-334b-57c7-91b6-4401f3489c69 ethernet enp0s3
enp0s8 00cb8299-feb9-55b6-a378-3fdc720e0bc6 ethernet enp0s8

⚫ Configure a static IP address.


[root@openEuler ~]# nmcli connection modify enp0s3 ipv4.method manual ipv4.addresses "10.0.2.10/24" ipv4.gateway "10.0.2.2"

⚫ Restart the network.


[root@openEuler network-scripts]# nmcli connection reload enp0s3
[root@openEuler network-scripts]# nmcli connection up enp0s3
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/18)
⚫ View the IP address.
[root@openEuler ~]# ip addr show enp0s3
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:7d:e1:a5 brd ff:ff:ff:ff:ff:ff
inet 10.0.2.10/24 brd 10.0.2.255 scope global noprefixroute enp0s3
valid_lft forever preferred_lft forever

50 Huawei Confidential

• conn: indicates that an operation is to be performed on a connection.

• add: adds (a connection)

• type: type of the connection

• con-name: connection name

• <ifname>: name of the network adapter

• mod: modifies (a connection)


Introduction to Routes
⚫ To facilitate communication between two hosts in different subnets, a mechanism is required
to describe the path for traffic. This mechanism is called routing, which is set using routing
entries.
⚫ A routing entry is a pair of predefined addresses, including the destination and gateway. It
indicates a gateway through which the destination can be reached.
⚫ The routing table is a collection of routing entries.

51 Huawei Confidential

• Detailed description of routes:


https://docs.freebsd.org/en/books/handbook/advanced-networking/#network-
routing
Route Management and Configuration
⚫ In openEuler, the route command is used to view, configure, and manage local routes.
⚫ In addition to the route command, the ip command can also be used to manage system
routes.
⚫ These commands will modify the routing table of the system. When the system is started,
the routing table is loaded to the memory and maintained by the kernel.

52 Huawei Confidential

• The route, ip, and nmcli commands can be used to manage routes. The following
uses the route command as an example.
Viewing the Routing Table Using the route Command
⚫ Run the route command to view the routing table.

[root@openEuler ~]# route -n


Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.110.254 0.0.0.0 UG 100 0 0 enp4s0
192.168.110.0 0.0.0.0 255.255.255.0 U 100 0 0 enp4s0
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0

53 Huawei Confidential

• When the -n option is used to display routes, the values in the Destination
column are IP addresses.

• Eight fields are displayed when you run the route command to view routes. The
possible values of the Flags field include:

▫ U (up) indicates that the route is up.

▫ H (host) indicates that the gateway is a host.

▫ G (gateway) indicates that the gateway is a router.

▫ R (reinstate) indicates that the route is reinstated for dynamic routing.

▫ D (dynamically) indicates that the route is dynamically written.

▫ M (modified) indicates that the route is dynamically modified by the


routing daemon or redirect.

▫ ! indicates that the route is closed.


Adding a Route Using the route Command
⚫ Add a (temporary) route to a network segment or host.

route [-f] [-p] [Command [Destination] [mask Netmask] [Gateway] [metric Metric]] [if Interface]]

⚫ Example:

[root@openEuler ~]# route add -net 192.168.101.0 netmask 255.255.255.0 dev enp4s0
[root@openEuler ~]# route add -host 192.168.100.10 dev enp4s0
[root@openEuler ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default _gateway 0.0.0.0 UG 100 0 0 enp4s0
192.168.100.10 0.0.0.0 255.255.255.255 UH 0 0 0 enp4s0
192.168.101.0 0.0.0.0 255.255.255.0 U 0 0 0 enp4s0
192.168.110.0 0.0.0.0 255.255.255.0 U 100 0 0 enp4s0
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0

54 Huawei Confidential

• You can use the route command to add routes. The added routes are stored in
the memory and become invalid after the system is restarted.

• The route add -net 192.168.101.0 netmask 255.255.255.0 dev enp3s0 command
adds a route to the 192.168.101.0/24 segment through the enp3s0 device.

• The route add -host 192.168.101.100 dev enp3s0 command adds a route to the
192.168.101.100 host through the enp3s0 device.

• The output of the route command shows that routes to hosts have a higher
priority than routes to network segments.
Deleting a Route Using the route Command
⚫ Deleting a route to a network segment or host using the route del command.
⚫ Syntax:
route del [-net|-host] [netmask Nm] [gw Gw] [[dev] If]

⚫ Example:

[root@openEuler ~]# route del -host 192.168.100.10 dev enp4s0


[root@openEuler ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default _gateway 0.0.0.0 UG 100 0 0 enp4s0
192.168.101.0 0.0.0.0 255.255.255.0 U 0 0 0 enp4s0
192.168.110.0 0.0.0.0 255.255.255.0 U 100 0 0 enp4s0
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0

55 Huawei Confidential

• The route del -net 192.168.101.0 netmask 255.255.255.0 dev enp3s0 command
deletes the route to the 192.168.101.0/24 segment. To delete a route to a
network segment, the network segment and subnet mask parameters are
mandatory, while the device parameter is optional.

• The route del -host 192.168.101.100 dev enp3s0 command deletes the route to
the 192.168.101.100 host. The device parameter is optional.

• To delete routes in the route file, use the vi editor to edit the file and restart the
network.
Host Name
⚫ A host name identifies a device in a local area network (LAN).
⚫ The device can be a physical or virtual machine.
⚫ The host name is stored in the /etc/hostname file.

[root@openEuler ~]# cat /etc/hostname


openEuler

56 Huawei Confidential
Setting the Host Name
⚫ Setting a temporary host name: hostname new-name
⚫ Setting a permanent host name: hostnamectl set-hostname new-name
⚫ Setting a host name by modifying the file: write new-name to the /etc/hostname file.

[root@openEuler ~]# hostname


openEuler
[root@openEuler ~]# hostname huawei
[root@openEuler ~]# hostname
huawei
[root@openEuler ~]# hostnamectl set-hostname openEuler01
[root@openEuler ~]# hostname
openEuler01
[root@openEuler ~]# echo "HCIA-openEuler" > /etc/hostname

57 Huawei Confidential

• To make the setting take effect, log in again or run the source .bashrc command.

• Run the hostname command to view the host name of the current system.
Introduction to the hosts File
⚫ Hosts in a LAN can be accessed through IP addresses.
⚫ IP addresses are difficult to remember when a large number of hosts exist in the LAN.
Therefore, we want to access the hosts directly through their host names.
⚫ In this case, the hosts can be located using a table that records the mapping between host
names and IP addresses. This table is the hosts file.
[root@openEuler ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost4.localdomain6

58 Huawei Confidential

• The hosts file is a system file without a file name extension. Its basic function is
to establish a "database" of frequently used domain names and their
corresponding IP addresses.

• When a user enters a website URL in the web browser, the system searches for
the corresponding IP address in the hosts file. Once the IP address is found, the
system opens the corresponding web page.

• If the URL is not found, the system sends the URL to the DNS server for IP
address resolution.

• Run the cat /etc/hosts command to view the hosts file.


Modifying the hosts File
⚫ You can edit the hosts file in the following format:

# Ip domain.com
192.168.10.20 www.example.com

⚫ To delete an entry, add # to comment it out. For example:

#ip domain.com
#192.168.10.20 www.example.com

59 Huawei Confidential
Quiz
1. Which of the following statements is incorrect about file systems?
A. A file system is a method and a data structure used by an OS to identify files on a
storage device or a partition.
B. The software structure that manages and stores file data is referred to as a file
management system.
C. The file system manages and controls computer hardware and software resources.
D. The file system organizes and allocates the space on file storage devices, stores files,
and protects and retrieves the stored files.
2. Linux is a multi-user OS that allows multiple users to log in at the same time and
allows one user to log in multiple times.
A. True
B. False
60 Huawei Confidential

• Answer:

▫ C

▫ A
Summary

⚫ This course discusses the basic components and types of OSs and basic
operations of Linux. Now, we have finished learning the basics about
computing, storage, network, and OS technologies. In cloud computing,
how can we use and manage the resources to provide services for
applications? We will address these issues in the next course about
virtualization technology.

61 Huawei Confidential
Recommendations

⚫ Huawei iLearning
 https://e.huawei.com/en/talent/portal/#/
⚫ Huawei Support Knowledge Base
 https://support.huawei.com/enterprise/en/knowledge?lang=en

62 Huawei Confidential
Acronyms and Abbreviations
CLI: Command Line Interface

GUI: Graphical User Interface

POSIX: Portable Operating System Interface

63 Huawei Confidential
Thank you. 把数字世界带入每个人、每个家庭、
每个组织,构建万物互联的智能世界。
Bring digital to every person, home, and
organization for a fully connected,
intelligent world.

Copyright© 2022 Huawei Technologies Co., Ltd.


All Rights Reserved.

The information in this document may contain predictive


statements including, without limitation, statements regarding
the future financial and operating results, future product
portfolio, new technology, etc. There are a number of factors that
could cause actual results and developments to differ materially
from those expressed or implied in the predictive statements.
Therefore, such information is provided for reference purpose
only and constitutes neither an offer nor an acceptance. Huawei
may change the information at any time without notice.

You might also like