After reading this Linux basic operation will be

Source: Internet
Author: User
Tags aliases echo command parent directory

Objective

Only a bald head can become stronger.

This article mainly summarizes the basic operation of Linux and some simple concepts ~ If the unfamiliar classmate can play the next Linux (or to buy a server to play "student version is not very expensive"), for developers, can use Linux to do some basic operation is necessary!

So let's get started, of course, my linux is just the entry level , if the wrong place also need to ask you to forgive, and in the comment area to point out the error ~

First, why we want to learn Linux

Believe that most of the people 's PC end is the use of Windows system, then why should we learn Linux this operating system??? The Windows graphical interface is doing so well, and the cost of learning is almost zero on a daily basis.

Linux is not the same, may be just contact with Linux people will think: Linux is good trouble Oh, not fun, are the character interface. Not intuitive, this broken system is used to do it ~ ~

Windows is handy for everyday use, but what we need to know is that the programs we develop are generally run under Linux .

There might be a question: Windows is the same operating system, Why put it under Linux and not under Windows ?? We believe that Windows can also run the programs we write.

I've summed up some of the benefits of Linux:

    1. Free
    2. Many of the native software is run under Linux, large community support, good ecological environment .
    3. Open source , can be customized, open, Multi-user network operating system .
    4. Relatively safe and stable

So the developers chose Linux to run the program we wrote ourselves.

Second, the basic knowledge of Linux

the composition of the Linux system :

    1. Linux kernel (Linus team management)
    2. Shell: interface for user-to-kernel interaction
    3. file system : Ext3, Ext4 and so on. Windows has FAT32, NTFS
    4. Third-party application software
Basic knowledge of 2.1Shell

In addition to the shell, the other should be very understood, then what is the shell ???

The shell is the user interface of the system and provides an interface for user interaction with the kernel (command interpreter)

The shell can execute:

    • Internal command
    • Application
    • Shell Script

Use type commands to differentiate between internal and external commands

So we can use the shell to do the following:

    • Command-line explanation (this is the most used!) )
    • Multiple order of execution for commands
    • wildcard character (Wild-card characters)
    • command completion, alias mechanism, command history
    • I/O redirection (input/output redirection)
    • Pipe (pipes)
    • Command substitution ( or $ ())
    • Shell programming language (Shell Script)

The main version of the shell has the following so many:

    • What we use (the default) is bash(Bourne again Shell)

Using ps commands to observe a shell being executed

2.2Linux BASIC directory structure

Under Windows, there will be a basic directory structure :

Linux is no exception, there is a basic directory structure:

Linux file system is a directory tree structure , the file system structure from a root directory, the root can have any number of files and subdirectories, subdirectories can have any number of files and subdirectories

    • Bin holds binary executables (ls,cat,mkdir, etc.)
    • Boot holds various files used for system boot
    • Dev for storing device files
    • ETC Storage System configuration file
    • Home Store The root directory of all user files
    • Lib holds shared libraries and kernel modules needed to run programs in the file system
    • MNT system administrator installs the temporary file system installation point
    • Placement of optional application packages that opt for additional installation
    • Proc Virtual file system, storing the current memory mapping
    • Root Super User Directory
    • Sbin store binary executable files, only root to access
    • TMP is used to store various temporary files
    • USR for storing system applications, more important directories/usr/local local Administrator software installation directory
    • var is used to store files that need to change data at run time
2.3 Command Basic format

cmd [options] [arguments], Options is called an option, arguments is called a parameter

Both options and parameters are entered as shell commands when they are executed, separated by a space .

    • Linux is case-sensitive

In General , the following option is used before the single - character option 减号- . Use two before Word options减号--

    • This is the general situation, some orders still do not belong to this rule (relatively few) ~ ~ ~
    • Example: ls -a and ls -all , a single character using one - , one word all using two--

In Linux, executable files are also categorized:

    • built-in commands : For efficiency reasons, the interpreter of some common commands is constructed inside the shell .
    • external command : commands stored in the/bin,/sbin directory
    • Utilities : Utilities stored in directories such as/usr/bin,/usr/sbin,/usr/share,/usr/local/bin, etc.
    • User program : After compiling the executable file, the user program can be run as a shell command
    • Shell script : A batch file written by the shell language that can be run as a shell command
2.4 Wildcard characters

Learn some regular expressions or a bit of basic students on the wildcard should be not unfamiliar with the Linux also have wildcards (useful when searching)

    • *: matches any character and any number of characters
    • ?: matches any single number of characters
    • []: Matches any one of the characters within []
    • [! ] : match except [!] Any character other than the one that says no.
2.5 Types of files

There are so many types of files under Linux:

    • Normal file-
    • Directoryd
    • Symbolic Linksl
      • Hard link: No different from normal files, Inode points to the same file on the hard disk block
      • Soft Links: Save the absolute path of the file it represents, is another file that has separate chunks on the hard disk, and replaces its own path when accessed (simply understood as a common shortcut in Windows).
    • Character device filesc
    • Block device filesb
    • Socketss
    • Named pipesp

Common Files, directories, and symbolic links. Other understanding of the can ~

2.5.1 User Home Directory

May be in the online access to the information will appear in the user's home directory such a noun, then what is he???

As already mentioned, our Linux is a multi-user network system ! Therefore, we can create multiple users under Linux, each user will have their own dedicated space .

    • Therefore, when creating a user, the system administrator creates a home directory for each user , usually in the /home/ directory
    • For example: User Osmond's home directory is:/home/osmond

Users have ownership of the files in their home directories and can do so in their own home directory.

Iii. Common Commands

It said a bunch of basic concepts, this is to give us a bit of the foundation before hitting the command, while knocking at the command will also encounter some of the more important points of knowledge. Then say it again ~ ~ ~

3.1 Common file, directory operation commands

This is the command we use most, Linux is themost basic command !

    • Available pwd commands to view the user's current directory
    • Use cd commands to switch directories
    • .Represents the current directory
    • ..Represents the top-level directory of the current directory (parent directory)
    • -Represents the directory in which the CD command was used before switching directories
    • ~Represents the absolute path name of the user's home directory

Absolute path:

    • Start with a slash (/) that describes the full description of the file location, which you can use whenever you want to specify a file name.

Relative path:

    • Do not start with a slash (/), specifying a location relative to your current working directory , which can be used as a simple way to specify a file name

Tips: Use the TAB key when entering commands to complete

    • ls: Display file or directory information
    • mkdir: Create an empty directory under the current directory
    • rmdir: Required Directory is empty
    • touch: Generate an empty file or change the time of the file
    • cp: Copying Files or directories
    • mv: Move a file or directory, file, or directory rename
    • rm: Delete a file or directory
    • ln: Create a linked file
    • find: Finding Files
    • file/stat: View file type or file attribute information
    • cat:View Text file contents
    • more:Can be paged to see
    • less:Not only can be paged, but also easy to search, rollover and other operations
    • tail -10: View 10 lines at the end of a file
    • head -20: View the header of the file 20 lines
    • echo: Redirects the content to the specified file, opens it, and creates it without
    • 管道命令 |: Give the previous result to the following command, for example: ls -la | wc , the result of LS to refuel the WC command to count the number of words
    • 重定向 > 是覆盖模式,>> 是追加模式, for example: Put the echo "Java3y,zhen de hen xihuan ni" > qingshu.txt left output in the file on the right.

What are we capable of learning these orders? in fact, it is in Windows to copy files, paste files, create files, view files of the several ~ ~ ~

3.1.1 Frequently used files and directories operation exercises

Consolidate the basics, to do the topic:

    • (1) The Linux shell program is the default bash program ;
    • (2) The Linux command format contains three sections, namely: command , options , parameters ,
    • (3) a single minus sign (-) before the Linux command option, followed by a one character , a double minus sign before the option (-), followed by a word ;
    • li> (4) The wildcard characters used in the Linux command are ? * [] ;
    • (5) The effect of the command ls/usr/bin/w* is to list all files or directories in the specified directory that begin with W ;
    • (6) command ls/usr/bin/w?? The effect is lists all files or directories under the specified directory that have a name length of 3 under W ;
    • (7) The effect of the command ls/usr/bin/[xyz]* is lists all files or directories in the specified directory that begin with x or Y or Z ;
    • (8) The effect of the command ls/usr/bin/[!a-h]* is list all files or directories under the specified directory that do not start with a to H interval letter ;
    • (9) directory operation, "." Means code> the current directory ;
    • (10) directory operation, ":" Means on the first-level directory ;
    • (11) When directory operation, "-" means last working directory ;
    • (12) directory operation, "~" means user home directory ;
    • (13) command LN to establish a file link, which is divided into: hard link and soft link ;
    • (14) command Touch can change the file three times, respectively: access time , modify. /ul>

Enter/tmp directory, create a file, Goldxx (xx for the last two digits of the study number), view the file time

In the account's home directory, establish a dog directory, enter the dog directory, set up a catxx (xx for the last two-bit) directory, enter the CATXX directory, display the current directory, and then go back to the top level directory, delete catxx directory;

Copy the/etc/passwd file to the account home directory, modify the account's main directory under passwd to Passwdxx (xx is the last two digits of the study number)

Look for a file named Zcat, copy the file to the/tmp directory, list the file in a long format, and then delete all files under the/tmp directory and check if the file has been deleted

Copy the/etc/hosts file to the Account Master directory; Create a hard-link file in the Account home directory (the file name is hostsyyy (YYY is the student's initials) and link to the hosts file in the home directory ; View inode information for hosts and hostsyyy files separately

Copy the/usr/bin/vdir file to the account home directory, create a soft link file (file name Newdir) in the Account home directory, link to the VDir file in the home directory, and view the inode information for the vdir and Newdir files separately

List all files in the directory/usr/bin directory in long format, output redirected to File Outxx (xx is the last two students), check the results; Lists all files in the directory/etc directory in a long format, and the output is added to the end of the file outxx

List all files in the/usr/bin directory in a long format, connect to the more command via the pipeline, and browse through the file lists

>和>>What's the difference?

A: > is the overwrite method redirected to the new file; >> It is added to the end of the original file in a supplemental way.

Where is the easy access to the list of files through the pipeline and more commands?

A: For the list of files beyond a screen display, this way can be split-screen browsing, more convenient .

3.2 File packaging and compression commands

Under the Windows operating system, we will compress or decompress using compression software such as WinRAR or fast press, etc.

Under Linux of course there are compression or decompression operation , below we will learn how to compress and decompress under Linux!

There are several ways to compress, and we commonly use the following three types:

    • Gzip
    • Bzip2
    • Tar

The commonly used compression commands are:

    • gzip filename
    • bzip2 filename
    • tar -czvf filename

The commonly used decompression commands are:

    • gzip -d filename.gz
    • bzip2 -d filename.bz2
    • tar -xzvf filename.tar.gz
3.3 Regular Expression +grep

We have learned cat、more、less、tail these commands to view text files above, but I want to quickly see if some of the keywords under this text file exist , what should I do???

In Windows it is relatively simple, almost all the text editor (Notepad) Support CTRL+F , enter the keyword inside to find out:

That under Linux, no graphical interface, no CTRL+F case, if you do not understand some of the commands, it is really hard to find the corresponding characters out . Let me just say how to quickly find some characters under a text file .

3.3.1 Regular Expressions

First of all, let's say regular expression, if the contact of the classmate know: This thing is not good to remember. Once it is not easy to forget, so only in the use of the time to check out ~ ~ ~ So below I will give some rules directly, not much to say.

3.3.2grep command

grep (Global search Regular expression) is a powerful text Search tool . GREP uses regular expressions to search for text and prints the matching lines.

Format:grep [options] PATTERN [FILE...]

    • PATTERN is a lookup condition: It can be a normal string, it can be a regular expression , and you usually enclose the re in single quotation marks.
    • File is the files to find, which can be multiple files with a space interval, or use the shell's wildcard characters to look up the pattern in multiple files, and omit to indicate a lookup in standard input.
    • The grep command does not make any modifications or effects to the input file, and you can use output redirection to save the results as a file

Example:

    • Find the line containing the string mystr in the file myfile
      • grep -n mystr myfile
    • Displays all lines in myfile with the first character as a letter
      • grep ‘^[a-zA-Z]‘ myfile
    • Find the first character line in file myfile that is not a # ( that is, filter out comment lines )
      • grep -v ‘^#‘ myfile
    • Lists the file names that contain the string "root" in the contents of all files under the/etc directory (including subdirectories)
      • grep -lr root /etc/*

Use grep to find the line in the/etc/passwd file that starts with a, ask for the line number, and find the line that ends with login in the/etc/passwd file;

3.4 Ways to improve work efficiency
    • Auto-Complete command
      • TAB key
    • Historical command
      • Up and DOWN ARROW keys
    • Aliases Alias

Here the feeling to say is only aliases alias, we see the example below to understand!

Displays the aliases currently defined by the shell, executes two of the commands that define aliases, and defines an alias grep that requires it to display the results in a color fashion

3.5Shell variable and shell environment

Under Windows There are user environment variables, system environment variables. There are some like Linux.

Shell variables can be broadly divided into three categories :

    • Internal variables : Provided by the system, the user can only use cannot be modified.
      • ?
      • GROUPS
    • Environment Variables : These variables determine the environment in which users work, they do not need to be defined by the user, and can be used directly in the shell, where certain variables can be modified by the user.
    • User Variables : Created and modified by the user, often used in shell scripting.
      • Variable assignment (defining variables)
        • varName=Value
        • export varName=Value
      • Reference variable$varName

Scope of Shell variables:

    • The scope of a local variable is limited only to the shell or shell script file where its command line resides ;
    • The scope of global variables includes the shell process and all its child processes .
    • Local variables are interchangeable with global variables: You can use export built-in commands to set local variables to global variables. You can use export built-in commands to set global variables to local variables.

Export Command :

    • displays the global variables visible to the current shell
      • export [-p]
    • define the value of the variable and declare it as a global variable .
      • export <变量名1=值1> [<变量名2=值2> ...]
    • Declares that some (some) local variables that have been assigned are global variables .
      • export <变量名1> [<变量名2> ...]
    • Declares that some of the global variables that have been assigned are local variables .
      • export -n <变量名1> [<变量名2> ...]

Shell Environment variables:

    • Environment variables define the environment in which the shell is run , ensuring that the shell commands are executed correctly.
    • The shell uses environment variables to determine the lookup path, registration directory, terminal type, terminal name, user name, and so on.
    • All environment variables are global variables (that is, child processes that can be passed to the Shell) and can be reset by the user.

Shell variables: query, display, and cancel :

    • Show all variables that are currently defined
      • All environment Variables :env
      • All variables and functions (including environment variables):set
    • Displays the value of a certain (some) variable
      • echo $NAME1 [$NAME2 ……]
    • To cancel the declaration or assignment of a variable
      • unset <NAME>
3.5.1Shell variables and shell environment exercises

Define the shell variable Stuxx (xx is the student number at the end of the two), the initial value for the student name all spelling, with the echo command to display the values of the STUXX variable; use the unset command to cancel the STUXX variable, check the results; Use the env command to see what the currently defined shell environment variables are

Can the value of the shell environment variable be modified? Why?

A: The value of the environment variable can be modified in general. But be careful to modify it, because once you modify the error, it can have a serious impact on the shell's normal operation and even cause the shell to not run.

Iv. VI Editor

I believe that the students who have not used Linux will see two editors when they look at some of these jokes:

    • Vim
    • Emacs

Below we learn how to use VI simply. VI is the abbreviation for "Visual interface", which can perform many text operations, such as output, delete, find, replace, block operations, etc., and users can customize them according to their own needs, which is not available in other editing programs .

    • VI can be seen as a notepad under our windows
    • Vim is one of the Vi Improved,vi clone versions

To edit a file using VI:

There are three modes of VI:

4.1 Normal Mode
    • GFor jumping directly to the end of a file
    • ZZUsed to save and exit VI
    • ZQUsed to not save a disk exit VI
    • /和?Used to find strings
    • nContinue to find the next
    • yyCopy a row
    • pPaste in the next line, p pasted in the previous line
    • ddDelete a line of text
    • xDelete the character where the cursor is located
    • uCancel last edit operation (undo)
4.2 Insert Mode

Enter insert command i、 a 、 o into insert mode in Normal mode. Any characters entered by the user are saved by vim as a file content and displayed on the screen.

    • In the text input process, if you want to return to normal mode, press the ESC key.
4.3 Command-line mode

In Normal mode, the user can : enter command mode by a colon, at which time vim displays a ":" As a prompt for the commands mode in the last line of the display window (the last line of the screen), waiting for the input.

    • :wSaves the current edit file, but does not exit
    • :wNewFile Save As another file named "NewFile"
    • :wqUsed to save and exit VI
    • :q!Used to not save a disk exit VI
    • :qFor direct exit VI (not modified)

Setting up the VI environment:

    • : Set autoindent indent, commonly used in program writing
    • : Set noautoindent Cancel Indent
    • : Set number Displays line numbers when editing a file
    • : Set Nonumber does not display line numbers
    • : Set Tabstop=value sets the number of space characters to display tabs
    • : Set display all options for settings
    • : Set all shows all options that can be set
4.4Vi Exercises

In the user's home directory, execute VI program, edit file Install.log; Move cursor to Line 10th, fifth character; Press capital letter G to reach end of file;

In the user home directory, execute VI program, edit the file install.log; use/command to find the string sudo, copy the line containing the string sudo

In the user's home directory, execute VI program, edit the file Install.log, enter the command mode, set the display line number; command to find the string openssh, use command N to find the next

Iv. Summary

This article mainly explains the basic knowledge of Linux and can operate Linux easily. command can be said to learn, can only be remembered that Linux has this function, then to the Internet to check is also very convenient.

The main is more practice, more play can remember some of the common Linux commands ~ ~ ~

I'll take the time to draw a map of the Linux commands (of course, the command is limited to the knowledge point of this article , and so on to the user, the network and other knowledge points to continue to add up!) )

If the article is wrong, welcome to correct, we communicate with each other.


Java3y
Links: https://juejin.im/post/5af8329d518825426d2d3887
Source: Denver Nuggets
Copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please specify the source.

After reading this Linux basic operation will be

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.