Just changed the title of the article: “Linux Basics for Back-end Programmers” -> “Linux Basics for Front-end & Back-end Programmers”. 😁
This article is updated on my Github: web link
My own summary of Java learning system knowledge points and interview questions, has been open source, will always improve, welcome advice and guidance welcome Star: github.com/Snailclimb/…
Before we learn about Linux, let’s take a quick look at the operating system.
One, start by understanding the operating system
1.1 Operating System Overview
I introduce operating system through the following four points:
- Operation System (OS) is a program that manages the hardware and software resources of a computer. It is the kernel and cornerstone of a computer System.
- Operating systems are essentially software programs that run on a computer;
- To provide users with an interactive operating interface with the system;
- An operating system has an inner core and a shell (we can think of the shell as an application that surrounds the kernel, which is the program that operates the hardware).
1.2 Operating System Classification
- Windows: at present the most popular personal desktop operating system, do not do more introduction, we are clear.
- Unix:The earliest multi-user, multi-task operating system. Time-sharing operating system according to the classification of operating systems. Unix is mostly used on servers, workstations, and now personal computers. It plays a very important role in creating Internet, computer network, or client/server models.
- Linux: Linux is a unix-like operating system that is free to use and freely distributed. There are many different versions of Linux, but they all use the Linux kernel. Linux can be installed on a variety of computer hardware devices, such as phones, tablets, routers, video game consoles, desktop computers, mainframes, and supercomputers. Strictly speaking, the word Linux itself refers only to the Linux kernel, but in fact Linux has been used to describe the entire operating system based on the Linux kernel and using various tools and databases of the GNU project.
Two Linux asain
The 2.1 Linux introduction
We’ve covered Linux above, but let’s just highlight three points here.
- Unix-like systems: Linux is a free, open source UniX-like operating system
- Linux kernel: Strictly speaking, the word Linux itself just means the Linux kernel
- The father of Linux: a legendary figure in programming. He is one of the most famous computer programmers and hackers in the world. He also started the open source project Git and is the lead developer.
2.2 Introduction to the birth of Linux
- In 1991 Linus Torvalds, a Finnish amateur computer enthusiast, wrote a minix-like system (a Unix-like operating system based on a microkernel architecture) named Linux by FTP administrators and added to the Free Software Foundation’s GNU Project;
- Linux uses a cuddly penguin as its logo, symbolizing an aggressive, loving life.
2.3 Classification of Linux
There are two types of Linux, depending on how native it is:
- Kernel version: Linux is not an operating system. Strictly speaking, Linux is just the kernel of an operating system. What is the kernel? The kernel establishes the communication platform between computer software and hardware. The kernel provides system services, such as file management, virtual memory, device I/O, etc.
- Release:A re-release of a kernel version based on secondary development by some organization or company. There are many Linux distributions (ubuntu and CentOS are widely used, so CentOS is recommended for beginners), as shown in the following figure:
Linux File System Overview
3.1 Introduction to the Linux File System
In Linux, all resources managed by the operating system, such as network interface cards, disk drives, printers, I/O devices, common files, or directories, are treated as one file.
That said, there is an important concept in LINUX: everything is a file. In fact, this is a reflection of the UNIX philosophy, and Linux is a rewrite of UNIX, so the concept has been passed on. On UNIX systems, all resources are considered files, including hardware devices. UNIX systems treat each piece of hardware as a file, often called a device file, so that users can access the hardware by reading and writing files.
3.2 File Type and Directory Structure
Linux supports five file types:
The Linux directory structure is as follows:
Linux file systems have distinct hierarchies, like an upside-down tree, with the root directory at the top:
Common Directory description:
- /bin: stores binary executable files (ls,cat,mkdir, etc.). Common commands are stored here.
- /etc: stores system management and configuration files.
- /home: the root directory for storing all user files. It is the base point of the user’s home directory. For example, the home directory of the user is /home/user, which can be expressed as ~user.
- /usr: stores system applications.
- /opt: The location where the optional application package for the additional installation is placed. Normally, we can install Tomcat and so on here;
- /proc: virtual file system directory, which is a mapping of system memory. Access this directory directly for system information;
- /root: the home directory of the superuser (system administrator) (privileged class ^o^);
- /sbin: stores binary executable files accessible only by root. The system commands and programs used by system administrators are stored here. Such as ifconfig, etc.;
- /dev: stores device files.
- / MNT: the installation point for the system administrator to install temporary file systems. The system provides this directory for users to mount other file systems temporarily.
- /boot: stores various files used for system booting.
- /lib: contains library files related to system operation.
- / TMP: stores temporary files. It is the public storage point for temporary files.
- /var: Used to store the files that need to change data during the runtime. It is also the overflow area of some large files, such as the log files of various services (system startup logs, etc.). And so on;
- /lost+found: This directory is usually empty, and the system shuts down abnormally, leaving behind “homeless” files (called.chk under Windows).
Four Basic Linux commands
The following are just some of the more common commands. Recommend a Linux command quick search site, very good, if you forget some commands or do not understand some commands can be solved here.
Man.linuxde.net/
4.1 Directory Switchover Commands
- CD usr: Switch to the usr directory in this directory
- cd .. (or CD.. /) : switches to the directory at the previous level
- CD / : Switch to the system root directory
- CD ~ : Switch to the user home directory
- CD – : switches to the previous directory
4.2 Directory Operation Commands (Add, Delete, Modify, And Query)
-
Mkdir Directory name: Add a directory
-
Ls or ll (ll is short for ls -l, ll command to see details about all directories and files under this directory) : View directory information
-
Find Directory parameter: Find directory (lookup)
Example:
- List all files and folders in the current directory and subdirectories:
find .
- in
/home
Find a file name ending in. TXT:find /home -name "*.txt"
- Same as above, but case is ignored:
find /home -iname "*.txt"
- Find all files ending in. TXT and. PDF in the current directory and subdirectories:
find . \( -name "*.txt" -o -name "*.pdf" \)
orfind . -name "*.txt" -o -name "*.pdf"
- List all files and folders in the current directory and subdirectories:
-
Mv Directory Name New directory name: Change the directory name (change)
Note: the syntax of MV can not only rename directories, but also rename various files, compressed packages, etc. Using the mv command, you can rename a file or directory or move a file from one directory to another. Another use of the mv command will be covered later.
-
Mv directory name New directory location: Move directory location — cut (change)
Note: the MV syntax allows you to cut not only directories but also files and compressed packages. In addition, mv and CP results are different, mv is like the file “move”, the number of files does not increase. Cp copies files, increasing the number of files.
-
Cp -r Directory name Target location for directory copy. -r indicates recursive copy
Note: the cp command can not only copy directories but also files, compressed packages, etc., copy files and compressed packages without writing -r recursion
-
Rm [-rf] Directory: Delete directory
Note: Rm can not only delete directories, but also delete other files or compressed packages. In order to enhance your memory, you can directly use rm -rf directory/file/compressed package to delete any directory or file
4.3 File Operation Commands (Add, Delete, Modify, And Query)
-
Touch file name: create file (add)
-
Cat /more/less/tail View the file name.
- Cat: Displays only the contents of the last screen
- More: The percentage can be displayed. Press Enter can go to the next line, space can go to the next page, and Q can exit the view
- Less: you can use PgUp and PgDn on the keyboard to scroll up and down. Q ends the view
- Tail-10: View the last 10 lines of the file, Ctrl+C ends
Note: Run the tail -f command to dynamically monitor a file. For example, the Tomcat log file changes as the program runs. You can run the tail -f catalina-2016-11-11.log command to monitor the file changes
-
Vim file: Modify the contents of the file (modify)
Vim editor is a powerful component in Linux, is a strengthened version of the VI editor, VIM editor commands and shortcuts have a lot of, but here is not a description, we do not need to study very thoroughly, using VIM to edit and modify the file will basically use it.
In real development, the main function of using vim editor is to modify the configuration file. Here are the general steps:
Vim file — — — — — — — — — — – > > enter the file command mode — — — — — – > press I to enter edit mode — — — — — — — — — — – > edit file > press Esc to enter the bottom line — — — — — > input: wq/q! (Enter wq to write and exit, that is, save; The input q! Indicates forcibly exit without saving.
-
Rm -rf File: Delete file (delete)
Delete the same directory: remember rm -rf file
4.4 Operation commands for Compressing Files
1) Package and compress files:
In Linux, packaging files usually end in.tar, and compression commands usually end in.gz.
In most cases, the file is packaged and compressed together. The file name extension is usually.tar.gz. Command: tar -zcvf Compressed file name Compressed file name:
Z: Use the gzip compression command for compression
C: Package the files
V: Displays the running process
F: Specify the file name
TXT bbb.txt ccC. TXT. If you want to package the test directory and name the compressed package as test.tar.gz, run the following command: TXT bbb.txt ccc. TXT or tar -zcvf test.tar.gz /test/
2) Decompress the package:
Run the tar [-xvf] command to compress the file
X: indicates decompression
Example:
1 Decompress the test.tar.gz file under /test to the current directory and run the tar -xvf test.tar.gz command
2 Decompress the test.tar.gz file under /test to the root directory /usr :tar -xvf xxx.tar.gz -c /usr (-c indicates the specified location for decompressing the file)
4.5 Linux Permission Commands
Each file in the operating system has specific permissions, owning users, and owning groups. Permissions are the mechanism used by the operating system to restrict access to resources. In Linux, permissions are divided into three groups: readable, writable, and ExcuTable. Corresponding to the owner, group, and other users of a file, users and groups can perform operations on a specific file through this mechanism. You can run the ls -l command to view the permissions of files or directories in a directory
Example: ls -l in a random directory
The information in the first column is explained as follows:
The following details the type of file, the permissions in Linux, and the owner, group, and other groups of the file.
Type of file:
- D: indicates a directory
- – : indicates a file
- L: stands for link (think of it as a shortcut in Windows)
In Linux, permissions are classified into the following types:
- R: indicates that the permission is readable. R can also be represented by 4
- W: indicates that the permission is writable. W can also be represented by 2
- X: indicates that the permission is executable. X can also be represented by the number 1
File and directory permissions difference:
Read/write execution means different things to files and directories.
For files:
Permission to name | Executable operation |
---|---|
r | You can use cat to view the contents of the file |
w | You can modify the contents of the file |
x | You can run it as a binary file |
For directories:
Permission to name | Executable operation |
---|---|
r | You can view the table of contents below |
w | You can create and delete files in a directory |
x | You can use the CD to access the directory |
Each user in Linux must belong to a group and cannot be independent of the group. In Linux each file has a concept of owner, group, and other groups.
-
The owner of the
The owner of the file is the person who created the file. The ls ‐ahl command allows you to see the owner of the file. You can also change the owner of the file by using the chown username filename.
-
File Group
When a user creates a file, the group of the file is the group of the user. Using the ls ‐ahl command you can see all groups of the file. You can also modify the group of the file using the CHGRP group name file name.
-
Other groups
All users of the system are other groups of the file except the owner and group of the file
Let’s see how to change file/directory permissions again.
Commands for modifying permissions on files/directories:chmod
For example, modify the permissions of aaa. TXT under /test to ensure that the owner has all permissions, the owner has read and write permissions, and other users have only read permissions
chmod u=rwx,g=rw,o=r aaa.txt
The examples above can also be expressed numerically:
chmod 764 aaa.txt
To add a more common thing:
What if we installed a ZooKeeper and asked it to start automatically every time we started it?
- Create a new script zooKeeper
- Run the following command to add the executable permission to the zookeeper script:
chmod +x zookeeper
- To add the ZooKeeper script to the boot device, run the following command:
chkconfig --add zookeeper
- To see if it was added successfully, the command is:
chkconfig --list
4.6 Linux User Management
Linux is a time-sharing operating system with multiple users and tasks. Any user who wants to use system resources must first apply for an account from the system administrator and then use this account to access the system.
On the one hand, the user account can help the system administrator to track the users using the system and control their access to system resources. On the other hand, it can also help users organize files and provide security protection for users.
Linux user management commands:
Useradd Option user name
: Adds a user accountUserdel Option user name
: Deletes user accountsUsermod Option User name
: Modifying an accountPasswd username
: Changes or creates a user passwordPasswd -s Indicates the user name
: Displays user account and password informationPasswd -d User name
: Clears the user password
The useradd command is used to create a new system user in Linux. Useradd can be used to create user accounts. After the account is created, run the passwd command to set the password. Userdel can be used to delete accounts. The account created using the useradd directive is actually stored in the /etc/passwd text file.
The passwd command is used to set user authentication information, including the user password and password expiration time. The system administrator can use it to manage the password of system users. Only the administrator can specify the user name. Ordinary users can only change their passwords.
4.7 Managing User Groups in Linux
Each user has a user group. The system can manage all users in a user group in a centralized manner. For example, users in Linux belong to a user group with the same name. This user group is created at the same time when users are created.
User group management involves adding, deleting, and modifying user groups. The addition, deletion, and modification of groups are essentially updates to the /etc/group file.
Commands for managing user groups in Linux:
Groupadd Option user group
: Adds a new user groupGroupdel user group
: To delete an existing user groupGroupmod Option User group
: Modifies the attributes of a user group
4.8 Other Common Commands
-
PWD: Displays the current location
-
Grep String to search File to search –color: indicates the search command. –color stands for highlight
-
Ps -ef/ps aux: These two commands are used to view the processes running in the system. The difference between the two commands is that the display formats are different. If you want to view the specific processes can use this format: ps aux | grep redis (view including redis string process)
Note: If you run the ps ((Process Status)) command, the Status of all processes is displayed. You can check the Status of a Process with the grep command.
-
Kill -9 PID of a process: kills the process. (-9 forcibly terminates the process.)
First use PS to find the process and then kill it
-
Network communication command:
- View the information about the network adapter in the current system: ifconfig
- To check the connection to a machine, run ping
- To view the current system port, run the netstat -an command
-
Shutdown: shutdown -h now: Shutdown now Shutdown +5 “System will shutdown after 5 minutes”: the System will shutdown after 5 minutes and send a warning message to the login user.
-
Reboot: reboot: restarts the system. Reboot -w: Perform a simulation of a reboot (recording only does not actually reboot).
If you think my article is helpful to you, welcome to pay attention to my wechat public account :”Java Interview Customs Manual “(a temperature wechat public account, no advertising, simple technology sharing, looking forward to common progress with you ~~~ adhere to the original, share beautiful articles, share a variety of Java learning resources.)