Chapter 3: Basics of Red Hat Linux 7.1
3.1 Log in and log out of the system
1. Start the system
Usually LILO is installed on the MBR. After the computer is started, the program on the MBR is executed, and a not very beautiful graphics will appear: on the left is a little Red Riding Hood image, and on the right is a list of the operating system that can be started, you can switch using the keyboard arrow. The default value is Linux after just installed, which means you don’t choose, and you will start Linux yourself later.
If the default choice is Windows, you can use vi to modify the files in the /etc directory after starting Linux, add default=windows, and then execute /sbin/lilo to regenerate LILO.
2. User login
Linux is a truly multi-user operating system. If users want to use this system, they must first log in. After using the system, they must log out. When a user logs into the system, in order for the system to recognize the user, he must enter the user name and password, and he can log in to the system and use it after the system is verified correctly.
There are two types of users under Linux:
1) root user: Super permission, the owner of the system, has and only one root user in the Linux system, and it can operate any operation in the system. The password set during system installation is the password of the root user.
2) Ordinary users: The Linux system can create many ordinary users and specify corresponding permissions to them so that they can use the Linux system with limited limitations.
We will explain in detail later on the management of users.
User login is carried out in two steps:
1) Enter the user's login name, and the system will identify the user based on the login name;
2) Enter the user's password. This password is a string selected by the user himself, which is completely confidential to other users and is the only basis for identifying users when logging in to the system. Therefore, every user should protect his password!
At the beginning of the system's establishment, there were only root users, while other users were created by root users. Because the root user's permissions are too large, if the root user misoperates, it may cause great losses. Therefore, it is recommended that the system administrator create a new user for himself and log in as the root user only when system maintenance and management tasks are required.
The following is a login example: (where bold text is input)
Red Hat Linux release 7.1 (Seawolf)
Kernerl 2.4.2-2 on an i686
Home login:root
Password:
In the above example, we found that it is empty after Password. In fact, it is not that you do not enter the password, but that when you enter, the Linux system will not display it, so it is used to protect the password!
If the login is successful, we will get the Shell (Shell is a program used to interact with the user, it is like in DOS, but there are many shells to choose from in Linux, such as bash, csh, ksh, etc.) prompt. If you log in as root user, the prompt obtained is "#", otherwise it will be "$".
Tip: If you set it to enter the graphical interface as soon as you start the installation, then after the system starts, the user login interface will be graphical, a bit like Windows, and when you enter the correct username and password, you will directly enter X Window. This setting can be modified:
In the /etc directory, there is an inittab file with a line of configuration:
id:3:default
Among them, the number 3 represents the character terminal that starts and enters the character terminal, and if changed to 5, it represents the character terminal that starts and enters the X Window.
3. Modify the password
In order to better protect the security of user accounts, Linux allows users to use the passwd command to modify their password at any time after logging in. To modify the password, you need to go through:
1) Enter the original password. If the password is entered incorrectly, the program will be aborted and the password cannot be modified;
2) Enter a new password;
3) The prompt is to repeat the new password. If the password entered twice matches, the password will be modified successfully.
It should be noted that in order to better protect passwords in Red Hat Linux 7.1, if the new password you enter is too simple, it will refuse to modify it. The following is an example of modifying the password: (where bold characters are input)
$ passwd
Changing password for user1
(current) UNIX password: ß Enter the original password in some
New UNIX password: ß Enter a new password
Retype new UNIX password: ß Enter a new password again
Passwd:all authentication tokens updated successfully ß Modified successfully!
Note that the password entered here will not be displayed either.
If the root user changes the password, you don’t need to enter the old password! That is, it can modify any user's password.
4. Log out
Whether you are a root user or a normal user, you can log out by simply executing the exit command.
5. Turn off the machine
In Linux systems, ordinary users do not have the right to shut down the system! Only the root user can close it. Of course, if you press the shutdown button, don't be a different matter. We can achieve this in the following ways:
1) Press the CTRL+ALT+DEL key combination, and the system will restart!
2) Execute the reboot command, and the system will also restart!
3) Execute the shutdown -h now command, so the system will shut down the computer!
4) Execute the halt command to shut down the computer.
Be careful not to shut down the system by using hard shutdown, restart keys, etc., as this will cause damage to the Linux file system!
6. Virtual console
Linux is a true multi-user operating system that can accept remote and local logins from multiple users at the same time, and also allows the same user to log in multiple times. Linux provides virtual console access methods for local users (that is, users who are in front of computers), allowing users to log in multiple times from different consoles at the same time.
Selecting the virtual console can be achieved by pressing the ALT key plus six function keys F1-F6. For example, after the user logs in, press the ALT+F2 key combination, and the user can see the "login:" prompt again, which is actually the second virtual console. When the ALT+F1 key combination is pressed, the user can return to the first virtual console.
You can experience the characteristics of multiple users of the Linux system by using a virtual console. For example, a user can switch to another virtual console to start another work before the work is finished. For example, when developing software, you can edit programs on one console, compile them on another console, and review information on the third console.
3.2 File and directory operations
Like other operating systems, users' data and programs are also saved in the form of files under Linux systems. Therefore, when using Linux, files and directories are often operated. Now let’s learn how to operate files and directories under Linux from the perspective of a Window user.
1. File name and file type
The file name is the identity of a file. From this perspective, the rules of file names are basically the same as those under Windows 9x. It is also composed of letters, numbers, underscores, and dots, with a maximum length of 255 characters.
Like Windows 9x, there are also ordinary files and directory files in Linux systems, but directory files are simply called directories in Window. There is a special file in the Linux system, that is, device files. In Linux systems, each I/O setting is mapped into a file, which can be processed like a normal file, which makes the operation of the file and the device as unified as possible. From the user's perspective, the use of I/O devices is almost the same as that of general files, so that you don't have to understand the details of I/O devices.
2. Directory structure
Like Windows, files are organized through directories in Linux. But the difference is that there is only one root directory under Linux, and it is not like Windows, which is a partition and one root directory. If there are multiple partitions, you need to mount other partitions to the root directory for use.
Recalling when we were partitioning Linux, there was an option to fill in, that is Mount Point. We wrote one of them as "/", which is the root directory (the opposite of Windows, one is "\" and the other is "/", which is really a natural enemy). Others may be /home, /usr.
After installing the system, you will find that /home and /usr are the home and usr directories under the root directory! By the way, the entire partition is used for this directory.
After installing Linux, there are many directories. Let’s explain some important directories below:
/bin: Stores more than 100 commonly used commands and tools under Linux
/dev: Store all device files under Linux!
/home: User home directory. Every time a user is created, a new directory with the same name as the user will be created here, giving the user a space of its own
/lost+found: As the name implies, some missing files may be found here
/mnt: The hook point of external devices, usually using two subdirectories: cdrom and floppy! Its existence simplifies the use of CDs and floppy disks. You just need to mount /mnt/cdrom after stuffing the disc, and you can mount the contents on the disc to /mnt/cdrom and you can access it. However, after you have finished using it, you should leave the directory and execute umount /mnt/cdrom. Similarly, floppy disks are mount /mnt/floppy and umount /mnt/floppy.
/proc: This is actually a fake directory, through which you can access the contents in the memory.
/sbin: Here are system-level commands and tools
/usr: Usually used to install various software
/usr/X11R6 X Window Directory
/usr/bin and /usr/sbin Some post-installation commands and tools
/usr/include, /usr/lib and /usr/share store some shared link libraries
/usr/local is often used to install new software
/usr/src Linux source program
/boot: Linux is started from here
/etc: Most configuration files stored here in Linux
/lib: Static link library
/root: root user's home directory, this is one of the privileges!
/var: Usually used to store some changes!
/var/log: Store system logs
/var/spool: store some emails, news, print queues, etc.
In addition, it should be noted that the concepts such as "current directory" and "path" under Linux are the same as those under Windows.
3. Display the file contents
Anyone who has used DOS commands should know that we can use the type command to view the contents of a file. There are five related commands under Linux, each with its own advantages, but they are all like type commands and can only be used to view text files.
1) cat command
The cat command is the most similar to the type command, and the method used is very simple: "cat file name". However, what is more powerful than the type command is that it can view multiple files at the same time: "cat file name one file name two".
2) more command
If the text file is long and cannot be displayed in one screen, then it may not be able to see clearly using the cat command. Here we can simply use more instead of cat command. Its effect is similar to type file name/p. Use the more command to display the text one screen at a time. After the display is full, stop and prompt the percentage of all the contents that have been displayed. Press the space bar to see the next screen.
3) less command
The function of the less command is almost the same as the more command, and it also displays files by page. The difference is that the less command allows users to flip through files both forward and backward when displaying files.
Ø Turn forward: press the b key;
Ø Turn backwards: press the p key;
Ø Specify location: Enter percentage
Ø Exit: q
I often use more and less and hardly use cat to view files.
4) head command
The head command can only view the first few lines of a file, and the format is:
head line number file name
If no row count is specified, the default value of 10 is used.
5) tail command
Corresponding to the head command, we can use the tail command to view the content at the end of the file. It is usually used to monitor whether a file has been modified in real time, and is usually used to observe logs. like:
tail -f maillog
4. Edit the file
There are many text editing tools in Red Hat Linux 7, the most commonly used one should be vi, which is an editor that is widely used in all UNIX systems. Its use is a bit special:
First, you can use the command "vi file name" to open a file.
When it was first started, vi was in the command state and could not enter any characters. In this state, you can use the arrow keys to move, and when you need to enter content, you need to enter the "i" or "a" command to enter the editing state. After editing is complete, you need to press the "ESC" key to return to the command state.
In the command state, you can enter ":q!" to exit without saving and ":wq" to exit.
5. Copy, delete and move files
Everyone is already familiar with DOS we can use copy, del, and move commands to copy, delete and move files. Let's talk about how to do the above operations in Linux system.
1) cp command: file/directory copy command
Its syntax format is: cp [Options] Source file or directory Target file or directory
Common options are:
Ø a This option is often used when copying directories. It retains links and file attributes and recursively copies directories, just like xcopy /s in DOS
Ø f If the target file or directory already exists, overwrite it and do not prompt
Ø i is exactly the opposite of the f option. When it is overridden, it will ask the user to answer "Y" to confirm.
Øp Use this option to retain modification time and access permissions when copying files
Ø r If the source given is a directory, then CP will recursively copy all subdirectories and files in that directory, but this requires that the target is also a directory name
In addition, it is important to note that if the source is a file name and the target is a directory name, then you can specify multiple source file names using the cp command. like:
$ cp /home/user1
This command will copy the and file into the /home/usr1 directory.
2) rm command: file/directory delete command
Its syntax format is: rm [options] file…
Common options are:
Ø f No instructions are given during the deletion process, and directly delete
Ø r Instructs rm to recursively delete all directories and subdirectories listed in the parameter
Ø i Interactively deleted, each file is given a prompt when deleting it
Be careful when using the rm command, especially when logging in as root user, I saw a friend accidentally typed the command "rm -rf /home/tmp" into "rm -rf /home/tmp" when using the rm command to delete the /home/tmp directory. As a result, when he walked back to the computer, the entire system was deleted!
3) mv command: file/directory move command
Its syntax format is: mv [Options] Source file or directory Target file or directory
Common options are:
Ø f If the operation is to overwrite an existing target file, no indication is given
Ø i Interactive operation. If the operation wants to overwrite an existing target file, the user will be asked whether to overwrite it.
The execution effect of the mv command is different from the parameter type!
First parameter (source) Second parameter (target) Result
File name File name Change the source file name to the target file name
File name Directory name Move the file to the target directory
Directory Name Directory Name The target directory already exists: the source directory is moved to the target directory
The target directory does not exist: change the name
Directory name File name Error
6. Directory-related operations
1) Create a new directory: mkdir, which is used the same as md under DOS: mkdir directory name;
2) Delete the empty directory: rmdir, its use is the same as rd under DOS: rmdir directory name;
3) Change the directory: cd, its use is basically the same as the cd command under DOS. The only difference is that no matter what the directory name is, there must be spaces between cd and the directory name, that is, "cd/", "cd..", and "cd." are all illegal. Instead, you should enter: "cd /", "cd ..", and "cd .". If you directly enter the command "cd" without adding any parameters, you will return to the home directory of this user.
4) Show the current directory: pwd
5) Column directory command: ls, equivalent to dir under DOS
Its syntax is: ls [option] [directory or file]
Common options are:
Ø a Displays all subdirectories and files in the specified directory, including hidden files;
Ø c Sort by file modification time
Ø l Use a long format to display the detailed information of the file, one line of information per file, its content is: file type and permissions Number of links File owner File group File size Last modified time File name
7. Permission operations for files and directories
In Linux systems, each file and directory has corresponding access permissions, which we can use to determine who can access and operate files and directories in what way. Access rights of files or directories are divided into three types: readable, writable and executable, respectively, represented by r, w, and x, and their meanings are:
r w x
File Readable Writable Executable
Directory List directory Can be written in directory You can access this directory
When a file is created, the file owner can set the permissions of the file.
For a file, users can be divided into three types and given different permissions to them:
1) File owner
2) Users in the same group as file owner
3) Other users
There are three groups of access rights for each file or directory, each group is represented by three digits, such as:
d rwx r-x r--
Part 1: Here d represents the directory, and the others are: - represents ordinary files c represents character device files;
Part 2: The permission word of the file owner, here r w x means readable, writable, and executable (the executable of the directory means that it can enter the directory);
Part 3: The permission word for users in the same group as the file owner. Here r - x means readable, unwritable, and executable. Since users in the same group communicate a lot, let him check the files and just don’t modify them randomly.
Part 4: The permission words for other users are here - - -. Of course, I will give them to people who have nothing to do with me. Of course, my files will not only not be written to you, but also not be allowed to read them.
1) File/directory permission setting command: chmod
This is one of the most commonly used commands by Linux system administrators, which is used to change access rights to files or directories. This command has two uses:
Ø Use text setting method that contains letters and operator expressions
Its syntax format is: chmod [who] [opt] [mode] file/directory name
Where who represents an object, is one or a combination of the following letters:
u: indicates the file owner
g: means the same group of users
o: means other users
a: means all users
opt represents the operation, which can be:
+: Add a permission
-: Cancel a permission
=: Grant a given permission and cancel the original permission
Mode represents permissions:
r: readable
w: Writable
x: Executable
For example: add read and write permissions to files for users in the same group:
chmod g+rw
Ø Use digital setting method
The rule of setting numbers is simpler: chmod [mode] file name
The key is the value of mode. At the beginning, many beginners will be confused. In fact, it is very simple. We regard rwx as a binary number. If there is, there is a 1 representation, and if there is no, there is a 0 representation. Then rwx r-x r--- can represent it as:
111 101 100
Then convert every three digits into a decimal number, which is 754.
For example, we want the permissions of this file to be:
Users in the same group Other users
Readable Yes Yes Yes
Writable Yes Yes
Executable
Then, we first get the permission string according to the above table: rw-rw-r--, then converting it into a binary number is 110 110 100, and then converting it into a decimal number every three digits will get 664. Therefore, we execute the command:
chmod 664
2) Change the owner command of the file: chown
The syntax format is simple: chown [Options] Username File/Directory Name
The most commonly used option is "R". Adding this parameter can change the owner of all subdirectories and files in the entire directory to the specified user.
3) Change the file group command: chgrp
This command is also very simple: chgrp group name file name
3.3 User Management
The main task of user management is to establish a legal user account, set and manage user passwords, modify the properties of user account, and delete the abandoned user account if necessary.
1. Add a new user
In Linux system, only the root user can create a new user. The following command will create a new user with login name user1.
# useradd user1
However, this user cannot log in because the initial password has not been set for it, and users without the password cannot log in to the system. By default, a new user home directory with the same user name will be created in the /home directory. If you need to specify the user home directory, you can use the following command:
# useradd -d /home/xf user1
At the same time, when the user logs in, he will get a shell program: /bin/bash. If you don't want this user to log in, you can specify that the user's shell program is: /bin/false. In this way, even if the user logs in, he cannot execute the commands under Linux:
# useradd -s /bin/false user1
In Linux, a new group will be created while adding a new user, which has the same name as the user, and this user is a member of the group. If you want the new user to be part of an existing group, you can use the following command:
# useradd -g user user1
In this way, the user belongs to the user group. And if you just want it to belong to another group, you should use:
# useradd -G user user1
After completing this, you should also use the passwd command to set an initial password for it.
2. Delete a user
To delete a user, just use a simple command "userdel username". However, it is best to delete the files left on the system, and you can use "userdel -r username" to achieve this.
3. Modify user attributes
In the previous example, we saw how to specify the user home directory when creating a new user, how to specify its shell, how to set the group it belongs to... and so on. A command is provided in Linux to implement:
usermod -g group name -G group name -d user home directory -s user shell
There is another direct method, which is to modify the /etc/passwd file. In this file, each user occupies one line, and its content is:
Username: Password: User ID: Group ID: User full name: User home directory: User Shell
However, it is worth noting that the password item is usually replaced by a * number, which you cannot see.
4. Add a group
Remember that Linux files can set different access permissions for people in the same group and people in different groups? We can create user groups according to our needs:
groupadd group name
5. Delete a group
Similarly, we sometimes need to delete a group, and its command is the groupdel group name.
6. Modify group members
If we need to add a user to a group, just edit the /etc/group file and write the user name behind the group name. For example, add the newuser user to the softdevelop group, just find the softdevelop line:
softdevelop:x:506:user1,user2
Then add newuser to form:
softdevelop:x:506:user1,user2,newuser
In addition, Red Hat Linux also provides a graphical user management tool: userconf, through which users can be managed more directly.
3.4 Process Management
Linux is a multi-user and multi-tasking operating system. Multi-user means that multiple users can use the computer system at the same time; multi-tasking means that Linux can perform several tasks at the same time, and it can perform another task before one task has been completed.
Everything that runs on a Linux system can be called a process. Every user task and every system management daemon can be called a process. Linux uses time-sharing management methods to share system resources together using all tasks. Let’s take a look at how to control these processes.
1. Start the process
There are two ways to start a process in Linux system:
1) Enter the command directly and a process will be started directly
ØUnder normal circumstances, the process will be executed in the foreground, and we can no longer execute new commands
Ø If we add a "&" after the command, the process will be executed in the background, and we can still execute the new command
2) Through the at, cron, and crontab commands, a process can be started regularly like scheduled tasks in Windows. For specific usage methods, you can use the man command name to query.
2. View the process
In Linux system, we can use the ps command to view the running process, for example:
List the processes that belong to the current user:
# ps
PID TTY TIME CMD
16767 pts/1 0:00 ps
18029 pts/1 0:00 bash
Where PID represents the process ID, TTY is which console the process was started, and CMD is the command.
If you want to list more detailed information, you can use the command: "ps -auxw".
3. Terminate the process
A process will be completed automatically after the task is completed. If you want to abort the process midway, there are two ways:
1) For programs running in the foreground, the process can be aborted directly by using the key combination CTRL+C;
2) For programs running in the background, you need to find its process number through the ps command introduced earlier, and then use "kill process number" to terminate the process.
3.5 Disk Management
System software and application software must be stored in the computer's disk space in the form of files. As a system administrator, you should monitor the use of the disk space at any time. We can use the following two commands to implement it:
1. df command
df means Disk Free, as the name implies, it is to check how much space is left on the disk and other information. Here is an example of usage:
# df
FileSystem 1k-blocks Used Available Use% Mounted on
/dev/hda5 4134900 1749728 2175124 45% /
/dev/hda6 6048320 5741092 0 100% /home
A total of 6 columns of information are displayed:
1) FileSystem: Hard disk partition
2) 1k-blocks: the partition size calculated by K
3) Used: The partition size that has been used (calculated in K)
4) Available: The partition size you need to use
5) Use%: the percentage of space used
6) Mounted on: Mounted point
You can see that /home is another partition, and now the space is used up! This was not planned at that time!
If the hard disk space is represented in K as the calculation unit, then you can use df -m, which will be calculated in M.
2. du command
du, that is disk usage, that is, to see how much disk is used. Here is an example of usage:
# pwd
/var/log
# du
4 ./uucp
776 .
Here, we use the du command to list the disk space occupied by the /var/log directory. It counts that this directory has a subdirectory: uucp, which occupies 4K, while the files in the /var/log directory have a total of 776K.
This command also has some commonly used options to complete more functions:
Ø -a will list the disk usage of all files, subdirectories, files in subdirectories, subdirectories in subdirectories...
Ø -b Indicates the disk space occupied in bytes
Ø -c Shows a statistic at the end
3.6 Software Installation
Under Red Hat Linux, the application software installation package usually has two formats:
1) rpm package, such as software-1.2.3-1. It is a package format created by Redhat Linux.
2) tar package, such as software-1.2. It is packaged using the UNIX system's packaging tool tar.
Moreover, most Linux application packages have certain rules to naming, which follows:
Name - Version - Revised Version - Type
For example:
sfotware-1.2.3-1.
Software name: software
Version number: 1.2.3
Fixed version: 1
Available platform: i386, suitable for Intel 80x86 platform.
Type: rpm, indicating that it is an rpm package.
According to the contents in the Linux application software installation package, it can be divided into:
1) It is an executable file, which means it can be run directly after unpacking. All packages in Windows are of this type. After installing this program, you can use it. However, when downloading, please pay attention to whether this software is the platform you are using, otherwise it will not be installed normally.
2) Another is the source program, which means that after unpacking, you also need to use a compiler to compile it into an executable file. This is almost non-existent in Windows systems, because the Windows idea is not open source programs.
Usually, those packaged with tar are source programs; while those packaged with rpm are often executable programs.
1. Get the application software packaged using rpm
rpm is a major contribution to Redhat, which makes Linux software installation easier and easier.
1) Installation:
I can finish it in just one simple sentence. implement:
rpm -ivh rpm package name
For more advanced ones, please see the table below:
rpm parameter parameter description
-i Install software
-t Test installation, not really installation
-p Show installation progress
-f No matter what error
-U Upgrade and Installation
-v Check whether the suite is installed correctly
These parameters can be used simultaneously. For more information, please refer to the command help of RPM.
2) Uninstall:
I can finish it in just a simple sentence. implement:
rpm -e software name
However, it should be noted that the software name is used later, not the package name. For example, when installing software-1.2.3-1. this package, you should execute:
rpm -ivh software-1.2.3-1.
And when uninstalling, you should execute:
rpm -e software。
2. Get the application packaged using tar
1) Installation:
The entire installation process can be divided into the following steps:
Ø Obtain application software: obtain by downloading and purchasing CDs;
Ø Unzip the file: Generally, tar packages will be compressed again, such as gzip, bz2, etc., so you need to decompress first. If it is the most common gz format, you can execute: "tar -xvzf package name", and you can complete the decompression and unpacking work in one step. If not, use the decompression software first, then execute "tar -xvf decompressed tar package" to unpack;
Ø Read the included INSTALL files and README files;
Ø Execute the "./configure" command to prepare for compilation;
Ø Execute the "make" command to compile the software;
Ø Perform “make install” to complete the installation;
Ø Execute "make clean" to delete temporary files generated during installation.
OK, that's it. We can run the application. But at this time, some readers will ask, how do I execute it? This is also a Linux-specific issue. In fact, generally speaking, the executable files of Linux application software will be stored in the /usr/local/bin directory! However, this is not the truth that "everyone can be used". The most reliable thing is to look at the INSTALL and README files of this software, which are generally explained.
2) Uninstall:
Usually, software developers rarely consider how to uninstall their own software, and tar only completes the packaging work, so they do not provide a good uninstall method. Generally, make uninstall is provided to uninstall the software.
3.1 Log in and log out of the system
1. Start the system
Usually LILO is installed on the MBR. After the computer is started, the program on the MBR is executed, and a not very beautiful graphics will appear: on the left is a little Red Riding Hood image, and on the right is a list of the operating system that can be started, you can switch using the keyboard arrow. The default value is Linux after just installed, which means you don’t choose, and you will start Linux yourself later.
If the default choice is Windows, you can use vi to modify the files in the /etc directory after starting Linux, add default=windows, and then execute /sbin/lilo to regenerate LILO.
2. User login
Linux is a truly multi-user operating system. If users want to use this system, they must first log in. After using the system, they must log out. When a user logs into the system, in order for the system to recognize the user, he must enter the user name and password, and he can log in to the system and use it after the system is verified correctly.
There are two types of users under Linux:
1) root user: Super permission, the owner of the system, has and only one root user in the Linux system, and it can operate any operation in the system. The password set during system installation is the password of the root user.
2) Ordinary users: The Linux system can create many ordinary users and specify corresponding permissions to them so that they can use the Linux system with limited limitations.
We will explain in detail later on the management of users.
User login is carried out in two steps:
1) Enter the user's login name, and the system will identify the user based on the login name;
2) Enter the user's password. This password is a string selected by the user himself, which is completely confidential to other users and is the only basis for identifying users when logging in to the system. Therefore, every user should protect his password!
At the beginning of the system's establishment, there were only root users, while other users were created by root users. Because the root user's permissions are too large, if the root user misoperates, it may cause great losses. Therefore, it is recommended that the system administrator create a new user for himself and log in as the root user only when system maintenance and management tasks are required.
The following is a login example: (where bold text is input)
Red Hat Linux release 7.1 (Seawolf)
Kernerl 2.4.2-2 on an i686
Home login:root
Password:
In the above example, we found that it is empty after Password. In fact, it is not that you do not enter the password, but that when you enter, the Linux system will not display it, so it is used to protect the password!
If the login is successful, we will get the Shell (Shell is a program used to interact with the user, it is like in DOS, but there are many shells to choose from in Linux, such as bash, csh, ksh, etc.) prompt. If you log in as root user, the prompt obtained is "#", otherwise it will be "$".
Tip: If you set it to enter the graphical interface as soon as you start the installation, then after the system starts, the user login interface will be graphical, a bit like Windows, and when you enter the correct username and password, you will directly enter X Window. This setting can be modified:
In the /etc directory, there is an inittab file with a line of configuration:
id:3:default
Among them, the number 3 represents the character terminal that starts and enters the character terminal, and if changed to 5, it represents the character terminal that starts and enters the X Window.
3. Modify the password
In order to better protect the security of user accounts, Linux allows users to use the passwd command to modify their password at any time after logging in. To modify the password, you need to go through:
1) Enter the original password. If the password is entered incorrectly, the program will be aborted and the password cannot be modified;
2) Enter a new password;
3) The prompt is to repeat the new password. If the password entered twice matches, the password will be modified successfully.
It should be noted that in order to better protect passwords in Red Hat Linux 7.1, if the new password you enter is too simple, it will refuse to modify it. The following is an example of modifying the password: (where bold characters are input)
$ passwd
Changing password for user1
(current) UNIX password: ß Enter the original password in some
New UNIX password: ß Enter a new password
Retype new UNIX password: ß Enter a new password again
Passwd:all authentication tokens updated successfully ß Modified successfully!
Note that the password entered here will not be displayed either.
If the root user changes the password, you don’t need to enter the old password! That is, it can modify any user's password.
4. Log out
Whether you are a root user or a normal user, you can log out by simply executing the exit command.
5. Turn off the machine
In Linux systems, ordinary users do not have the right to shut down the system! Only the root user can close it. Of course, if you press the shutdown button, don't be a different matter. We can achieve this in the following ways:
1) Press the CTRL+ALT+DEL key combination, and the system will restart!
2) Execute the reboot command, and the system will also restart!
3) Execute the shutdown -h now command, so the system will shut down the computer!
4) Execute the halt command to shut down the computer.
Be careful not to shut down the system by using hard shutdown, restart keys, etc., as this will cause damage to the Linux file system!
6. Virtual console
Linux is a true multi-user operating system that can accept remote and local logins from multiple users at the same time, and also allows the same user to log in multiple times. Linux provides virtual console access methods for local users (that is, users who are in front of computers), allowing users to log in multiple times from different consoles at the same time.
Selecting the virtual console can be achieved by pressing the ALT key plus six function keys F1-F6. For example, after the user logs in, press the ALT+F2 key combination, and the user can see the "login:" prompt again, which is actually the second virtual console. When the ALT+F1 key combination is pressed, the user can return to the first virtual console.
You can experience the characteristics of multiple users of the Linux system by using a virtual console. For example, a user can switch to another virtual console to start another work before the work is finished. For example, when developing software, you can edit programs on one console, compile them on another console, and review information on the third console.
3.2 File and directory operations
Like other operating systems, users' data and programs are also saved in the form of files under Linux systems. Therefore, when using Linux, files and directories are often operated. Now let’s learn how to operate files and directories under Linux from the perspective of a Window user.
1. File name and file type
The file name is the identity of a file. From this perspective, the rules of file names are basically the same as those under Windows 9x. It is also composed of letters, numbers, underscores, and dots, with a maximum length of 255 characters.
Like Windows 9x, there are also ordinary files and directory files in Linux systems, but directory files are simply called directories in Window. There is a special file in the Linux system, that is, device files. In Linux systems, each I/O setting is mapped into a file, which can be processed like a normal file, which makes the operation of the file and the device as unified as possible. From the user's perspective, the use of I/O devices is almost the same as that of general files, so that you don't have to understand the details of I/O devices.
2. Directory structure
Like Windows, files are organized through directories in Linux. But the difference is that there is only one root directory under Linux, and it is not like Windows, which is a partition and one root directory. If there are multiple partitions, you need to mount other partitions to the root directory for use.
Recalling when we were partitioning Linux, there was an option to fill in, that is Mount Point. We wrote one of them as "/", which is the root directory (the opposite of Windows, one is "\" and the other is "/", which is really a natural enemy). Others may be /home, /usr.
After installing the system, you will find that /home and /usr are the home and usr directories under the root directory! By the way, the entire partition is used for this directory.
After installing Linux, there are many directories. Let’s explain some important directories below:
/bin: Stores more than 100 commonly used commands and tools under Linux
/dev: Store all device files under Linux!
/home: User home directory. Every time a user is created, a new directory with the same name as the user will be created here, giving the user a space of its own
/lost+found: As the name implies, some missing files may be found here
/mnt: The hook point of external devices, usually using two subdirectories: cdrom and floppy! Its existence simplifies the use of CDs and floppy disks. You just need to mount /mnt/cdrom after stuffing the disc, and you can mount the contents on the disc to /mnt/cdrom and you can access it. However, after you have finished using it, you should leave the directory and execute umount /mnt/cdrom. Similarly, floppy disks are mount /mnt/floppy and umount /mnt/floppy.
/proc: This is actually a fake directory, through which you can access the contents in the memory.
/sbin: Here are system-level commands and tools
/usr: Usually used to install various software
/usr/X11R6 X Window Directory
/usr/bin and /usr/sbin Some post-installation commands and tools
/usr/include, /usr/lib and /usr/share store some shared link libraries
/usr/local is often used to install new software
/usr/src Linux source program
/boot: Linux is started from here
/etc: Most configuration files stored here in Linux
/lib: Static link library
/root: root user's home directory, this is one of the privileges!
/var: Usually used to store some changes!
/var/log: Store system logs
/var/spool: store some emails, news, print queues, etc.
In addition, it should be noted that the concepts such as "current directory" and "path" under Linux are the same as those under Windows.
3. Display the file contents
Anyone who has used DOS commands should know that we can use the type command to view the contents of a file. There are five related commands under Linux, each with its own advantages, but they are all like type commands and can only be used to view text files.
1) cat command
The cat command is the most similar to the type command, and the method used is very simple: "cat file name". However, what is more powerful than the type command is that it can view multiple files at the same time: "cat file name one file name two".
2) more command
If the text file is long and cannot be displayed in one screen, then it may not be able to see clearly using the cat command. Here we can simply use more instead of cat command. Its effect is similar to type file name/p. Use the more command to display the text one screen at a time. After the display is full, stop and prompt the percentage of all the contents that have been displayed. Press the space bar to see the next screen.
3) less command
The function of the less command is almost the same as the more command, and it also displays files by page. The difference is that the less command allows users to flip through files both forward and backward when displaying files.
Ø Turn forward: press the b key;
Ø Turn backwards: press the p key;
Ø Specify location: Enter percentage
Ø Exit: q
I often use more and less and hardly use cat to view files.
4) head command
The head command can only view the first few lines of a file, and the format is:
head line number file name
If no row count is specified, the default value of 10 is used.
5) tail command
Corresponding to the head command, we can use the tail command to view the content at the end of the file. It is usually used to monitor whether a file has been modified in real time, and is usually used to observe logs. like:
tail -f maillog
4. Edit the file
There are many text editing tools in Red Hat Linux 7, the most commonly used one should be vi, which is an editor that is widely used in all UNIX systems. Its use is a bit special:
First, you can use the command "vi file name" to open a file.
When it was first started, vi was in the command state and could not enter any characters. In this state, you can use the arrow keys to move, and when you need to enter content, you need to enter the "i" or "a" command to enter the editing state. After editing is complete, you need to press the "ESC" key to return to the command state.
In the command state, you can enter ":q!" to exit without saving and ":wq" to exit.
5. Copy, delete and move files
Everyone is already familiar with DOS we can use copy, del, and move commands to copy, delete and move files. Let's talk about how to do the above operations in Linux system.
1) cp command: file/directory copy command
Its syntax format is: cp [Options] Source file or directory Target file or directory
Common options are:
Ø a This option is often used when copying directories. It retains links and file attributes and recursively copies directories, just like xcopy /s in DOS
Ø f If the target file or directory already exists, overwrite it and do not prompt
Ø i is exactly the opposite of the f option. When it is overridden, it will ask the user to answer "Y" to confirm.
Øp Use this option to retain modification time and access permissions when copying files
Ø r If the source given is a directory, then CP will recursively copy all subdirectories and files in that directory, but this requires that the target is also a directory name
In addition, it is important to note that if the source is a file name and the target is a directory name, then you can specify multiple source file names using the cp command. like:
$ cp /home/user1
This command will copy the and file into the /home/usr1 directory.
2) rm command: file/directory delete command
Its syntax format is: rm [options] file…
Common options are:
Ø f No instructions are given during the deletion process, and directly delete
Ø r Instructs rm to recursively delete all directories and subdirectories listed in the parameter
Ø i Interactively deleted, each file is given a prompt when deleting it
Be careful when using the rm command, especially when logging in as root user, I saw a friend accidentally typed the command "rm -rf /home/tmp" into "rm -rf /home/tmp" when using the rm command to delete the /home/tmp directory. As a result, when he walked back to the computer, the entire system was deleted!
3) mv command: file/directory move command
Its syntax format is: mv [Options] Source file or directory Target file or directory
Common options are:
Ø f If the operation is to overwrite an existing target file, no indication is given
Ø i Interactive operation. If the operation wants to overwrite an existing target file, the user will be asked whether to overwrite it.
The execution effect of the mv command is different from the parameter type!
First parameter (source) Second parameter (target) Result
File name File name Change the source file name to the target file name
File name Directory name Move the file to the target directory
Directory Name Directory Name The target directory already exists: the source directory is moved to the target directory
The target directory does not exist: change the name
Directory name File name Error
6. Directory-related operations
1) Create a new directory: mkdir, which is used the same as md under DOS: mkdir directory name;
2) Delete the empty directory: rmdir, its use is the same as rd under DOS: rmdir directory name;
3) Change the directory: cd, its use is basically the same as the cd command under DOS. The only difference is that no matter what the directory name is, there must be spaces between cd and the directory name, that is, "cd/", "cd..", and "cd." are all illegal. Instead, you should enter: "cd /", "cd ..", and "cd .". If you directly enter the command "cd" without adding any parameters, you will return to the home directory of this user.
4) Show the current directory: pwd
5) Column directory command: ls, equivalent to dir under DOS
Its syntax is: ls [option] [directory or file]
Common options are:
Ø a Displays all subdirectories and files in the specified directory, including hidden files;
Ø c Sort by file modification time
Ø l Use a long format to display the detailed information of the file, one line of information per file, its content is: file type and permissions Number of links File owner File group File size Last modified time File name
7. Permission operations for files and directories
In Linux systems, each file and directory has corresponding access permissions, which we can use to determine who can access and operate files and directories in what way. Access rights of files or directories are divided into three types: readable, writable and executable, respectively, represented by r, w, and x, and their meanings are:
r w x
File Readable Writable Executable
Directory List directory Can be written in directory You can access this directory
When a file is created, the file owner can set the permissions of the file.
For a file, users can be divided into three types and given different permissions to them:
1) File owner
2) Users in the same group as file owner
3) Other users
There are three groups of access rights for each file or directory, each group is represented by three digits, such as:
d rwx r-x r--
Part 1: Here d represents the directory, and the others are: - represents ordinary files c represents character device files;
Part 2: The permission word of the file owner, here r w x means readable, writable, and executable (the executable of the directory means that it can enter the directory);
Part 3: The permission word for users in the same group as the file owner. Here r - x means readable, unwritable, and executable. Since users in the same group communicate a lot, let him check the files and just don’t modify them randomly.
Part 4: The permission words for other users are here - - -. Of course, I will give them to people who have nothing to do with me. Of course, my files will not only not be written to you, but also not be allowed to read them.
1) File/directory permission setting command: chmod
This is one of the most commonly used commands by Linux system administrators, which is used to change access rights to files or directories. This command has two uses:
Ø Use text setting method that contains letters and operator expressions
Its syntax format is: chmod [who] [opt] [mode] file/directory name
Where who represents an object, is one or a combination of the following letters:
u: indicates the file owner
g: means the same group of users
o: means other users
a: means all users
opt represents the operation, which can be:
+: Add a permission
-: Cancel a permission
=: Grant a given permission and cancel the original permission
Mode represents permissions:
r: readable
w: Writable
x: Executable
For example: add read and write permissions to files for users in the same group:
chmod g+rw
Ø Use digital setting method
The rule of setting numbers is simpler: chmod [mode] file name
The key is the value of mode. At the beginning, many beginners will be confused. In fact, it is very simple. We regard rwx as a binary number. If there is, there is a 1 representation, and if there is no, there is a 0 representation. Then rwx r-x r--- can represent it as:
111 101 100
Then convert every three digits into a decimal number, which is 754.
For example, we want the permissions of this file to be:
Users in the same group Other users
Readable Yes Yes Yes
Writable Yes Yes
Executable
Then, we first get the permission string according to the above table: rw-rw-r--, then converting it into a binary number is 110 110 100, and then converting it into a decimal number every three digits will get 664. Therefore, we execute the command:
chmod 664
2) Change the owner command of the file: chown
The syntax format is simple: chown [Options] Username File/Directory Name
The most commonly used option is "R". Adding this parameter can change the owner of all subdirectories and files in the entire directory to the specified user.
3) Change the file group command: chgrp
This command is also very simple: chgrp group name file name
3.3 User Management
The main task of user management is to establish a legal user account, set and manage user passwords, modify the properties of user account, and delete the abandoned user account if necessary.
1. Add a new user
In Linux system, only the root user can create a new user. The following command will create a new user with login name user1.
# useradd user1
However, this user cannot log in because the initial password has not been set for it, and users without the password cannot log in to the system. By default, a new user home directory with the same user name will be created in the /home directory. If you need to specify the user home directory, you can use the following command:
# useradd -d /home/xf user1
At the same time, when the user logs in, he will get a shell program: /bin/bash. If you don't want this user to log in, you can specify that the user's shell program is: /bin/false. In this way, even if the user logs in, he cannot execute the commands under Linux:
# useradd -s /bin/false user1
In Linux, a new group will be created while adding a new user, which has the same name as the user, and this user is a member of the group. If you want the new user to be part of an existing group, you can use the following command:
# useradd -g user user1
In this way, the user belongs to the user group. And if you just want it to belong to another group, you should use:
# useradd -G user user1
After completing this, you should also use the passwd command to set an initial password for it.
2. Delete a user
To delete a user, just use a simple command "userdel username". However, it is best to delete the files left on the system, and you can use "userdel -r username" to achieve this.
3. Modify user attributes
In the previous example, we saw how to specify the user home directory when creating a new user, how to specify its shell, how to set the group it belongs to... and so on. A command is provided in Linux to implement:
usermod -g group name -G group name -d user home directory -s user shell
There is another direct method, which is to modify the /etc/passwd file. In this file, each user occupies one line, and its content is:
Username: Password: User ID: Group ID: User full name: User home directory: User Shell
However, it is worth noting that the password item is usually replaced by a * number, which you cannot see.
4. Add a group
Remember that Linux files can set different access permissions for people in the same group and people in different groups? We can create user groups according to our needs:
groupadd group name
5. Delete a group
Similarly, we sometimes need to delete a group, and its command is the groupdel group name.
6. Modify group members
If we need to add a user to a group, just edit the /etc/group file and write the user name behind the group name. For example, add the newuser user to the softdevelop group, just find the softdevelop line:
softdevelop:x:506:user1,user2
Then add newuser to form:
softdevelop:x:506:user1,user2,newuser
In addition, Red Hat Linux also provides a graphical user management tool: userconf, through which users can be managed more directly.
3.4 Process Management
Linux is a multi-user and multi-tasking operating system. Multi-user means that multiple users can use the computer system at the same time; multi-tasking means that Linux can perform several tasks at the same time, and it can perform another task before one task has been completed.
Everything that runs on a Linux system can be called a process. Every user task and every system management daemon can be called a process. Linux uses time-sharing management methods to share system resources together using all tasks. Let’s take a look at how to control these processes.
1. Start the process
There are two ways to start a process in Linux system:
1) Enter the command directly and a process will be started directly
ØUnder normal circumstances, the process will be executed in the foreground, and we can no longer execute new commands
Ø If we add a "&" after the command, the process will be executed in the background, and we can still execute the new command
2) Through the at, cron, and crontab commands, a process can be started regularly like scheduled tasks in Windows. For specific usage methods, you can use the man command name to query.
2. View the process
In Linux system, we can use the ps command to view the running process, for example:
List the processes that belong to the current user:
# ps
PID TTY TIME CMD
16767 pts/1 0:00 ps
18029 pts/1 0:00 bash
Where PID represents the process ID, TTY is which console the process was started, and CMD is the command.
If you want to list more detailed information, you can use the command: "ps -auxw".
3. Terminate the process
A process will be completed automatically after the task is completed. If you want to abort the process midway, there are two ways:
1) For programs running in the foreground, the process can be aborted directly by using the key combination CTRL+C;
2) For programs running in the background, you need to find its process number through the ps command introduced earlier, and then use "kill process number" to terminate the process.
3.5 Disk Management
System software and application software must be stored in the computer's disk space in the form of files. As a system administrator, you should monitor the use of the disk space at any time. We can use the following two commands to implement it:
1. df command
df means Disk Free, as the name implies, it is to check how much space is left on the disk and other information. Here is an example of usage:
# df
FileSystem 1k-blocks Used Available Use% Mounted on
/dev/hda5 4134900 1749728 2175124 45% /
/dev/hda6 6048320 5741092 0 100% /home
A total of 6 columns of information are displayed:
1) FileSystem: Hard disk partition
2) 1k-blocks: the partition size calculated by K
3) Used: The partition size that has been used (calculated in K)
4) Available: The partition size you need to use
5) Use%: the percentage of space used
6) Mounted on: Mounted point
You can see that /home is another partition, and now the space is used up! This was not planned at that time!
If the hard disk space is represented in K as the calculation unit, then you can use df -m, which will be calculated in M.
2. du command
du, that is disk usage, that is, to see how much disk is used. Here is an example of usage:
# pwd
/var/log
# du
4 ./uucp
776 .
Here, we use the du command to list the disk space occupied by the /var/log directory. It counts that this directory has a subdirectory: uucp, which occupies 4K, while the files in the /var/log directory have a total of 776K.
This command also has some commonly used options to complete more functions:
Ø -a will list the disk usage of all files, subdirectories, files in subdirectories, subdirectories in subdirectories...
Ø -b Indicates the disk space occupied in bytes
Ø -c Shows a statistic at the end
3.6 Software Installation
Under Red Hat Linux, the application software installation package usually has two formats:
1) rpm package, such as software-1.2.3-1. It is a package format created by Redhat Linux.
2) tar package, such as software-1.2. It is packaged using the UNIX system's packaging tool tar.
Moreover, most Linux application packages have certain rules to naming, which follows:
Name - Version - Revised Version - Type
For example:
sfotware-1.2.3-1.
Software name: software
Version number: 1.2.3
Fixed version: 1
Available platform: i386, suitable for Intel 80x86 platform.
Type: rpm, indicating that it is an rpm package.
According to the contents in the Linux application software installation package, it can be divided into:
1) It is an executable file, which means it can be run directly after unpacking. All packages in Windows are of this type. After installing this program, you can use it. However, when downloading, please pay attention to whether this software is the platform you are using, otherwise it will not be installed normally.
2) Another is the source program, which means that after unpacking, you also need to use a compiler to compile it into an executable file. This is almost non-existent in Windows systems, because the Windows idea is not open source programs.
Usually, those packaged with tar are source programs; while those packaged with rpm are often executable programs.
1. Get the application software packaged using rpm
rpm is a major contribution to Redhat, which makes Linux software installation easier and easier.
1) Installation:
I can finish it in just one simple sentence. implement:
rpm -ivh rpm package name
For more advanced ones, please see the table below:
rpm parameter parameter description
-i Install software
-t Test installation, not really installation
-p Show installation progress
-f No matter what error
-U Upgrade and Installation
-v Check whether the suite is installed correctly
These parameters can be used simultaneously. For more information, please refer to the command help of RPM.
2) Uninstall:
I can finish it in just a simple sentence. implement:
rpm -e software name
However, it should be noted that the software name is used later, not the package name. For example, when installing software-1.2.3-1. this package, you should execute:
rpm -ivh software-1.2.3-1.
And when uninstalling, you should execute:
rpm -e software。
2. Get the application packaged using tar
1) Installation:
The entire installation process can be divided into the following steps:
Ø Obtain application software: obtain by downloading and purchasing CDs;
Ø Unzip the file: Generally, tar packages will be compressed again, such as gzip, bz2, etc., so you need to decompress first. If it is the most common gz format, you can execute: "tar -xvzf package name", and you can complete the decompression and unpacking work in one step. If not, use the decompression software first, then execute "tar -xvf decompressed tar package" to unpack;
Ø Read the included INSTALL files and README files;
Ø Execute the "./configure" command to prepare for compilation;
Ø Execute the "make" command to compile the software;
Ø Perform “make install” to complete the installation;
Ø Execute "make clean" to delete temporary files generated during installation.
OK, that's it. We can run the application. But at this time, some readers will ask, how do I execute it? This is also a Linux-specific issue. In fact, generally speaking, the executable files of Linux application software will be stored in the /usr/local/bin directory! However, this is not the truth that "everyone can be used". The most reliable thing is to look at the INSTALL and README files of this software, which are generally explained.
2) Uninstall:
Usually, software developers rarely consider how to uninstall their own software, and tar only completes the packaging work, so they do not provide a good uninstall method. Generally, make uninstall is provided to uninstall the software.