Click to follow, we will make progress a little bit every day together!
1. Overview of Linux
1.1 Why do testers learn linux
For software testers, any product we test is based on an operating system. For example, the QQ software we use every day, it has versions for windows, ios, Android, Mac OS, etc. It is necessary to install QQ on each platform to conduct corresponding tests. Therefore, proficiency in using these operating systems and mastering the basic knowledge of a series of operating systems should be the basic skills that every test engineer must master.
At present, the mainstream operating systems in the market include windows, unix, linux, etc., and linux, as the operating system used for the background server deployment of many software applications, is also the most widely used server-side operating system. Proficient in the use of linux systems, such words often appear in test job requirements and job seekers' skill descriptions. In this group of testers, those who can really use the Linux operating system proficiently, even if they are only familiar with common commands, are relatively rare! Therefore , testers learn linux , not only can they improve the depth of testing , but also can increase their core competitiveness , broaden their skill stacks , and improve their testing capabilities at a deeper level
What can testers do to learn linux? As a beginner, building a test environment should be the primary purpose of learning.
1.2 What is linux
Linux is an open source, free operating system. Its stability, security, and multi-concurrency processing have been recognized by the industry. At present, many neutral, large and even giant projects are using Linux.
Linux kernel: redhat, red flag linux, ubuntu, suse, fedora,
Their kernels are all the same (linux is actually a general term)
The Linux operating system has many advantages: free open source, multi-threading, multi-user support, good security, superior memory and file management, embedded system suitable for small kernel programs, etc.
The disadvantage of linux is that it uses command line operation, so the operation is relatively difficult, but it is this kind of character-level command line operation, which will occupy less system resources and reduce the possibility of being attacked and making mistakes.
1.3 Differences between linux and Windows
comparison of windows and linux |
||
windows |
linux |
|
TOLL |
TOLL |
free |
open source |
non-open source |
open source |
software resources |
Rich software resources, but most of them may need to purchase licenses |
Most software can be freely obtained, and there are fewer choices of software with the same function |
Technical Support |
main graphical interface |
Mainly character mode, command line interface |
1.4 How to learn linux
A tester's learning of linux is not necessarily very systematic, because proficient in linux is the job responsibility of the operation and maintenance personnel. As a tester, the primary purpose of learning should be to be proficient in using common commands and proficient in building a test environment. Therefore, keep practicing the commands. You should type each common command several times to verify the feedback after entering the command. Finally, practice makes perfect, and you can slowly remember the common commands.
So, how to learn linux? One word: practice!
2. Getting started with linux
2.1 Files, Directories
13.2.2 linux files
All contents of linux are stored in the form of files, including hardware (everything is a file), and linux does not distinguish file types by extension.
There are many basic types of linux, the common ones are as follows:
normal file |
Such as text files, shell scripts, java source code, c language source code, etc., you can use file operation commands such as vi, cat, more, less to manage |
catalog file |
It is a directory, which is equivalent to a folder on Windows, including the directory name and subdirectory name. You can use ls to list the contents of the directory |
link file |
Similar to the shortcut below in Windows |
2.3 linux directory
The Linux file system adopts a hierarchical tree-like directory structure. The top level of this structure is the root directory "/", and then other directories are created under this directory.
In the linux system, all files and directories start with the root directory /, the directories starting with / become absolute directories, and those that do not start with the root directory / are called relative directories.
The linux system file directory is organized as follows
/ |
The upper root directory of the linux file system, the top of the cultural system tree, called the root directory or top-level directory |
root |
Store the related files of the root user |
home |
The user's home directory (host directory) preset by the system, which stores related files of ordinary users |
bin |
A directory where all users can use common commands |
sbin |
System management-related binary files are stored in the directory. Only with certain permissions can the commands be used. |
etc |
Store various configuration files |
var |
Store frequently changing files, such as network connection sock files |
boot |
The startup directory, which stores the relevant files for booting the system |
usr |
Unix System Resource: The default directory for installing software, equivalent to the program files folder under Windows |
dev |
Device file storage directory |
lib |
System library save directory |
mnt |
The directory where the CD-ROM and floppy drives are mounted by default |
opt |
Additional installed application directory, some packages we can install it in this directory |
proc |
Directly written to the memory, cannot be directly operated, saves the mount point of the memory |
2.4 Common shortcut keys
tab |
automatic completion |
ctrl+c |
Forcibly terminate the current command execution, that is, kill the current process |
ctrl+l |
clear screen |
ctrl+z |
put the command in the background |
ctrl+r |
Search in command history |
ctrl+a |
Move the cursor to the beginning of the command line |
ctrl+e |
Move the cursor to the end of the command line |
ctrl+u |
Delete from the cursor position to the beginning of the line |
ctrl+b |
Same as left key on keyboard |
ctrl+f |
Same as keyboard right |
3. Common commands
After users log in to Linux, they can enter commands behind the Linux command prompt to interact with the system.
As follows:
[root@localhost~]#
in:
root: the currently logged in user
localhost:hostname
~: the current directory, ~ represents the home directory
#: The prompt of the super user, if it is a normal user, the prompt is $
linux command format: command [options] [parameters]
For example: cp dir1 dir2, cp is the copy command, dir1 and dir2 are parameters, which means to copy dir1 to dir2
Notice:
Individual command usage does not follow this format
When there are multiple commands, they can be written together
Simplified and full options, such as -a equals -all
Linux is strictly case-sensitive, and general commands are all lowercase without special instructions.
There are spaces between linux commands and parameters, please do not crowd them all together like English letters
The following is a detailed description of the most frequently used and commonly used commands in Linux.
4. Disk Management
4.1 cd
cd , change directory (chang directory)
The cd command allows the login user to switch between different directories
Syntax: cd [target directory]
The following are some commonly used directory switching
cd ~ |
Enter the current user's home directory |
cd |
Enter the current user's home directory |
cd - |
enter last directory |
cd.. |
Enter the previous directory |
cd . |
enter the current directory |
cd / |
enter the root directory |
Difference between relative path and absolute path
cd relative path: as long as the beginning is not / is a relative path, it will refer to the current directory and search through the relative path
cd absolute path: An absolute path is a file or directory name starting with the root directory /. For example: /home/data/package, it will start from the root directory (that is, the top-level directory /), and perform recursive search level by level. The absolute path e method is used through the cd command. As long as the path is correct, it can be located in any directory. Enter the specified directory.
4.2 ls
ls, list directory contents
Syntax: ls [target directory]
The ls command lists directory contents, including the names of files and subdirectories
-a |
Show all files in a directory, including hidden files |
-l |
Display long list format, abbreviated as ll |
-d |
View directory properties |
-h |
Humanized display file size |
-i |
show inode |
The habit of using at work is generally to switch to a certain directory with the cd command, and directly enter ls to view the contents of the current directory, which is similar to opening a certain folder on the Windows system.
Another common way of writing is ll, ll is the abbreviation of ls -l, which can list the contents of the directory in a list format, such as:
The description of each property of the package below:
drwxxr-xr-x |
Through 10 characters, the type of the file and the |
2 |
number of files connected |
root |
represents the user |
root |
Indicates the group the user is in |
4096 |
Indicates the file size |
June 23 05:28 |
Indicates the last modified date |
package |
Indicates the file name |
The first 10 characters of each line can determine the type of the file and the permissions of different users on the file
The first character indicates the type: file (-), directory (d), link (l)
The rest of the characters are in groups of 3 (rwx), read (r), write (w), execute (x)
The first group of rwx: file owner permissions are read, write and execute
The second group of rx: the permissions of users in the same group as the file owner are read and execute, no write permissions
The third group rx: the permissions of other users who are not in the same group as the file owner are read and execute, no write permissions
Read, write, and execute are represented by numbers as r=4, w=2, x=1 respectively.
rwx =4+2+1=7
rx=4+0+1=5
rx=4+0+1=5
So the permissions of the file for different users can be represented by the value 755
4.3 pwd
pwd, print working directory
Execute the pwd command to obtain the absolute path of the current working directory.
4.4 mkdir
mkdir, make directory
-p: Create a directory recursively, that is, if the upper-level directory of the directory is not created, the upper-level directory will be created together.
4.5 rmdir
Delete empty directories, this command is rarely used in actual operation, we generally use rm
Note that the rmdir command can only delete empty directories. If you want to delete all files in the directory, you can use: rm -rf path
4.6 df
df, displays information about the disk, such as file system usage
df [-ahikHTm] [directory or filename]
-a : list all filesystems
-k: Display each file system in KB
-m: Display each file system in MB
-h: Display in GB, MB, KB, etc. formats
-H: replace the calculation method of M=1024K with M=1000K
-T: List along with the partition's filesystem name (eg ext3)
-i: Display the number of inodes instead of the hard disk capacity
df [path], see which partition a directory is in, and display other information
Note that the two commands df and du are not frequently used by testers.
4.7 du
du, displays the size of a directory or file, and the du command displays the disk space occupied by the specified directory or file
Syntax: du [-ahskm] [file or directory name]
-a : List all file and directory sizes
-h: Display in human-readable capacity format (G/M)
-s: show the total, do not list the capacity occupied by each directory
-k: display capacity in KB
-m: List capacity display in MB
5. File Management
5.1 touch
touch, change the file or directory time, can also create an empty document
touch [-acdmt] filename
-a : modify access time
-c : modify time without creating file
-d: You can follow the date, or you can use --date="date or time"
-m: modify mtime
-t: Time can be followed by time, the format is [YYMMDDhhmm]
5.2 cp
cp copy command
The cp command is used to copy files or directories. The parameter must specify two or more files or directories, and the last path must be an existing directory. The previously specified file or directory can be copied to this directory.
Common parameters:
-a This option is usually used when copying directories. It preserves links, file attributes, and recursively copies directories.
-p copies the contents of the source file, and copies the modification time and access rights to the new file
-r If the given source file is a directory file, then cp will recursively copy all subdirectories and files in the directory. At this point the target file must be a directory name
Such as: cp -r dir1 dir2 dir3, recursively copy, copy dir1 and dir2 to the dir3 directory
5.3 mv
mv , move and rename
The mv command can move files or directories, and can also change file or directory names
grammar:
mv [source file or directory] [destination file or directory]
Such as mv dir1 dir2: move dir1 to the dir2 directory
mv /home/hello /home/world; rename the hello file in the /home directory to world
5.4rm
rm , delete files and directories
The rm command can delete a file or directory, use the parameter "-r" to delete the directory, otherwise the default is to delete the file
rm -rf * , delete everything, including directories and files
where -r means recursion and -f means force
5.5 cat
cat , display the contents of the file, and print the contents of the file to the standard output device
Syntax: cat fileName
Common parameters:
-n : Number the number of lines of output
5.6 head
View the first N lines of a plain text document and write to standard output
head -n 20 View the first 20 lines of a text file
5.7 tail
View the last N lines of a plain text document and write to standard output
tail -n 20 View the last 20 lines of a text document
tail -f error.log is constantly refreshed to view changes in file content in real time
5.8 more, less
more , display file content with pagination
Syntax: more fileName
The more command is similar to cat. It is displayed one page at a time, which is easy to read. Press the space bar to turn to the next page, and press the b key (or ctrl + pag up to turn up) to turn forward one page.
more + 10 fileName : display the content of fileName from line 10
less , display file content with pagination
less is similar to more, use less to browse files at will
5.9 echo
echo: output string
Syntax: echo [-ne] [string] or echo [--help][--version]
echo will send the input string to standard output
6. System Settings
6.1 alias
alias: some commands are very long, or the name seems awkward, you can give the command an alias
Command: alias: Display all aliases currently defined by the system
【Case】 alias cp = 'cp -i'
[Case] alias li = 'ls -l -color=tty'
Users can use alias , the alias of a custom command. If only alias is entered, all current alias settings will be listed. The validity of the alias is only based on the operation of the login. To set the alias automatically every time you log in, you can set the alias of the command in /etc/profile or your own ~/.bashrc.
Also, if you want a valid alias for every user, add the line alias la = 'ls -al' to the end of /etc/bashrc
bashrc is a configuration file for environment variables. The difference between /etc/bashrc and ~/.bashrc is that one is set for the whole system and the other is set for a single user. If you want to give an alias that takes effect for every user, please put alias la = 'ls -al' line is added to the end of /etc/bashrc, bashrc is a configuration file for environment variables. The difference between /etc/bashrc and ~/.bashrc is that one is set for the whole system and the other is set for single-user use
Execution order of commands:
1: Execute commands with absolute and relative paths
2: Execute alias
3: Execute Bash's internal commands
4: Execute to find the first command according to the directory defined by the $PATH environment variable
6.2 aliases
unalias: remove alias
Syntax: unalias alias
6.3 export
export, set and display environment variables
The export command can add, modify and delete environment variables
export -p : List all environment variables assigned to the program by the shell.
6.4 man
man [command] , help, similar to help in dos; man is actually manual (operation instructions),
man's level:
1: View the help for the command
2: View help for functions that can be called by the kernel
3: View help for functions and function libraries
4: View special files for help, mainly files in the /dev directory
5: View the help of the configuration file
6: View the game's help
7: View help for other miscellaneous items
8: View help for commands available to system administrators
9: View and kernel related files for help
See what level of help the command has:
man -f command, equivalent to whats command
eg: man -5 passwd
man -4 null
man -8 ifconfig
View all help related to commands
man -k command, equivalent to apropos command
If you like it, please follow it, and if it is useful, please forward it ~
Promotion, salary increase, no missed test - click "watching"