Linux system (1) - basic knowledge, common commands

       Preparing for the postgraduate entrance examination, after a year of silence, I started again. First, make a plan. First, reorganize the knowledge points of Linux C at a pace of two large blocks a day, and then rationalize the ideas of the online chat room. After finishing the knowledge of C++, combine QT and Mysql with C++. Chat room rewrite. Today, let's review the basic knowledge of Linux, shell commands, vim, gcc, makefile and other common development tools in Linux systems.

1. Basic knowledge of Linux

        Linux is an open system from the very beginning, and it always follows the principle of open source code . It is a mature and stable network operating system. As an embedded operating system, it has the following advantages. 1. Openness 2. Multi-user 3. Multi-tasking 4. Excellent stability and speed performance 5. Rich network performance 6. Reliable system security 7. Portability: Suitable for most computer platforms.

        Linux's graphical interface - the X Window System . The X Window System is just a software (or service) on Linux, it is not part of Linux itself. The X Window System is a rather resource-intensive piece of software that can significantly degrade Linux system performance. If you want to better enjoy the high efficiency and high stability brought by Linux, you should use the command line interface of Linux as much as possible, that is, the Shell environment.

Linux system structure
Linux system structure

Shell is a command line interpreter in Linux. The user enters the command, which is parsed by the shell and then passed to the Linux kernel.

        Linux is just an operating system kernel, which implements the core functions of the operating system: memory management, process management, file system management and device management . User OS, there must be more application support. The Shell is the main application that provides the environment in which other programs are launched and provides a command-line interface to interact with the user. Shell programs commonly used in Linux include sh, bash, csh, etc.

2, files, directories and paths.

        The concept of file on Linux system is relatively broad, it is a common file used to save data, it can represent a device, and it can also be a named pipe used for communication. Those beginning with a period . are system hidden files. Directories can be thought of as special files. Its content is information about other files.

         There can only be one root directory / in a Linux file system, it has no parent directory. All other directories have parent directories. There are two directories under each directory by default, one of them is ., which represents the directory itself; the other name is two or two periods.. represents the parent directory. Both files are hidden files.

        When operating in the shell, there is a concept of the current directory . The current directory is the default operating directory for many commands and is the starting point for relative path lookups. Generally speaking, users have a home directory, which is placed under the root directory home and named after the user's name. The home directory is a directory that the user has full operational rights to. The home directory can usually be represented by ~.

        Linux uses a standard tree structure . Usually a directory is used as the top level (root directory), and other subdirectories are generated from the root directory. Subdirectories under the root directory can be arbitrarily nested.

         A path is used to represent a file and is formally composed of multiple filenames separated by slashes/. All but the last filename must represent a directory. Each file after the slash must exist in the directory before the slash, which forms a step-by-step search process.

       There are two expressions for paths: those that start with a slash are called absolute paths , which are searched from the root directory level by level; those that do not start with a slash are called relative paths , which will search from the current directory.

3. Users and permissions.

        Linux is a multi-user operating system, and multiple users can log in at the same time to operate. Different users have different permissions. The root user has the most privileges, and the privileges of other users have corresponding restrictions.

There is also the concept of user groups         on Linux systems. A group can contain multiple users, and a user can join multiple groups at the same time. In addition to their own permissions, users in the group also have the common permissions of members of the user group. Usually, every time a new user is created, a group with the same name as the user is created at the same time, and the new user is included in the group.

        Each file in the Linux file system has ownership flags , and the system controls user access to the file based on these flags. First, each file records the user it belongs to and the group it belongs to ; secondly, each file has three sets of permission flags, which are for the user, the group and other users to which it belongs . Each set of permissions includes read, write, execute three kind of permissions. If the user has read permission to each file, he can view the contents of the file; if he has write permission, he can modify the contents of the file; if he has execute permission, he can run the program as an executable program.

       For a directory, there are also three permissions. If the user has read permission to a directory, he can view the contents of the directory, that is, the list of files contained in the directory; if he has write permission, he can modify the contents of the directory, that is, create and delete files; if he has execute permission, he can Use this directory as the path to make files in the directory, otherwise operations are not allowed, and this directory cannot be used as the current directory.

       File ownership flags can be viewed with ls -l.

 

2. Shell and common commands

        The interface of the Shell command line is divided into two categories: one is the function implemented by the Shell itself, called built-in commands ; the other is a separate application, after the command is entered, the Shell executes the program, and most Linux commands belong to the latter, called external commands .

        Most shell commands accept command parameters, which are written after the command and separated by spaces. The argument may be a filename, or it may represent a command option. There are two conventions for command options: long form and segment form .

         The long form is represented by two minus signs followed by an English word

          The short form is represented by a minus sign followed by a letter .

man --help == man -h //Display help information for the man command.

2. Command usage skills

(1) Press the Tab key when the input command is not completed , and the Shell will automatically complete it; if there are multiple possibilities, it cannot be automatically completed. Press Tab again to display all possible file names and commands that can be automatically completed.

(2) Press the up and down arrow keys to find commands in the command execution history .

(3) During the command input process (without pressing the Enter key), you can press the Ctrl+C key combination to cancel the input .

(4) The command being executed can be terminated by pressing Ctrl+C key combination .

(5) ctrl+L key combination means clear command terminal screen .

3, Linux common commands

(1) User management commands

(1) useradd sun //Add a user named sun

(2) userdel sun //Delete the user whose username is sun

(3) su sun //Switch to sun user

(4) su //Switch to super user

(5) who //View the login information of the current user

Super user: [root@localhost~]#

Ordinary user: [sun@localhost root]$

(2) File directory commands

(1) ls command

(a) It is used to list the contents of the directory. If the directory name is given, all files and subdirectories in the directory will be listed; if the command gives the file name, the relevant information of the file will be listed; if the directory name or file name is not given, then Displays all files and subdirectories in the current directory. Sort alphabetically .

(b) Common options

-a list include hidden files

-l list details

(c) Format

ls / home             

ls -a / home 

ls -al / home

(2) pwd command

(a) Display the absolute path of the current job

(b) Format

pwd

(3) cd command

(a) Change the working directory

(b) Format

cd [directory name] //Can be an absolute path or a relative path, if omitted, it will enter the user's home directory

(4) mkdir command

(a) Create new file

(b) Format

mkdir file //Create a folder named file

mkdir examp.c //Create a file named exampel.c

(5) cp command

(a) Used to copy files or directories

(b) Format

cp [options] source file or directory destination file or directory

(c) Common options

-i If the target file exists, remind before overwriting

-a preserve links, file attributes, and recursively copy subdirectories

-d keep links when copying

-l don't copy, just create a link

(6) mv command

(a) rename or move a file or directory

(b) Format

mv [options] source file or directory destination file or directory

(c) If the first parameter is the file name and the second parameter is the file name that does not exist in the same directory, mv completes the file renaming; if the second parameter is the existing directory name, the source file is deleted. Move to the target directory. If the first parameter is the directory name, and the second parameter is the file or directory name that does not exist in the same directory, mv completes the renaming of the directory; if the second parameter is the existing directory name, the source directory will be Move to the target directory.

(d) Common options

-i If the target file exists, prompt for overwriting.

(7) rm command

(a) Used to delete files or directories

(b) When deleting a directory, all files and subdirectories under it will be deleted; when deleting a linked file, only the link will be deleted, and the original file will not be deleted.

(c) Common options

-f Ignore nonexistent nonexistent files without prompting.

-r delete all files and subdirectories in the directory

-i give user prompt before deleting files

(8) cat command

(a) Display text file

(b) Format

cat [options] filename

(c) Common options

-n number all output lines

-b blank lines are not numbered

-c merge two blank lines into one

(9) wc command

(a) Count the number of lines, words and bytes in the file.

(b) Format

wc [options] filename

(c) Common options

-c count bytes

-l count lines

-w count word count

(d) word means a string separated by space characters. If no filename is given, it is read from standard input. The command also prints statistics for all files.

(10) chmod command

(a) Used to change the access method of a file or directory

(b) Format:

Letter setting method: chmod [who] [operator] [mode] file name

who: set the object u the owner of the file or directory g the group user of the file or directory, that is, the user with the same GID as the owner -o means other users  -a all users, the default value 

Operators: + add a right - cancel a right = set the specified permission and cancel all other permissions

mode: Access rights  can be a combination of several letters.

r readable w writable x executable u has the same authority as the file owner g has the same authority as the file belongs to the group o has the same authority as other users

           chmod u+x example3.c     

Digital setting mode: chmod [mode] filename

Numeric attributes are in the format of 3 octal numbers from 0 to 7 in the order (u)(g)(o)

0 no permission 1 executable permission 2 write permission 4 read permission
            chmod 775 example3.c 

(11) ln command

(a) Create a link to a file or directory

(b) Format

ln [options] file or directory link name

(c) In the Linux system, links are divided into two categories, hard links and symbolic links . When establishing a hard link, the linking file and the linked file must be in the same file system, and a hard link to a directory cannot be established. For symbolic links, the above problem does not exist.

(d) By default, ln generates a hard link ; if the s option is added to the ln command , a symbolic link is established .
(12) find command

(a) Starting from the specified directory, recursively search each subdirectory under it, find the files that meet the conditions, and perform the specified operation on it. Its general format is:

find start directory find condition operation  

(3) Other orders

(1) kill command

(a) Used to terminate a process.

(b) Format: kill signal name or number process identifier

(c) Commonly used forms

kill -STOP process identifier //Send a SIGSTOP signal to stop a process without destroying the process.

kill -CONT process identifier //Send SIGCONT to restart a stopped process.

kill -9 process identifier //Send the SIGKILL signal to force the process to stop immediately, but not to clean up.

(2) ifconfig command

(a) It is used to view the address and parameters of the configuration network interface, including IP address, network mask, broadcast address, and its use authority is super user .

(b) Format:

ifconfig has two usage formats for finding and changing network interfaces respectively

ifconfig [options] [network interface]: used to view the network configuration of the current system.

ifconfig network interface [options]: used to configure the IP address, netmask, broadcast address, etc. of the specified interface (such as eth0, eth1).

(c) Common parameters

Common parameters of the second format of ifconfig:

-interface specifies the network interface -up activates the specified interface -down closes the specified network interface 

-broadcast set the interface broadcast address -pointopint enable point-to-point mode -netmask set the subnet mask of the interface

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324464916&siteId=291194637