Introduction
Switch between the Linux console and the graphic interface
Familiar with Linux commands
This section describes commands that are frequently used.
File Operation commands
Directory command
File comparison command
Add User and change PASSWORD command
Command for listing file content
Other commands
Switch between the Linux console and the graphic interface
CTRL + ALT + F1 ~ F6
CTRL + ALT + F7
Familiar with Linux commands
1. Use the tab key to complete the command.
2. Make good use of help
File Operation commands
Ls (list) is equivalent to the Dir in DOS
Function Description: lists the contents of a directory.
Note: Execute the LS command to list the contents of the Directory, including the names of files and subdirectories.
Parameters:
-1Only one file or directory name is displayed in each column.
-A or-ALL: all files and directories in the current directory.
-C: sort by time to display files and directories.
-C displays the file and directory names in a straight line from left to right.
-D or-directory displays the directory name rather than its content.
-I or-inode displays inode numbers of files and directories.
-L use the detailed format list. Including permissions, ownership, and size.
-L or-dereference: if a file or directory with the symbolic connection is encountered, the original file or directory pointed to by the connection is directly listed.
-R or-ReverseReverse sorting.
-R or-recursive processing: all files and subdirectories under the specified directory are processed together.
-S or-size displays the size of the file and directory, in blocks.
-Version: displays the version information.
MV
Function Description: Move or rename an existing file or directory.
Syntax: MV [source file or directory] [target file or directory]
Note: You can change the name of a music video file or directory.
Parameters:
-B or-backup if you need to overwrite the file, overwrite the original backup.
-F or-force: if the target file or directory is the same as the existing file or directory, the existing file or directory will be overwritten.
Ask the user before-I or-interactive Overwriting
CP (copy)
Function Description: copy a file or directory.
Syntax: CP [source file or directory] [target file or directory] [target directory]
Note: The CP command is used to copy files or directories. For example, if two or more files or directories are specified at the same time, and the last destination is an existing Directory, then it copies all the previously specified files or directories to this directory. If multiple files or directories are specified at the same time, and the last destination is not an existing Directory, an error message is displayed.
Parameters:
-A or-archive copies the File status, permissions, and other materials as far as possible.
-F or-force forcibly Copies files or directories, regardless of whether the target file or directory already exists.
-I or-interactive ask the user before overwriting existing files.
-L or-LinkEstablish a hard connection to the source file instead of copying the file.
-R recursive processing: processes the files in the specified directory along with subdirectories.
-R or-recursive processing that processes all files in the specified directory along with subdirectories.
-V or-verbose displays the command execution process.
Rm (remove)
Function Description: delete a file or directory.
Syntax: Rm [file or directory...]
Note: Execute the RM command to delete a file or directory. If you want to delete a directory, you must add the "-R" parameter. Otherwise, only the file will be deleted by default.
Parameters:
-F or-force forcibly deletes a file or directory.
-I or-interactive ask the user before deleting an existing file or directory.
-R,-R, or-recursive recursion processes all the files and subdirectories in the specified directory.
-V or-verbose displays the command execution process.
-Version: displays the version information.
Touch
Function Description: changes the file or directory time. It can be used to create an empty file, but when a file or folder exists, touch will assign the current system time to the file or folder.
Syntax: touch [-ACFM] [-D <date and time>] [-r <reference file or directory>] [-T <date and time>] [-- help] [-- version] [file or directory...] or touch [-ACFM] [-- help] [-- version] [Date and time] [file or directory...]
Note: You can use the touch command to change the date and time of a file or directory, including the access time and change time.
Parameters:
-D <time and date> uses the specified date and time instead of the current time.
-R <reference file or directory> sets the date and time of the specified file or directory to the same date as that of the reference file or directory.
-T <date and time> uses the specified date and time instead of the current time.
-Help Online Help.
-Version: displays the version information.
The WC command is used to count the number of bytes, number of words, and number of lines in a specified file, and display the statistical result.
Syntax: WC [Option] File
Note: This command counts the number of bytes, number of words, and number of lines in a given file. If no file name is provided, it is read from the standard input. WC also provides the President count for all specified files. Is the largest string separated by space characters.
The options of this command are as follows:
-C: counts the number of bytes.
-L number of statistics rows.
-W counts the number of words.
File comparison command
Comm command: To compare two ordered files, you can use the comm command.
Syntax: comm [-123] file1 file2
Note: This command compares two sorted files. File1 and file2 are sorted files. Comm reads the two files and generates three output columns: only the rows that appear in file1, only the rows that appear in file2, And the rows that exist in both files. If the file name is "-", it indicates reading from the standard input.
Option 1, 2, or 3 suppress the corresponding column display. For example, comm-12 only shows the rows that exist in both files; Comm-23 only shows the rows that appear in the first file but not in the second file; comm-123 then nothing is displayed.
Diff command: This command compares two text files one by one and lists their differences. It performs more complex checks than comm commands. It performs a system check on the given files and displays all different rows in the two files. It is not required to sort the files in advance.
Syntax: Diff [Option] file1 file2
Note: This Command tells you which lines of file1 and file2 need to be modified to make the two files consistent. If "-" is used to represent file1 or fiie2, it indicates the standard input. If file1 or file2 is a directory, diff compares the files with the same name in the directory.
The meanings of diff options are as follows:
-B ignores the spaces at the end of the line, and one or more space characters in the string are considered equal. For example, how are you and how are you are treated as the same string.
-C uses the context output format (three rows of context are provided ).
-C n uses the context output format (N rows of context are provided ).
-E generates a valid ed script as the output.
-R when file1 and file2 are directories, recursion applies to each file and directory.
Directory command
PWD (print working directory)
Function Description: displays the working directory.
Syntax: Pwd [-- help] [-- version]
Note: When executing the PWD command, you can immediately learn the absolute path name of your current working directory.
CD (Change directory) related to Cd in DOS
Function Description: Switch the directory.
Syntax: CD [target directory]
Note: The CD command allows users to switch between different directories, but the user must have sufficient permissions to access the target directory.
.. Indicates the parent directory
CD to go to the home directory of the user.
CD-Return to the directory just now
Cd ~ Shrek returns to the Shrek directory.
Mkdir (make Directories) is equivalent to MD in DOS
Function Description: create a directory
Syntax:Mkdir[-P] [-- help] [-- version] [-M <Directory attribute>] [directory name]
Note: mkdir allows you to create a directory and set the directory permissions at the same time.
Parameters:
-P or-parents if the upper-level directory of the directory to be created has not yet been created, the upper-level directory will be created together.
Rmdir (remove directory)
Function Description: delete a directory.
Syntax: rmdir [-p] [-- help] [-- ignore-fail-on-non-empty] [-- verbose] [-- version] [directory...]
Note: You can use the rmdir command to delete empty directories.
Parameters:
-P or-Parents: After deleting a specified directory, if the upper-level directory of the directory has become an empty directory, delete it.
-Help Online Help.
-Ignore-fail-on-non-empty ignores non-empty directory error messages.
-Verbose displays the command execution process.
-Version: displays the version information.
Add users and change passwords
Useradd
Function Description: create a user account.
Syntax: useradd [-G <group>] [-G <group>] [-S <shell>]
Note: useradd can be used to create a user account. After the account is created, use passwd to set the password of the account, and use userdel to delete the account. The account created using the useradd command is actually saved in the/etc/passwd text file.
Parameters:
-C <remarks> Add remarks. The remarks are saved in the remarks field of passwd.
-D <logon directory> specifies the start directory for user login.
-D. Change the default value.
-E <validity period> specifies the validity period of the account.
-F <buffer days> specifies the number of days after the password expires.
-G <group> specifies the group to which the user belongs.
-G <group> specifies the additional group to which the user belongs.
-M automatically creates the user's logon directory.
-M: do not automatically create a user's logon directory.
-N cancel creating a group named by the user name.
-R: Create a system account.
-S <shell> specifies the shell used after the user logs on.
-U <uid> specifies the user ID.
Passwd (password)
Function Description: Set the password.
Syntax: passwd [-dkls] [-u <-F>] [user name]
Note: The passwd command allows you to change your password, while the system administrator can use it to manage your password. Only Administrators can specify user names. Generally, users can only change their passwords.
Parameters:
-D. Delete the password. This parameter can only be used by system administrators.
-F.
-K can be updated only when the password expires.
-L lock the password.
-S: list the password information. This parameter can only be used by system administrators.
-U unlocks the locked account.
Command for listing file content
Cat is similar to the type in DOS.
Permission: All Users
Usage: CAT [-abeensttuv] [-- help] [-- version] filename
Note: connect the archive string and upload it to the Basic output (screen or add> filename to another archive)
Parameters:
-N or-number is composed1Start to number all output rows
-B or-number-nonblank is similar to-N, except that the blank row is not numbered.
-S or-squeeze-blank when there are two consecutive blank rows or more, it is replaced by a blank row
-V or-show-nonprinting
More: when the content of a file exceeds one screen, you can use this command to view the file content.
The meaning of each option in the more command is:
-P: Clear the screen before the next screen is displayed.
-C works basically the same as-P.
-D display more friendly prompts at the bottom of each screen:
Based on more, less can be viewed line by line and displayed on pages. Q exit, // or? Can be found.
Head command
If you want to view what a file stores, you can view only the first few lines of the file without having to browse the entire file. Use the head command to display only the first few lines of the file or standard input.
Syntax: head [-N] File
Function: displays the first several rows of a specified file.
Note: This command displays the first n lines of each specified file. If n is not given, the default value is 10. If no file is specified, the head is read from the standard input. For example, the first three rows of the file example. C are displayed.
Tail command: Similarly, if you want to view the end of a file, you can use the tail command.
Syntax: tail [+/-num] [parameter] File
Note: This command displays the specified content of a file. It displays the content within the specified display range of the specified file on the standard output. If no file name is specified, the standard input file is used.
The meanings of the options in the tail command are as follows:
+ Num is displayed after row num.
-Num is displayed starting from the num row at the end of the file. If the num parameter is omitted, the default value is 10.
L count the unit of text behavior num. When used with Parameter options + num or-num options, num indicates the number of lines of text lines to be displayed.
C is measured in bytes as num. When used with Parameter options + num or-num options, num indicates the number of characters to be displayed.
Other commands
Alias
Function Description: sets the alias of an instruction.
Syntax: alias [alias] = [command name]
Note: You can use alias to customize the alias of the command. If you only enter alias, all current alias settings can be listed. Alias is valid only for this login operation. If you want to automatically set the alias for each login, you can set it in shell.
Parameter: If no parameter is added, all alias settings are listed.
Ln (Link)
Function Description: connect to a file or directory.
Syntax: ln [source file or directory...] [destination Directory]
Note: ln commands are used to connect files or directories. For example, if two or more files or directories are specified at the same time, and the last destination is an existing Directory, all the previously specified files or directories will be copied to this directory. If multiple files or directories are specified at the same time and the destination is not an existing Directory, an error message is displayed.
parameter quantity:
-B or-backup is deleted to overwrite the backup before the target file.
-D,-F, or-directory creates a directory hard connection.
-f or-force forcibly establishes a connection to a file or directory, regardless of whether the file or directory exists.
ask the user before-I or-interactive overwrites existing files.
-N or- NO -dereference treats the target directory of the symbolic connection as a common file.
-S or-symbolic establishes a symbolic connection to the source file instead of a hard connection.
-S
or-suffix =
after backing up the target file with the "-B" parameter, A backup string is added at the end of the backup file. The default backup string at the end is the symbol "~", You can change it through the "-s" parameter.
-V or-verbose displays the command execution process.
-v
or-version-control =
use the "-B" parameter to back up the target file, A backup string is added at the end of the backup file. This string is not only changed with the "-s" parameter. When the "-V" parameter
is used to specify different backup modes, it will also generate backup strings with different characters at the end.
-help online help.
-version: displays the version information.