“This is the third day of my participation in the November Gwen Challenge. See details of the event: The last Gwen Challenge 2021”.
👨🎓 author: Java Academic Conference
🏦 Storage: Github, Gitee
✏️ blogs: CSDN, Nuggets, InfoQ, Cloud + Community
💌 public account: Java Academic Party
🚫 special statement: the original is not easy, shall not be reproduced or copied without authorization, if you need to reproduce can contact xiaobian authorization.
🙏 Copyright notice: part of the text or pictures in the article come from the Internet and Baidu Encyclopedia, if there is infringement, please contact xiaobian as soon as possible. Wechat search public Java academic party contact xiaobian.
☠️ Daily toxic chicken Soup: Nothing to say, read the article.
👋 Hello! I’m your old friend Java Academic Party. When we play Windows is very skilled, so xiaobian today to take you to make a Linux system, xiaobian with a week to give you the whole of some Linux dry goods, because the content is too much, xiaobian sub development. Without further ado, let’s jump right into today’s topic: Linux. Linux, full name GNU/Linux, is a free to use and freely distributed Unix-like operating system. Its kernel was first released by Linus Benadicte Torvalds on October 5, 1991. It is mainly inspired by the ideas of Minix and UNIX. POSIX is a multiuser, multitask, multithreaded and multi-CPU operating system based on POSIX. It can run major Unix tools, applications, and network protocols. It supports both 32-bit and 64-bit hardware. Linux inherits the design idea of Unix taking network as the core, and is a stable multi-user network operating system. There are hundreds of different distributions of Linux, such as community-based debian and ArchLinux, and commercially based Red Hat Enterprise Linux, SUSE, Oracle Linux, and more.
8.Linux User Profiles
8.1 Introduction to Users in Linux
- Linux is a multi-user and multi-task operating system. Any user who wants to use system resources must apply for an account from the system administrator and use the account to access the system.
- The root user is the default administrator account. The root user can create multiple common users and assign them to common employees of the company. Common employees then use this account to access the company server.
- The root account is a super administrator system generated by Linux by default. Ordinary users can also create new ordinary users as long as the root administrator gives them permissions, but most of them use the root class to create new ordinary accounts.
- Windows can be used only with an account, but Linux can be used only with a valid account and password.
8.2 Adding a User
- Useradd User name: Creates a new user account.
Note: When creating an account using this command, the account that created the account must have the permission to create an account (usually the root account to create a new user).
Liunx does several things for us when using this create command:
- Create a user.
- Create a root directory for this user in the /home directory. The directory name is the same as the user name by default. (Can be modified)
- In Linux, every user belongs to at least one group. If you do not specify a group when creating a user, the system creates a group with the same name as the user name and adds the user to the group.
Setting the user name
- Syntax: useradd [option] User name
- Useradd Zhangsan: Creates an account named zhangsan. In this case, an account is created, a group named Zhangsan is created and assigned to this group, and a directory named Zhangsan is created under /home as the root directory of the newly created user.
- Useradd -d /home/ls lisi: create an account named lisi and specify a directory named lisi under home folder named ls.
Set the password
Syntax format: passwd User name: Sets the password for the specified user.
- Note: if the password is set too simple, it will cause you to re-enter a complex password, and the password is not visible when entering, is hidden input.
8.3 Deleting a User
Syntax: userdel[option] User name
- Userdel Zhangsan: Deletes user Zhangsan and reserves the home directory of Zhangsan.
- Userdel -r lisi: Delete user lisi and delete the lisi home directory (cascade delete, often used).
8.4 Viewing Users
Syntax format: ID User name
- Id Zhangsan: View information about user Zhangsan. Query information about user groups.
8.5 Switching Users
Syntax: su user name
- Su Zhangsan: Switch to user Zhangsan. You do not need to provide a password.
- Su root: Switch to user root. The password is required.
Note: When switching from a user with high permission to a user with low permission, you do not need to enter a password. Otherwise, enter the password.
Important: The exit command returns to the original user and does not require a password to switch back to root.
9. Perform basic operations for the Linux group
- Linux groups are similar to roles. The system can centrally manage multiple users with common features. Each user belongs to at least one group and can exist in multiple groups. If you do not specify a group when creating a user, the system creates a group with the same user name by default and assigns the newly created user to the group. By default, the root user belongs to the root group.
9.1 add the group
- Syntax: groupadd Group name
Groupadd devgroup: Creates a devgroup.
9.2 delete the group
- Syntax format: groupdel Group name
Groupdel devgroup: deletes a devgroup.
9.3 Specifying Groups when Adding Users (Common)
- Syntax: useradd -g group name User name
Useradd -g devgroup zhangsan: Add user Zhangsan and specify that Zhangsan belongs to devgroup.
9.4 Adding a User to a Specified Group
- Syntax format: gpasswd -a User name Group name
gpasswd -a zhangsan dev
Note:
- You can use the view user command to view the group to which the user belongs.
- Adding a user to a specified group does not remove the user from the previous group and add it to the newly specified group. Instead, a copy of the object from the previous group is added to the specified group, where the user exists in both groups.
9.5 Removing a User from a Group
- Syntax format: gpasswd -d User name Group name
gpasswd -d zhangsan dev
- A GID is called a primary group. Users cannot move out of the primary group. Groups are called attach groups, and users can be removed from attach groups.
10.Linux help commands
- View the built-in help information for all commands: help command
- View the help information specified in the Linux system manual: man command (man cannot be used)
Note: Press Enter to display the help information line by line, press space to display the help information page by page, and press Q to exit the help.
11. Linux directory operation commands
11.1 Viewing A Directory
View a list of subdirectories and files in a directory
- View the current directory: PWD. This one starts at the root.
- To view a list of all subdirectories or files in a specified directory: ls [specified directory]
- View the list of subdirectories or files under the current directory: ls
Displays a list of subdirectories and files in the specified format
- Ls Specifies the directory: use the default display mode (equivalent to the Windos mode, where hidden files are not shown)
- Ls -l Specifies a directory. The directory is displayed in a list. (Equivalent to a list in Windows)
- Ls -a Specify directory: Displays subdirectories and file lists (including hidden files) under the specified directory.
Note: the above command can be written as ls -a(ls -l), etc. View the subdirectories and file list under the current directory.
View your list of parameters that can be superimposed
- Ls -al Specified directory: Displays subdirectories and files (including hidden files) under a specified directory in a list.
11.2 Changing a Directory
- Syntax: CD [parameter]
- Switch to a specified directory
Parameter information:
- Absolute directory: The path starts from the root path (/). (You can jump to the specified folder from any location in one step)
- Relative directory: The path starts from the current directory. (Step by step jump to the specified folder)
A few special CD commands:
- CD ~ or CD: go to your home directory. This is an absolute directory. (Common user in the home directory, root user in the root directory)
- cd .. Returns the directory one level above the current directory. This is a relative directory.
- CD. Return to the current directory
11.2 Creating a Directory
Creating a Level-1 Directory
- Absolute directory: mkdir /opt/testDir/test: create the test directory in opt/testDir.
- Relative directory: mkdir test: creates the test directory under this directory.
Note: only account root has permission to create a directory. This parameter cannot be created for a common user.
Creating a Multi-level directory
- Absolute directory: mkdir -p /opt/testDir/test3/tes4: Create test3 and then test4 in opt/testDir. Multistage create
- Relative directory: mkdir -p test3/test4: Create test3 and then test4 in the current directory. Multistage create
11.3 Deleting a Directory
Rmdir directory: Delete an empty directory
Syntax: rm [option] : file or directory to be deleted
Rm -r: Deletes the entire folder recursively
Rm -f: Forcibly deletes data without prompting
12. Linux file operation commands
12.1 Creating a File
- Vi /vim: You can create a file in the specified directory. But creating a file with this command will be opened by default using the editor. And vi and Vim can only create one file at a time.
- Touch Filenames list (filenames separated by Spaces) : This command creates one or more files.
- TXT t2. TXT: Creates multiple files in the current directory.
12.2 Viewing the Contents of a File
View all file contents
Cat [option] File name to view (absolute/relative)
Cat-n The name of the file to view: This will display the travel number.
Note: Files are only displayed as read-only files.
View the contents of the file with the number of lines specified at the beginning
Head file name: The first 10 lines of a file are displayed by default.
Head -n 5 File name: View the first 5 lines of the file. 5 can be any number.
Note: On Linux, all file names can be displayed using either absolute or relative paths.
View the contents of the file ending with the specified number of lines
Tail file name: View the last 10 lines of the file by default.
Tail -n 5 File name: View the content in the last five lines of the file. The value of 5 can be any.
12.3 Output variables or constants to the console
Echo [options] [output content] : Outputs variable or constant content to the console
- Echo $PATH: Outputs the PATH to the console, where PATH needs to be capitalized.
- echo Hello world! : You can print Hello World on the console
Print the result of the previous view command to the specified file (if the file does not exist, the system will automatically create one for us). And the file is created in the same directory as the command) : see command > file name
- ls > ret.txt
Note:
- The input to this file is not a directory, but the name of the corresponding file or subdirectory under this directory.
- When the folder exists, executing the command again will overwrite the previous contents of the file.
Copy of file contents:
- Cat ret.txt > ret_new. TXT: Copies the contents of the source file to a new file without changing the contents of the source file.
Note: both new and copied files overwrite the contents of previous files.
13.Linux system operations
- Shutdown now: Power off immediately
- Shutdown -h 1: Power off after 1 hour
- Shutdown -r now: Restart the computer now
- Reboot: Restart the computer now
- Sync: Synchronizes memory data to disks.
14. Date and time instructions in Linux
View or set the system date or time: date
- Date: Displays the complete date and time of the system.
- Date +%Y: indicates the current system year.
- Date +%m: indicates the current system month.
- Date +5d: indicates the current system date.
- Date ‘+%Y-% M- % D %H:%M:%S’ : The current system time is displayed in yyyY-MM-DD HH: MM :ss format.
View the calendar in Linux
- CAL: Displays the system calendar of the current month.
- CAL 2020: Displays calendar information for all months of the specified year.
15. Find a file or directory in Linux
Find [search scope] [search criteria] keyword
Search criteria:
- Name: Search by name by default. The name can be omitted or searched by name.
- Size: Search by file size.
- User: Search by file owner. By default, whoever created the file is the owner of the file. It can be changed later)
15.1 Searching for Files or Directories By Name
- Find *. TXT (relative path): searches the current directory. All of the.txt files.
- Find * e * (relative path) : Searches for all files and directories in the current directory whose name contains e.
- Find /etc/* / TXT: searches for all. TXT files in the /etc/directory.
15.2 Search by File Size
In Linux, the + sign means greater than and the – sign means less than.
- Find /etc/size-5k (5M) : searches for all files smaller than 5K /5M in the /etc/directory.
- Find /etc/size +5k(5M) : searches for all files larger than 5K /5M in the /etc/directory.
15.3 Search by file owner
- Find /etc/user zhangsan: searches for files and directories in /etc/directory whose owner is zhangsan.
Today first share here, tomorrow continue to share with you Linux system about file management, like big guys, attention not lost yo
Above project source code,Click planet to get it for freeplanet(making address)If I didn’t have my Github buddies. You can follow my wechat official account:Java academic lie prone, send Linux, free to everyone project source code, the code is personally tested by small make up, absolutely reliable. It’s free to use.