I studied the basic Linux Basics course in the lab building, where I made a learning summary.
Introduction to the first section of Linux systems
This section focuses on what Linux is, what it's like, how it's going, what's important, what's the difference between Linux and Windows, and how to learn Linux.
1. What is Linux
Linux is an operating system, just like Windows (xp,7,8) and Mac OS. Linux is mainly the system call and the two layers of the kernel. Intuitively, the operating system also contains applications that run on it, such as text editors, browsers, e-mails, and so on.
The difference between 2.linux and Windows
- Linux free or charge a little fee;
- Linux is mostly open source free software;
- Linux is more secure than Windows, and does not need to install anti-virus software;
- Linux with graphical interface and full command-line operation
- Linux customization is strong;
3. How to learn Linux
Section II Introduction to Linux Systems
This section mainly introduces the Linux desktop environment, Linux terminal. Through the practice of the use of Common shell commands, shortcut keys, wildcard characters, using small tricks and other operations.
1.linux Desktop Environment
- Compared to the current Windows system, Unix/linux itself is not a graphical interface, we usually see on the unix/linux distribution of the graphical interface is actually just run on the Linux system on the software.
- Lab building currently uses the XFCE desktop environment, which means that you can choose to install different desktop environments on Linux, or even customize your own desktop.
2.linux Terminal
- Usually when we use Linux, we do not deal directly with the system, but through a called
Shell
intermediate program. A shell is a software (command parser) that "provides the user with an interface", similar to a DOS command line and later Cmd.exe.
- The common shells that are popular in Unix/linux are bash, zsh, Ksh, CSH, and more.
3. Command-Line Operations
The most important thing in Linux is the command, which consists of 2 processes, inputs and outputs.
Double-click the icon on the desktop to Xfce终端
open the terminal, the system will automatically run the shell program, and then you can enter a command for the system to execute.
shortcut Keys |
function |
tab |
Command completion |
CTRL + C |
Terminates the current program but does not exit the terminal |
Ctrl+d |
Keyboard input end or exit terminal |
Ctrl+s |
Pause the current program, pause and press any key to resume running |
CTRL + Z |
Run the current program in the background and restore to the foreground as command FG |
CTRL + A |
Move the cursor to the input outfit, which is equivalent to the home key |
Ctrl+e |
Moves the cursor to the end of the input line, equivalent to the END key |
Ctrl+k |
Remove from cursor position to end of line |
Alt+backspace |
Delete a word forward |
Shift+pgup |
Scroll the terminal display up |
Shift+pgdn |
Display the terminal scroll down key |
↑ |
Restore the commands you have entered before |
- Common wildcard characters
character |
meaning |
* |
Match 0 or more characters |
? |
Match any one character |
[List] |
Match any single character in the list |
[!list] |
Matches a character other than any single character in the list |
[C1-C2] |
Match any single word in c1-c2 such as: [0-9] [A-z] |
{String1,string2,...} |
Match string1 or string2 (or more) one string |
{C1.. C2} |
Match all characters in c1-c2 such as {1..10} |
- Create & Find File operations
$ touch adsfasd.txt wergjlkas.txt
$ ls *.txt
- Create multiple files at once
$ touch love_{1..10}_linux.txt
4.banner Command Practice
Banner can output graphic characters.
Use the following command to install the first:
$ sudo apt-get update$ sudo apt-get install sysvbanner
- And then:
$ banner shiyanlou
Practice Toilet/figlet Command:
sudo apt-get install toilet/figlet
Section III User and file Rights management
This section learns about creating, deleting users, user groups, and file permission settings in Linux.
1. User Management
Common who commands
Create user
To create a user requires root privileges, this command will be used for sudo. However, the use of this command has two large premises, one is that you want to know the current login user's password, and the second is the current user must be in the sudo user group. Shiyanlou users also belong to the sudo user group.
$ sudo adduser gege $ su -l gege
In Linux each user has a attribution (user group), user groups simply understand is a set of users, they share some resources and permissions, and have private resources.
2.linux file Permissions
- The LS command lists and displays the files in the current directory and views the file permissions:
gege
User Login, new macbook
file, enter to $ ll macbook
view file owner permissions. ctrl+d
Exit login, change back to Shiyanlou user identity, change file owner to shiyanlou
.
$ su -l gege $ touch macbook $ ll macbook ctrl+d $ cd /home/gege $ ls macbook $ sudo chown shiyanlou macbook $ ll macbook
Method 1:2 binary digit representation
Method Two: Add and subtract assignment operation
Input$ chmod go-rw macbook
g
, o
There are also u
separate representations group
, others
and user
, and respectively, to +
-
increase and remove the corresponding permissions.
3. Job
Add a user loutest
, use sudo
Create file /opt/forloutest
, set to user loutest
can read and write.
$ sudo touch /opt/forloutest $ ll /opt/forloutest $ sudo chmod 600 /opt/forloutest $ ll /opt/forloutest
Section Fourth Linux directory structure and file basic operation
This section studies the structure of the file organization directory of Linux, relative and absolute paths, moving, copying, renaming, and editing files.
1.linux directory Structure
Linux constructs the entire system in the form of a tree-shaped directory structure.
$ tree /
The absolute path, in short, is the /
full path from the root directory to the end of the directory you want to go to, in the form of a directory that represents the directory in the directory /usr/local/bin
under the root directory usr
local
bin
.
Relative path, that is, relative to your current directory path, relative path is the current directory .
as the starting point, with the directory you want to end.
Several statements:
Basic operations for 2.linux files
- New file:
$ touch test
Create a blank file named Test. If you do not have permissions in other directories, you need to cd ~
switch back to the user's /home/shiyanlou
directory first.
- New directory:
$ mkdir gege
create an empty directory named Gege; $ mkdir -p father/son/grandson
Create a multilevel directory.
- Copy file:
$ cp test father/son/grandson
Copy the file test to the Father/son/grandson directory.
- Copy directory:
$ cp -r father gege
Copy the father to the directory Gege.
- To delete a file:
$ rm test
- To delete a directory:
$ rm -R gege
To move a file:
$ mkdir Documents 新建一个目录Documents $ mv file1 Documents 将文件file1移动到目录中
- Rename file:
$ mv 旧的文件名 新的文件名
;
Batch Rename
- To view files:
Use cat
, tac
and nl
commands to view files. The first two commands are used to print the file contents to the standard output (terminal), which is cat
a positive sequence display, in tac
reverse order.
To view the passwd files that were copied from the/etc directory before: $ cat passwd
. You can add -n
parameters to display line numbers $ cat -n passwd
.
View file type: $ file /bin/ls
.
3. JobCreate a homework
directory, build the 1.txt~10.txt
file name, and delete it 1.txt~5.txt
.
Section fifth environment variables and file lookup
This section learns about the role and usage of environment variables and several ways to search for files.
1. Environment variables
(1) Use declare
the command to create a variable named variable a
: $ declare a
.
(2) Use the =
number assignment operator to tmp
assign a variable to shiyanlou
: $ tmp=shiyanlou
.
(3) Read the value of the variable, using echo
commands and $
symbols (the $ symbol is used to denote a value that refers to a variable: $ echo $tmp
.
- Environment variables
- The search path and order of the command
To view the contents of the PATH environment variable:
Create one of the simplest executable Shell scripts and a "Hello World" program created using the C language:
- Variable modification
- Variable deletion
$ unset temp
2. File Search
Search-related commands are commonly used, whereis
which
, find
and locate
.
whereis
Only binary (-B), man Help file (-m), and source code file (-s) can be searched. You can use the command if you want to get a more comprehensive search result locate
.
which
itself is a shell built-in command, we usually use which to determine whether a specified software is installed.
find
Should be the strongest of these commands.
3. Digital Rain
4. Job
5. Challenge One
Sixth section file packaging and decompression
Learned the use of the common compression/decompression tools on Linux- Zip,rar,tar
.
1.zip/tar common commands
Package: Zip something.zip Something (directory please add-r parameter)
Unpack: unzip something. Zip
Specify path:-d parameter
Package: TAR-ZCVF Something.tar something
Unpacking: TAR-ZXVF Somet Hing.tar
Specifies the path:-C parameter
2. Job
Create a file named Test, respectively, with Zip and tar are packaged into a compressed package and then extracted to the/home/shiyanlou directory.
section seventh file system operations and Disk Management 1. View disk and directory capacity
DF: Use the DF command to view the capacity of the disk; Du: Use the du command to view the capacity of the directory; Du-h: In k,m,g, increase the letter The readability of the information. Du-h-D 0 ~: View information for Level 1 directories only. Du-a: The same--all displays the size of all files in the directory. Du-s: Only the totals are displayed with--summarize, and only the last plus total value is listed.
2. Simple Disk Management
- Create a virtual image file with the DD command
Create an empty file with a capacity of 256M from the/dev/zero device:
pre>
$ dd if=/dev/zero of=virtual.img bs=1m count=256 $ du-h virtual.img
- format disk with mkfs command
Use the following command to format our virtual disk image as a ext4 file system.
$ sudo mkfs.ext4 virtual.img
3. Job
- find the top 10 files in the current directory
Section eighth Help commands under Linux
This section learns the differences between built-in and external commands, and the use of related help commands.
1. Differences in built-in/external commands
The result is that the built-in command (built-in commands are in the builtins. def in Bash Source)
xxx is a shell builtin
The result of this is an external command (external command in/usr/bin or/usr/sbin, etc.)
xxx is /usr/sbin/xxx
Gets the result of alias, which indicates the name set by the command alias
xxx is an alias for xx --xxx
2. Help commands
The Help command (built in zsh without the help command, enters bash and has the command built into bash), such as 内建命令
:
help exit help cd
such as 外建命令
ls:
ls --help
Man command
man ls
Info command (with bash)
info ls
Section nineth Linux Task Plan Crontab1.crontab
The crontab is used to set instructions that are executed periodically, and through the crontab command, we can execute a specified system instruction or shell script at a fixed interval. The units of the time interval can be any combination of minutes, hours, days, months, and weeks.
In this lab environment, crontab needs to be started manually, and Ubuntu will default on its own locally without having to start manually:
- Start Rsyslog so that we can find out whether our task was actually executed by using the information in the log:
sudo service rsyslog start
- Start crontab:
sudo cron -f &
- To add a task:
crontab -e
The task is that every minute we create a blank file in the/home/shiyanlou directory with the name of the current month day and seconds.
*/1 * * * * touch /home/shiyanlou/$(date +\%Y\%m\%d\%H\%M\%S)
2. Challenge II
Xiaoming is a server administrator who needs to back up the forum data every day (here we replace with the log), back up the day's logs and delete the previous logs. And the file name after the backup is the format of the year-month-day. Alternatives.log is below/var/log/.
Goal
为shiyanlou用户添加计划任务 每天凌晨3点的时候定时备份alternatives.log到/home/shiyanlou/tmp/目录 命名格式为年-月-日。
Steps
$ sudo cron -f & $ crontab -e 1-3 []: 1 按下a开始编辑,在文件最后一行输入: 0 3 * * * cp /var/log/alternatives.log /home/shiyanlou/tmp/$(date + \%Y\%m\%d) Ctrl+C,退出编辑模式; 输入":wq",退出。
Section Tenth command execution sequence control and piping
This section learns about sequential execution, selection execution, piping, cut commands, grep commands, WC commands, sort commands, and more.
1. Command execution Sequence control
- Sequential execution
Simple order (execution can be used; to complete)
Selective execution commands (which)
First install Cowsay, statement:
sudo apt-get update sudo apt-get install cowsay
Input$ which cowsay>/dev/null && cowsay -f head-in ohch~
2. Piping
Pipelines are also classified as anonymous and named pipes. When we use some filter programs, we often use anonymous pipes, which are represented in the command line |分隔符
.
To see what files and directories are in the/etc directory, use the LS command: $ ls -al /etc
. There is too much content, the screen cannot be fully displayed, this time you can use the pipeline:$ ls -al /etc | less
Cut command--print a field for each line
Print the/etc/passwd file with: The 1th field and the 6th field of the delimiter represent the user name and their home directory, respectively:
$ cut /etc/passwd -d ‘:‘ -f 1,6
Print the first n characters of each line in a/etc/passwd file:
前五个(包含第五个):cut /etc/passwd -c -5 前五个之后的(包含第五个):$ cut /etc/passwd -c 5- 第五个:$ cut /etc/passwd -c 5
- grep command to find matching strings in text or stdin
Search all text files in the/home/shiyanlou directory that contain "Shiyanlou" and display the line numbers in the current text:$ grep -rnI "shiyanlou" ~
Here if the Chinese and English switch is not aware of the results will appear in the search for problems, Comparison:
- WC command, simple and compact counting tool
The WC command is used to count and output the number of rows, words, and bytes in a file, such as the statistics of the output/etc/passwd file:$ wc /etc/passwd
Output only the number of rows, words, bytes, characters, and bytes of the longest line in the input text, respectively:
行数: $ wc -l /etc/passwd 单词数: $ wc -w /etc/passwd 字节数: $ wc -c /etc/passwd 字符数: $ wc -m /etc/passwd 最长行字节数: $ wc -L /etc/passwd
Combined with pipeline statistics/etc all directories below:$ ls -dl /etc/*/ | wc -l
3. Practical work
Install Aview and ImageMagick, and then display the picture with the Asciiview command. The statements are as follows:
sudo apt-get update sudo apt-get aview sudo apt-get imagemagick asciiview Linux.png
11th Simple Text Processing
This section learns the command Tr,col,join,paste
in conjunction with pipeline operations.
1. Four commands
-
TR command use: tr [OPTION]...SET1 [Set2]
, the TR command can be used to delete some text in the message or to convert it.
-D Delete and set1 matching characters, note that not all-word matching is not matched by character order-S to remove Set1 specified consecutive and repeated characters in the input text
-
Col command usage: col [option] , the col command can change the tab to the equivalent number of space keys, or reverse the operation.
-X Converts the tab to a space-H to tab (default option)
-
Join command: join [option]. . File1 file2
, merging the rows of two files that contain the same content.
-t Specifies the delimiter, the default is space-I ignores case differences-1 indicates which field the first file is to compare with, and the default comparison of the first fields-2 indicates the second file to use for comparison, the default comparison of the first field
br>
-
Paste command usage: paste [option] file ...
, which is simply merging multiple files together, tab-separated, without comparing the data.
-D specifies a merged delimiter, by default Tab-s not merged into one row, one line per file
2. Practice work
Section 12th Data Flow redirection
This section learns how to use redirection, file descriptors (0,1,2).
Redirect: > or >> operations are used more than once in the previous course, and know that they are directing standard output to a file or append to a file, respectively. This is redirection, redirecting data that was originally output to standard output to a file, because standard output (/dev/stdout) itself is also a file, and we have no problem with directing the output of the command to another file.
- File descriptor
Practice work
Challenge Three
In Linux, the processing and analysis of text is extremely important. There is a file called Data1,:http://labfile.oss.aliyuncs.com/courses/1/data1.
There is a record of some of the commands, and now you need to find out the first 3 commands from the inside and save them in/home/shiyanlou/result.
目标 处理文本data 将结果写入result 结果包含次数和命令,如“100 ls” 提示 cut截取(-c 8- 明白含义吗) uniq -dc去重 sort 的参数选择-k1 -n -r 答案类似于 cat data|....|....|.... > /home/shiyanlou/result
Note Put the data1 file in the Home/shiyanlou directory, the statement is:
Experimental results:
Section 13th Regular Expression basics
Learn the sed ,grep ,awk
usage, notation, 正则表达式
and syntax of BASIC commands.
1. Regular expressions
- Grammar
Priority level
2.grep Pattern Matching command
- Common parameters
Operation
Location-Find the line in the/etc/group file that begins with "Shiyanlou":
$ grep ‘shiyanlou‘ /etc/group $ grep ‘^shiyanlou‘ /etc/group
Number
#将匹配以‘z‘开头以‘o‘结尾的所有字符串 $ echo ‘zero\nzo\nzoo‘ | grep ‘z.*o‘ # 将匹配以‘z‘开头以‘o‘结尾,中间包含一个任意字符的字符串 $ echo ‘zero\nzo\nzoo‘ | grep ‘z.o‘ # 将匹配以‘z‘开头,以任意多个‘o‘结尾的字符串 $ echo ‘zero\nzo\nzoo‘ | grep ‘zo*‘
Choose
# grep默认是区分大小写的,这里将匹配所有的小写字母 $ echo ‘1234\nabcd‘ | grep ‘[a-z]‘ # 将匹配所有的数字 $ echo ‘1234\nabcd‘ | grep ‘[0-9]‘ # 将匹配所有的数字 $ echo ‘1234\nabcd‘ | grep ‘[[:digit:]]‘ # 将匹配所有的小写字母 $ echo ‘1234\nabcd‘ | grep ‘[[:lower:]]‘ # 将匹配所有的大写字母 $ echo ‘1234\nabcd‘ | grep ‘[[:upper:]]‘ # 将匹配所有的字母和数字,包括0-9,a-z,A-Z $ echo ‘1234\nabcd‘ | grep ‘[[:alnum:]]‘ # 将匹配所有的字母 $ echo ‘1234\nabcd‘ | grep ‘[[:alpha:]]‘
- Exclude characters
Extending regular Expressions
3.sed Stream Editor
Command basic format: sed [参数]... [执行命令] [输入文件]...
. Shaped like:
$ sed -i ‘1s/sad/happy/‘ test # 表示将test文件中第一行的"sad"替换为"happy"
- Common parameters
- Common action Commands
- Print the specified line
- In-line substitution
Inline substitution
4.awk Text Processing language
Awk is a very powerful programming language tool for working with text, and the course just takes us to get started.
awk [-F fs] [-v var=value] [-f prog-file | ‘program text‘] [file...]
。 Where the-f parameter is used to pre-specify the field delimiter mentioned earlier (and how other fields are specified),-V is used to pre-specify a variable for the AWK program, the-f parameter specifies the program file to be executed by the awk command, or the program statement is placed directly here without the-f argument. Finally, the text input that awk needs to process, and multiple text files can be entered at the same time.
- Practice: Create a new text document, print to a terminal
- Common built-in variables
5. Challenge Four
Goal:
在文件data中匹配数字开头的行,结果写入/home/shiyanlou/num文件; 在文件data中匹配出正确格式的邮箱,结果写入一个名为/home/shiyanlou/mail的文件。
section 14th software Installation under Linux
- Install Package: $ apt-get Install < package name >
- Update package: $ sudo apt-get update
- Uninstall software: $ sudo apt-get remove < package name >
- Search software: $ sudo apt-cache search softname1 softname2 softname3 ...
- Add: Use dpkg, install from binary package
- Practice work
15th Linux Process concept 1. Conceptual understanding
A program is a software designed to accomplish a task, and a process is a running program. A program has at least one process, and a process has at least one thread. The thread's dividing scale is smaller than the process, which makes the multi-thread procedure high concurrency. In addition, the process has a separate memory unit during execution, and multiple threads share memory, which greatly improves the efficiency of the program operation.
2. Properties of the process
- Classification, derivation of processes
- Process Group and Sessions
- Work Management
16th Linux Process Management Control
Learn some of the tools provided by Linux to view and control processes: View the running state of a process, the end control of a process, and the order in which processes are executed.
1. View of the process
- top tool use
First line:
Second line:
Third line:
Line Fourth:
Fifth line:
Process Status:
The use of the Li>ps tool
Uses the-l parameter to display its own bash-related process information for this login: ps-l
Relatively speaking, we use the following command, he will list all the process information : PS aux
If you look for one of these processes, we can also work with grep and regular expressions: ps aux | grep zsh
Can also be viewed, together with part of the in- The process appears in a tree-like way: PS axjf
Through Pstree you can see the same number of processes directly, the main thing is we can see the phase between all processes Nature:
pstree pstree-up #参数选择: #-a: Each program tree is connected in ASCII characters; #-p: Lists each proce The PID of the SS; #-u: The name of the account to which each process is owned is also listed.
2. Management of the process
- KILL command: Use Kill to manipulate the end of a process or restart.
- Process Execution order: Nice, ps command.
Section 17th Linux Log System
Common logs are typically stored in/var/log:
You can roughly divide the logs into two categories based on the service object: System log, Application log. System log is mainly for the system built-in program or system kernel such as log information such as Alternatives.log, btmp and so on, the application log is the third-party application of our installed log such as TOMCAT7, apache2 and so on.
references
Getting Started with Linux Basics (new version)
2017-2018-2 20179204 "Network attack and Defense practice" First week learning summary of the Linux Foundation