banner
Barry

Barry

偶尔摆烂,经常偶尔.
twitter
github
tg_channel
medium
email
steam_profiles

A Modern Approach to Linux

Notes based on Frank's Linux course

0.0 Understanding Systems#

  • What is a system?
  • A system is something that allows interaction between humans and machines, enabling actions like clicking with a mouse, typing on a keyboard, watching movies, and installing software. In simple terms, it is what the human-machine interaction relies on, and the system is needed to boot up.

0.1 Understanding the Linux Operating System and the Concept of Open Source: The Many Versions of Linux#

  • Popular computer systems in the world today:
  • Windows - Bill Gates
  • GNU/Linux - Linus Benedict Torvalds - Open Source
  • Unix (the father of Linux) - Thompson and Ritchie - paid usage for government agencies, companies, etc.
  • Linux distributions: Ubuntu, CentOS, Red Hat, Kali, etc.

0.2 Meaning of Open Source#

  • Open, share, and progress together
  • Open source does not necessarily mean free

0.3 Uses of Linux and Various Distributions#

  • Linux is primarily used on servers.
  • Strictly speaking, Linux refers only to the kernel of the operating system, as the operating system includes many user graphical interfaces and other utility tools.
    As long as the GNU General Public License (GPL) is followed, any individual or organization can freely use all underlying source code of Linux, as well as modify and redistribute it.
    Linux derivatives:
  • Debian - Ubuntu, Deepin, Raspberry Pi OS, Knoppix
    Fedora - Red Hat, CentOS, Moblin
    OpenSUSE - GeckoLinux, openSUSE EcoLab Spin

1.1 VMware Virtual Machine#

Ways to install the system:

  • Physical machine
  • Dual system
  • Virtual machine

1.2 VMware 16#

  • Software version; most people pursue the latest version, while enterprises need stability more. We should learn according to enterprise standards; we learn what the enterprise needs.

1.3 Regarding the Update from 15 to 16#

  • VMware 15 does not support Ubuntu 20.04.

    Updating the version will not affect the restoration of the virtual machine.

2.1 Try Ubuntu First#

See: Linux (Ubuntu) Zero-Basis Experience Teaching

PS: Checking the execution content of installed software helps with learning.

2.2 VMware Tools#

  • Configure Ubuntu mirror sources
  • VMware Tools installation
tar zxvf VMwareTools-10.3.22-15902021.tar.gz \
cd vmware-tools-distrib/
ls
sudo ./vmware-install.pl

2.3 Ubuntu 20.04 Settings#

See video link in 2.1.

2.4 Installation Guidance for Other Linux Distributions#

  • Commercial distributions
  • Community distributions

2.5 Download Guidance#

  • Download from the official website.

3.1 What Do We Need to Learn About Linux? - The Four Components of Linux#

Getting started with Linux is not about learning "Linux." First, experience various Linux distributions, comparing their differences and similarities with other systems. What we actually learn about Linux is Shell.

The four parts of the Linux operating system:

  • Linux Kernel
  • GNU ("GNU's Not Unix!") tools
  • GUI Desktop environment
  • Application
  • PS: IT terminology does not follow the usual English phonetics but is professional terminology.

3.2 Is Linux Command Line or Graphical Interface? - What is GUI? What is GNU? What is the difference between GNU/Linux and Linux?#

The Linux kernel is based on:

  • GUI - interface
  • GNU - command, system tools

3.3 Components of the Linux Kernel#

Linux Kernel

    1. Management of hardware devices
    1. Software programs (system), operating software
    1. System memory
    1. File management

3.4 File System#

The file system is the standard for reading and writing.

  • The concept of partitions in Linux: ext, ext2, ext3, ext4
  • Windows disk file management concepts: FAT32, NTFS, exFAT

3.5 GNU Core: coreutils and shell#

The GNU organization created some software that Unix had but the Linux kernel itself did not. Therefore, GNU mimicked Unix and wrote some necessary software for Linux.

GNU Coreutils refers to a set of commands and tools originally on Unix that have been ported to Linux for use, including:

  • Tools for handling files

  • Tools for manipulating text

  • Tools for managing processes

  • GNU Core Shell

  • Software provided for user interaction with the computer.

  • The command-line shell provides a command-line interface (CLI).

  • The graphical shell provides a graphical user interface (GUI).

3.6 Shell: CLI and GUI, Commands and Interfaces#

Shell types: bash, zsh, korn, tcsh, oh-my-zsh.

3.7 GUI Desktop#

Xwindows, KDE, GNOME, Unity.
Conclusion: Experience Introduction.
Focus on Shell.
Draw a mind map summarizing the relationships in the Linux operating system.

4.1 CLI Preparation#

  • CLI-related settings, select Preferences.
  • Theme Variant theme change.
    Open new terminals in method for opening a new terminal; Tab represents creating a new terminal in the same window, Window represents opening a new window for a new terminal.
    New tab position default is the last position.
  • Shortcut settings, Ctrl+Alt+T to open a new terminal.

4.2 CLI Terminal#

yeats@yeats-virtual-machine:~$
  • Username@MachineName: Current directory $ indicates waiting for user input.
  • ~ represents the user's home directory.
  • /home is the root directory for storing all user files.

In Settings, About can view machine name and related information.

4.3 Mastering Linux Command Parameters, Skillfully Using Various Commands - Teach a Man to Fish, Start with ls#

  • The ls command is used to display the target list and is one of the most frequently used commands in Linux.
  • The abbreviation for ls -l is ll, which lists detailed information about visible files in the current directory. The output information includes file name, file type, permissions, number of hard links, owner name, group name, and size (bytes) from left to right.
  • The man command is the help command in Linux, which allows you to view help information for commands, configuration files, and programming in Linux.

Recommended: Linux Command Search

Linux Command Search

4.4 The Linux Root Directory and Its Differences from Windows#

  • Windows uses drive letters and backslashes for file directories.
  • In Linux, everything is a file, and file directories use forward slashes.

4.5 Analysis of the Linux Root Directory, FHS Authoritative Paper, Understanding the Distribution of All Distribution Folders#

  • / Linux root directory
  • /bin Binary directory, GNU tools, commands
  • /cdrom CD-ROM
  • /etc System configuration files
  • /home User home directory
  • /lib Library directory, storing library files
  • /lost+found When the system encounters errors, some lost fragments are placed in this directory.
  • /mnt Mount directory (connecting external devices to the computer)
  • /proc Pseudo file system
  • /run Run directory
  • /snap Package management, software package installation management method
  • /tmp Temporary directory
  • /var Variable directory
  • /boot Boot directory
  • /dev Device directory
  • /media Media directory
  • /opt Optional directory
  • /root Root user's home directory, administrator
  • /sbin System binary directory, commands or tools used by GNU advanced administrators
  • /srv Service directory
  • /usr User binary directory, GNU tools
  • See: FHS File System Hierarchy Standard

FHS File System Hierarchy Standard

4.6 cd Command#

  • cd Enter the user's home directory.
  • cd.. Switch to the previous level.
  • cd – Return to the last working directory.

4.7 Ctrl + C? Not for Copying in Linux#

  • Ctrl+c (kill foreground process) sends a SIGINT signal to all processes in the foreground process group, forcibly terminating the program's execution.
  • Ctrl+l clears the screen.

4.8 Absolute Path#

  • Full path D:\Study\Frank_FuckPPT\Linux

4.9 Relative Path#

  • Non-full path \Frank_FuckPPT\Linux

4.10 Paths in Linux vs. Windows#

  • gedit /Document/doc/1.txt operates on the root directory (absolute path).
  • gedit ~/Document/doc/1.txt operates on the current directory (relative path).
  • gedit ./Document/doc/1.txt operates on the current directory (relative path).
  • gedit Document/doc/1.txt operates on the current directory (relative path).

4.11 How to Practice? Experience Class#

  • Single dot . refers to the current file.
  • Double dots .. refer to the parent directory of the current directory.

4.12 Advanced Usage of ls: Various Matching and Filtering Symbols in Folders#

  • * replaces multiple symbols.
  • ? replaces a single symbol.
  • -a, --all lists all files in the directory, including those starting with ".".
  • -l, --format=long, --format=verbose adds information about file type, permissions, number of hard links, etc., in addition to each file name.
  • -F, --classify, --file-type appends a character to each file name to indicate the file type.

4.13 touch Command#

The touch command has two functions:

  • One is to update the timestamp of an existing file to the current system time (default behavior).
  • The other is to create a new empty file.

4.14 cp Command#

  • The cp command copies the source file or directory to the target file or directory.
  • Source file: Specify the source file list. By default, the cp command cannot copy directories; to copy a directory, the -R option must be used.
  • Target file: Specify the target file. When "source files" are multiple files, the "target file" must be a specified directory.
  • cp What file do you want to copy? Where do you want to copy it to?
  • -i prompts the user before overwriting existing files.
  • -R/r recursively processes all files and subdirectories under the specified directory.

4.15 cp Recursive Practice Skills#

pwd displays the current working directory.

cp -R ./*.java ~/Documents/temp/

4.16 Linux Terminal Cursor Movement Skills#

  • Tab for auto-completion.
  • Ctrl + E to jump to the end of the line.
  • Ctrl + B to move the cursor left.
  • Ctrl + H to delete the character before the cursor (equivalent to backspace).
  • Ctrl + T to move the character before the cursor back.
  • Ctrl + R to search previously used commands.
  • Ctrl + W to delete the word before the cursor.
  • Ctrl + U to delete the content before the cursor.
  • Ctrl + K to delete the content after the cursor.
  • .lnk shortcut

  • Linux link files

    1. Symbolic link (soft link)

    Refers to a shortcut; the original file/folder must exist.

    1. Hard link

    Refers to a copy; the original file/folder must exist.

  • The ln command is used to create links for files, which can be either hard links or symbolic links. The default link type is a hard link. To create a symbolic link, the "-s" option must be used.
  • ln Original file name Link file name
  • ls -l to view.
  • Soft link: has a pointer, is a separate file, different media.
  • Hard link: no pointer, same media.
  • Soft link copies the link file.

4.19 Notes#

  • Symbolic links
  • Soft links

4.20 mv Command#

  • The mv command is used to rename files or directories or to move files from one directory to another.
  • To rename, mv Who to rename What to rename to.

4.21 Moving and Other Operations#

  • To move, mv The file to move to the directory.
  • After entering, cd !$
  • !$ lists and executes the most recent command in your command history.

4.22 rm - The Best Annual Deletion Command#

  • sudo rm -rf /* This command is extremely dangerous.
  • The rm command can delete one or more files or directories in a directory and can also delete a directory along with all its files and subdirectories. For link files, it only deletes the entire link file while keeping the original file unchanged.
  • rm -i prompts for confirmation.
  • rm -i -rf no prompt.
  • Note: Linux does not have a recycle bin.

4.23 Creating and Deleting Directories#

  • mkdir is used to create directories.
  • rmdir is used to delete empty directories.

4.24 File Types#

  • file is used to detect the type of a given file.
  • Windows text is txt.
  • Linux text is text.

4.25 cat, more, less#

  • cat concatenates multiple files and prints to standard output, suitable for short texts.
  • -n, --number numbers all lines starting from 1.
  • more displays file content one screen at a time.
  • b for the previous page, space for the next page, q to exit.
  • less allows for scrolling through file content both up and down.
  • The less command allows users to browse files forward or backward, while the more command can only browse forward.
  • When displaying a file with the less command, use the PageUp key to scroll up and the PageDown key to scroll down. To exit the less program, press the Q key.
  • To search within the file, type /.

4.26 tail and head Commands#

  • tail displays the last few lines of a specified file on the screen.

    tail -n 2 demo.c
    
  • head displays the beginning part of a file.

    head -n 2 demo.c
    

5.1 Task Manager#

  • Processes, performance, users, services.
  • Services: monitor user behavior and serve users.

5.2 ps and top Commands#

  • top allows real-time dynamic viewing of the overall operation of the system and is a practical tool that integrates various information to monitor system performance and operation information.
  • ps (process status) is one of the most complex commands in Linux and is the most basic yet powerful command for viewing processes. This command can determine which processes are running and their status, whether processes have ended, whether there are zombie processes, which processes are consuming excessive resources, etc. In short, most information can be obtained by executing this command.
  • ps axo pid,comm,pcpu # View the PID, name, and CPU usage of processes.
  • ps -aux | grep named # View detailed information about the named process.

5.3 kill Command#

Use ps -aux | grep named # View detailed information about the named process.
kill pid to kill the process.

5.4 Meaning of Mounting#

See: The Role of Linux Mounting (https://blog.csdn.net/qq_35583154/article/details/86569903)

Insert a new hard drive, partitioned as sdb1, but it does not yet belong to /. Mount the new hard drive partition sdb1 to the working directory /Share/. After that, accessing the /Share/ folder is equivalent to accessing the sdb1 partition of this hard drive. Any operation on /Share/ is equivalent to operating on the files in sdb1.

5.5 mount#

  • mount is used to mount files outside the Linux system.
  • /mnt is the automatic mount point.
  • sudo fdisk -l to view hard disk and partition information.
  • sudo mount /dev/sdc1 /mnt
  • sudo umount /mnt
  • Automatically mounted directories cannot be unmounted.

5.5 Significance of Mounting - Trying to Use a USB Drive? Auto-Play Malicious Scripts?#

  • Enterprises do not automatically mount to prevent malicious autoplay scripts.

5.6 Connecting and Mounting Android Devices#

  • Android connection protocol (SMB) mount path /run/user/1000/gvfs.

5.7 df and du#

  • df is used to display the available disk space on disk partitions. The default display unit is KB. This command can be used to obtain information about how much space has been occupied on the hard disk and how much space is left.
  • -h or --human-readable: displays information in a more readable format.
  • du is also used to check space usage, but unlike the df command, the Linux du command checks the disk space usage of files and directories, which differs from the df command.

5.8 sort Command#

  • sort sorts all lines in a text file.
  • By default, it sorts based on the first character of each line and displays it without changing the original file.
  • -n, --numeric-sort sorts based on numbers.
  • -M, --month-sort sorts in the order of non-months, January, December.
  • -r, --reverse reverses the order of the results.

5.9 Basic Understanding of grep, Searching Files#

  • grep (global search regular expression (RE) and print out the line) is a powerful text search tool that can search text using regular expressions and print matching lines.

  • grep 543 ~/Templates/1.txt

5.10 Packing, Compressing, Archiving, and Unpacking - What Are Their Differences?#

  • tar for packing and compressing.
  • tar -cvf 1.tar 1.txt packs without compressing.
  • tar -zcvf 1.tar.gz 1.txt packs and compresses with gzip.
  • tar -zxvf /opt/soft/test/1.tar.gz unpacks the tar package.

6.1 Concept of Parent and Child Shells#

  • bash
  • ps -f
  • ps --forest

6.2 What is the Role of Semicolons in Commands?#

  • Commands separated by semicolons (;) are executed sequentially.
  • Create a child shell to execute.

6.3 sleep and jobs#

  • sleep delays the current action for a period of time; it can be followed by s for seconds, m for minutes, h for hours, d for days.

    If it hangs in the background and needs to be terminated, use the kill command.

  • jobs displays the status of jobs; -l additionally lists the PID in job information.

6.4 Background#

  • Execute in the background tar -zxvf ……; &

6.5 coproc Coroutine#

  • Linux coroutine handles commands. Coroutines can do two things simultaneously. A child shell is generated in the background, and commands are executed in the child shell.
  • coproc sleep 10
  • coproc frank_av{ sleep 10; sleep 300;}
  • Must end with a semicolon, spaces within braces.

6.6 External Commands and Built-in Commands#

  • Commands executed by the shell can be divided into built-in commands and external commands. The former is built into the shell.
  • The latter is an independent file (which can be a binary file or a script). Built-in commands are executed by the current shell itself, such as echo, cd, etc.
  • When executing external commands, the shell process forks a child process, the parent process then suspends, and the child process execs to load the external file. The parent process continues execution after the child process returns.

6.7 alias#

  • alias defines or displays aliases.
  • type shows the type of a specified command.
  • alias li='ls -li'
  • However, closing the current shell will make it unusable.

7.1 What Are Environment Variables? Understand What Environment Variables Are!!!#

  • Environment variables generally refer to parameters used in the operating system to specify the operating environment, such as the location of temporary folders and system folders.
  • Writing environment variables for folders means they can be accessed from anywhere, effectively telling the system where this directory is.

7.2 Global Environment Variables and Local Environment Variables#

  • Windows: system variables and user variables.
  • Linux: global environment variables and local environment variables.
  • Global environment variables printenv.
  • printenv USER.
  • echo $USER.
  • cd $HOME.

7.3 Definition of User and Local Variables#

  • Local variables can only be executed in the current shell and become unusable after exiting the child shell.
  • Note: Do not use uppercase for defining local variables.
  • Global variables use uppercase and underscore naming conventions.

7.4 Defining Global Variables#

  • export sets the export attribute for shell variables or functions.
  • Can be executed in child shells but will still be invalid after closing.

7.5 Default Environment Variables#

  • set.

7.6 Why Use Environment Variables?#

  • Needed for configuring the development environment.
  • Temporary environment variables.
  • PATH=$PATH:/home/yeats/Templates/.

7.7 Permanent Configuration of Environment Variables?#

  • Startup files: environment variables that are executed by default when the computer starts.

  • bash shell.

  • 1 login shell.

  • 2 non-login shell opens.

  • 3 runs scripts in non-interactive shells.

  • cat /etc/profile.

  • ~/.bashrc.

  • ~/.bash_profile.

  • ~/.profile.

  • ~/.bash_login.

  • cat bashrc.

  • Add global environment variables (need to learn vim).

8.1 Introduction to PMS Systems and Software Installation#

  • PMS Package Management System.
  • Solves tool dependency issues.
  • apt install.
  • apt-get install.
  • apt-cache.
  • aptitude (deprecated).

8.2 Install, Update, Uninstall#

  • apt -h.
  • Update sudo apt update.
  • Upgrade sudo apt upgrade.
  • Uninstall sudo apt remove oneko.

8.3 Other Distribution Versions?#

8.4 Case Study of Installing Third-Party Software: Guidance on Open Source Software from GitHub#

9.1 Meaning and Role of User Permissions#

  • Users and permissions.
  • It is not safe to give everyone all permissions.
  • Avoid being hacked.
  • User ID UID.
  • System users have UID < 500.
  • cat /etc/passwd.
  • sudo cat /etc/shadow.

9.2 Creating, Deleting, and Changing Users#

  • Create sudo useradd user1.
  • Delete sudo userdel user1.
  • Change password sudo passwd user1.
  • chage modifies the validity period of accounts and passwords.

9.3 group#

  • Linux groups.

    Purpose: Sharing resource permissions.

  • tail /etc/group.

  • Ubuntu does not allow all users to be included in one group; instead, each user has a separate group.

  • sudo groupadd groupfrank.

  • sudo groupdel groupfrank.

9.4 File and Folder Permissions#

rwx Permissions for the file owner (Owner).
r-x Permissions for the user group (Group).
r-x Permissions for other users (Other Users).

See: Linux chmod command (Linux chmod command | Runoob.com).

9.5 chmod Command#

  • The usermod command is used to modify basic information about users.
  • The usermod command does not allow you to change the name of an online user account.
  • When the usermod command is used to change the user ID, it must be confirmed that the user is not executing any programs on the computer.

Attached: vi/vim Keyboard Diagram#

vi/vim Keyboard Diagram

10.1 Brief Introduction to Editors: Vim, the God of Editors; Emacs, the God of Editors#

  • emacs - the God of editors.
  • vim - the God of editors.
  • Vim is a text editor developed from vi. It has rich features for code completion, compilation, and error navigation, widely used among programmers. It is favored alongside Emacs as the preferred editor for Unix-like system users.
  • The vi editor is commonly referred to as vi, which is short for visual editor. It can perform numerous text operations such as output, deletion, searching, replacing, and block operations, and users can customize it according to their needs, which is not available in other editing programs.
  • Vim is an enhanced version of vi, making it easier to use. Almost all commands from vi can be used in vim.

10.2 Simple Usage of vim#

  • Install vim.
  • sudo apt install vim.

vim Working Modes, Generally Considered Two Modes Abroad#

  • Normal mode (command operation mode): operate on files.
  • Insert mode: edit.
  • From edit mode to normal mode: ESC.

Generally Considered Three Modes in China#

  • General command mode: referred to as general mode, is the first working mode entered. You can directly enter general command mode by typing vi + filename. In this mode, you can view, copy, delete, and replace text content. You cannot input relevant text content.
  • Edit mode: In general mode, input i or o or a to enter edit mode. In this mode, you can input text content. When inputting i, the working interface appears as shown, and only in this state can you input file content. After finishing input, you can press the ESC key to exit edit mode and return to general mode.
  • Command line mode: In general mode, input : or / or ? to enter command line mode. In this mode, you can input relevant commands. When inputting , this command indicates saving and exiting. Pressing the Enter key automatically saves the file and exits the vi editor, or press ESC to return to general mode.

The Relationship Between the Three Working Modes is Shown in the Diagram#

Relationship Between the Three Working Modes of VIM

Exiting the vim Editor Generally Divided into Three Situations#

  • :q means exit without saving.
  • :wq save and exit.
  • :q! force exit without saving the file.

10.3 Moving the Cursor#

  • Up: k
  • Down: j
  • Left: h
  • Right: l
  • Next line: b
  • Previous line: w
  • Find the previous character: N
  • Find the next character: n

10.4 Paging#

  • Page up (BACKWARD): ctrl+B
  • Page down (FORWARD): ctrl+F
  • Scroll up: ctrl+E
  • Scroll down: ctrl+Y
  • Move to the last line: G or shift+g
  • Move to the first line: gg

10.5 Different Ways to Edit Text and Jump Word Operations#

  • i insert before the cursor position.
  • a insert after the cursor position.
  • o directly enter the next line.
  • x delete the character at the cursor.
  • dd delete the entire line.
  • u undo.
  • dw remove from the current cursor position to the end of the word.
  • b jump to the first letter of the word.
  • e jump to the end of the word.
  • w jump to the word, first jumping to the first letter of the word, then jumping to the end of the word.
  • shift+w; shift+b big jump.

10.6 Jumping to the Beginning and End of Lines#

  • shift+6 or 0 jump to the beginning of the line.
  • shift+4 jump to the end of the line.

10.7 Jumping Between Functions and Paragraphs with Braces#

  • {} jump between braces.

10.8 vim Copy, Cut, and Paste#

  • p paste.
  • yw copy a word.
  • y$ copy from the current position to the end of the line.

10.9 Visual Mode#

  • v select text.
  • V select lines.
  • v G select all.
  • ctrl+v matrix selection.
  • o switch between the beginning and end of the text.
  • vaw quickly select a word.
  • vab include parentheses.
  • vaB include braces.
  • va< include angle brackets.

10.10 Other Skills in Visual Mode#

  • v shift+< indent left.
  • v shift+> indent right.
  • shift+~ or shift+u shift+U change case.

10.11 Search and Replace#

  • Search /.
  • Press n to find the next.
  • :s /const/let/g replace const with let in one line.
  • :%s /const/let/g replace all const with let.
  • set number temporarily display line numbers.
  • :9,15s /const/let/g replace const with let from lines 9 to 15.
  • :%s /const/let/gc replace with prompts.

10.12 Basic Configuration of vim#

  • touch .vimrc.
  • vim .vimrc.

Write the following code into .vimrc:

set syntax=on
set tabstop=4
set softtabstop=4
set number
set enc=utf-8
set showmatch
  • source .vimrc.
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.