RHEL8 system installation notes
Shutdown and restart commands
Only the administrator can perform shutdown and restart
1. Shutdown command
shutdown //Shutdown
shutdown -h now //Shut down immediately
shutdown -h 60 //Shut down after 60 minutes
2. Restart command
reboot //Restart the system
shutdown -r now //restart immediately
shutdown -r 20 //Restart the system in 20 minutes
Note: shutdown -c //Cancel shutdown or restart
Path representation method under Linux
1. Absolute path
A. It must start with "/" (root), it is the only way to absolutely describe the path where the file is located.
B. The "/" root directory is the top-level directory of the Linux operating system, and no path is higher than it.
2. Relative path
A. The path is relative, the path where the file is located is relative to the current path.
B. The current path uses. Or ./ to indicate; the upper directory of the current directory uses ... or …/ to indicate
C. The current user's home directory uses ~ to indicate; the last working path uses-to indicate
3. Related commands for path switching and viewing
pwd //View the current working path
cd //Change the working path, switch the path (switch to the current user's home directory by default)
for example:
[root@zjs64 ~]# pwd //Print current working path
/root
[root@zjs64 ~]# cd /home //Switch to the /home directory
[root@zjs64 home]# cd …/ //Switch to the upper directory of the current path
[root@zjs64 /]# pwd
/
[root@zjs64 /]# cd ~ //Switch to the current user's home directory
[root@zjs64 ~]# cd-//Switch to the last working path
/
[root@zjs64 /]# cd //Switch to the current user's home directory
[root@zjs64 ~]# pwd
/root
RHEL8 file operation management
Under Linux, everything is a file!
Note: 1. All the following commands need to be executed on a carrier, which is called a terminal.
2. All commands on the terminal need to be translated and analyzed before the computer can understand and execute them. This translation and analysis thing is called SHELL interpreter, RedHat and Centos default shell interpreter is called bash.
3. Since you need bash to help translate and explain related commands, the command you type must conform to its syntax, otherwise an error will be reported.
Command [optional] parameters
[root@localhost ~]# ls -l
/root
Command: The main body of the entire shell command
Options: Affect or fine-tune the behavior of the command, usually implemented with -, -
Parameters: the object of the command
1. Common file types
A. Common file types
d: Directory file: equivalent to a folder under Windows.
l: Link file: similar to shortcuts under Windows.
b: Block device files: all storage devices, such as disks, CDs, U disks, CD-ROMs, etc.
c: Character device file: all input and output devices, such as keyboard, mouse, printer, etc.
p: Pipe file: simply understood as a way of communication between programs or processes.
-: Indicates ordinary files: similar to Notepad, Word, etc. under Windows, you can use related commands to edit and view file contents.
B. The meaning of different colors of directory files
Use the file command to determine the file type
[root@localhost ~]# file /root
/root: directory directory
[root@localhost ~]# file /root/install.log
/root/install.log: ASCII text ordinary text file
[root@localhost ~]# file /dev/sda
/dev/sda: block special block device file, store data
[root@localhost ~]# file /dev/tty1
/dev/tty1: character special character device
[root@localhost ~]# file /bin/sh
/bin/sh: symbolic link to bash soft link file
2.
ls-List the contents of the directory
Common options:
-a all, view all files in the directory, including hidden files
-l long list display
-h human, displayed in a humane way
-d lists only the directory name, not other content
-t sort by modification time
-r sort in reverse order -S sort by file size
-i displays the inode number (index number) of the file
-R recursively list the contents of the directory
-m display content separated by commas
3.
mkdir-create a directory
Common options
-p cascade creation
[root@localhost~]# mkdir /test/ //Create a test directory under the root
[root@localhost~]# mkdir ./test/ //Create a test directory in the current directory
[root@localhost~]# mkdir -p /test/yunwei/redhat
Note: If the upper-level directory of the created directory does not exist, you need to add the -p parameter; -p can be in the front or back.
4.
touch-create file
Note: File naming rules under Linux
1. The file name is strictly case sensitive file FILE
2. The file name cannot contain special symbols, such as (/or *, etc.)
3. The file name can be up to 255 characters
A. Create a new empty file (the target file does not exist)
Prepare the environment, delete all files in the /tmp/ directory
[root@localhost ~]# rm –rf /tmp/*
[root@localhost ~]# touch /tmp/file1 //Create file1 file in /tmp directory
[root@localhost ~]# touch file1 //Create file1 file in the current directory
Note: Although the above two file1 files have the same name, they are not the same file because the paths are different.
B. File modification time (the target file exists)
a.
View the relevant time of the file
[root@localhost tmp]# stat /tmp/file1 //View the status information of the
file Access: View the access time of the file
Modify: File modification time
Change: When the file attribute time, file size, permissions and other information change, the time will change
b. Time to modify the file
[root@localhost tmp]# touch -a file1 -t 201506161320 modify file access time
[root@localhost tmp]# touch -m file1 -t 201612121330 Modify file modification time
-a: access time
-m: modification time
-t: time type format
[root@localhost tmp]# touch -d 20110808 file1 modify the file date
[root@localhost tmp]# touch -d 1215 file1 modify file time
[root@localhost tmp]# touch -d “20101012 11:11:11” file1 modify the date and time of the file
Note: You only need to master the usage of touch -d.
Note: RHEL6 starts relatime, and atime delay modification, one of the conditions must be met:
-
Since the last modification of atime, it has reached 86400 seconds;
-
When a write operation occurs;
5. View file content
cat command: generally view small files, listed from the first line to the last line
Common options:
-n: display line number
-A: Display control characters, such as line breaks, tabs, etc. (linux $ and Windows ^M$)
tac command: generally view small files, listed from the last line to the first line
More and less commands: generally view large files, q exit to view, you can search, suggest less command
head command: view the first 10 lines of the file by default, head -n 15 or head -15 means view the first 15 lines
tail command: view the last 10 lines of the file by default, tail -n 15 or tail -15 means view the last 15 lines; -f means dynamic view
ldd command: generally used to view binary command files
[root@localhost tmp]# cat /etc/passwd View the contents of the /etc/passwd file
[root@localhost tmp]# cat -n /etc/passwd View the contents of the /etc/passwd file and print the line number
[root@localhost tmp]# tac /etc/passwd View the contents of the /etc/passwd file
[root@localhost tmp]# head -5 /etc/passwd View the first 5 lines of the /etc/passwd file
[root@localhost tmp]# tail -5 /etc/passwd View the last 5 lines of the /etc/passwd file
[root@localhost tmp]# more /var/log/messages
[root@localhost tmp]# less /var/log/messages
[root@localhost tmp]# ldd /bin/mkdir View the contents of the mkdir command file (binary)
6, cp-copy files
Note: local file copy
Common options:
-a Recursively copy files, including directory and file attribute information
-r copy directories recursively
-p file attribute information copy
-v display copy process information
usage:
Where to copy the files to be copied with the cp option
for example:
#cp /root/file1 /home Copy the file1 file under /root/ to the /home directory
#cp -r /home/itcast /root Copy the /home/itcast directory to the /root directory
#su-user01 switch to user01
$ touch file1
#cp -p /home/user01/file1 /tmp/ copy home/user01/file1 file (including attribute information) to /tmp
#cp /root/file1 /tmp/test1 copy file and rename
Note:
Both -a and -p need to copy file attribute information
-p can only copy files
-a can copy files and directories
7.
mv-move or rename files
Mobile file usage (under different paths):
#mv The file to be moved is moved to a new path.
Note: The path of the file is different
Rename usage (under the same path):
#mv The name of the original file The name of the new file
Note: The path of the old file and the new file are the same
#mv /root/file1 /tmp //Move the /root/file1 file to the /tmp directory
#mv /tmp/file1 /tmp/test1 //Rename the file1 file in the /tmp directory to test1
8.
rm-delete files
Common options
-r delete recursively, generally used to delete directories
-f delete directly without prompting
[root@localhost tmp]# rm file1 delete the file1 file in the current directory, there is a prompt [root@localhost tmp]# rm -r dir1 delete the dir1 directory in the current directory, there is a prompt
[root@localhost tmp]# rm -f /root/file1 Force delete /root/file1 file, delete directly without prompt
Expand
(1) How to get help under Linux
1. help-simple help
help command: know the meaning of the command, and you can use help if you don’t know the relevant parameters
Internal command for help: help command
External command for help: command --help
cp --help
help cd
2.
man-detailed help
#man man
ANUAL SECTIONS
The standard sections of the manual include:
1 User Commands Commands used by all users
2 System Calls
3 C Library Functions
4 Devices and Special Files
5 File Formats and Conventions
6 Games et. Al . Game
7 Miscellanea Miscellaneous
8 System Administration tools and Deamons system administrator and program user related
Generally, it is not necessary to use chapter numbers, for example:
#man 1 ls
#man ls
#man useradd
#man setfacl (/EXAMPLES)
#man -f passwd List passwd manuals in all chapters
#man 1 passwd passwd command help
#man 5 passwd user profile help
#man -a passwd find in all chapters
#man -k passwd Export man page with keywords
Programmer's Manual man 23467
Administrator manual man 158
(2) Standard input and output of Bash
1、名词解释
Standard input (stdin): input file descriptor on the keyboard—>0
Standard output (stdout): the correct output file descriptor on the screen—>1
Standard error (stderr): Wrong output file descriptor on the screen—>2
2. Related symbols
: Standard output redirection, override redirection, 1> or> standard output redirection, 2> standard error redirection
: Redirection append, 1>> standard output append, 2>> standard error append
<: Standard input
&>: Standard output and standard error redirection
3. Illustrate with examples
① Environmental preparation
Write a simple script (copy it directly first, say it later):
[root@localhost ~]# echo -e'date\nuuu'> 1.sh Create 1.sh script file
[root@localhost ~]# cat 1.sh
date
uuu
executes the 1.sh script, and the output on the screen is as follows:
[root@localhost ~]# bash 1.sh
Sat Apr 18 14:00:09 EDT 2020 The correct result is called standard output
1.sh: line 2: uuu: command not found The wrong result is called standard error
② Demand 1:
Redirect standard output (the correct result on the screen) to the /tmp/1.log file
[root@localhost ~]# bash 1.sh > /tmp/1.log
1.sh: line 2: uuu: command not found The standard error (error result) is still on the screen, and the correct result is in the file
[root@localhost ~]# cat /tmp/1.log file is the result of standard output
Sat Apr 18
14:05:27 EDT 2020
③ Demand 2:
[root@localhost ~]# bash 1.sh 2>
/tmp/2.log
Sat Apr 18 14:06:06 EDT 2020 standard output is still on the screen, standard error is redirected to the file
[root@localhost ~]# cat /tmp/2.log
1.sh: line 2: uuu: command not found The file is the result of standard error
Note:> or 2> both indicate override redirection
View the contents of the /etc/hosts file and redirect standard output to /tmp/1.log
[root@localhost ~]# cat /etc/hosts >
/tmp/1.log
[root@localhost ~]# cat /tmp/1.log View the file and find that the original content is overwritten 127.0.0.1 localhost localhost.localdomain localhost4
localhost4.localdomain4
::1 localhost
localhost.localdomain localhost6 localhost6.localdomain6
Summary:> or 1> means standard output redirection; 2> means standard error redirection
④ Demand 3:
Redirect standard output and standard error to /tmp/3.log together
[root@localhost ~]# bash 1.sh
&>/tmp/3.log
[root@localhost ~]# cat /tmp/3.log
Sat Apr 18 14:06:36 EDT 2020
- sh: line 2: uuu: command not found
Note:
&> means that standard output and standard error are redirected together
4. The echo command
Echo will send the input string to standard output with a newline character at the end. Can be understood as a print string.
Common options:
-n: Do not output the final newline character "\n"
-e: Interpret escape characters (special characters such as \n, \t, etc. appear in the string, they will be treated specially, and they will not be output as normal text)
for example:
[root@localhost~]# echo hello world 打印hello world
hello world
[root@localhost~]# echo aaaa 打印aaaa
aaaa
[root@localhost~]# echo hello> file1 redirect hello to file1
[root@localhost~]# cat file1
Hello
to sum up:
-
Echo means to print a string, the string is sent to standard output by default; a newline character is printed by default
-
Echo can be used in conjunction with the> or >> symbol to create files or append content.
Common control characters:
\t means tab
\n means newline
[root@localhost~]# echo -e'date\nuuu'> 1.sh //-e means to interpret \n as a newline
[root@localhost~]# cat 1.sh
date
uuu
To be continued...
To be continued...