After the previous study, probably understand the computer composition principle and some knowledge of the operating system. Although this knowledge is trivial, pieced together, in the future work and study still need to have a deep understanding. But these preparatory knowledge should be sufficient for children's shoes that are ready to enter the gates of Linux. So you can find (KU) fast (BI) The knock command, this article will come to the study of these days to make a summary of the order.
Before starting the Linux command to learn, you might want to review the operating system knowledge, which may be used in the later learning, it is necessary to understand again.
1.Kernel kernel and system calls
Kernel is the core of the operating system, the first day we have said that the operating system core functions, such as process management, memory management, file system, network management, etc., are provided by the kernel. These functions are the basic function of each operating system, and those running on the operating system are more or less required to use the functionality provided by the kernel. So here we can understand the role of the kernel in a different way: abstracting the computing power of computer hardware and providing it to upper-level software calls. This call is called a system call.
System calls can be interpreted to be programmed to invoke the lowest-level API provided by the operating system. But for programmers, system calls are too low-level and complex, and are cumbersome to use. At this point we need to use the library, the library is the operating system to call the system a higher level of abstraction, through the call library programming, more simple than the system calls. The hierarchy of these operating systems is clear to us: applications such as Kernel cores, and various libraries. The application is built on the basis of various libraries.
2.Magic number of magic numbers
The software we write is also called an executable file. Software is essentially a file, but can be executed, then how the operating system to determine whether the file can be executed? or where to execute the file? This will use the magic number. Magic number, as the name implies, it is magical, its magic is: you can tell the operating system whether the file is an executable file or an ordinary file, as well as some other information.
In particular, the magic number is at the beginning of the binary code of each file, which is used to represent several special characters of the file type and permissions, and the format of these special characters is fixed. When you double-click an application, or enter a command in the CLI, the shell submits the binary file to the operating system's kernel Kernel, Kernel to find the magic number of the file, judging whether the file is executable or not, and so on. If the detected requirements are legitimate, the file is run, and if the detection is illegal, the execution is denied.
3. Working Directory
Presumably you have found that as long as we are in the operating system, we are in one directory. All of the operations that we have done are done in one directory. This directory is also called the Working directory (working directory).
Here's a question: one of the basic philosophies of Linux is that everything is file, so is the directory a file? is the filename a file? Where are the file names and files stored? I do not understand these questions, stay in the post-and-answer.
Speaking of the working directory, here is the first Linux command introduced in this article: PWD (print working directory). This command is used to output the working directory where the user is currently in the form of a string on Bash.
4.Linux File System Introduction
Linux uses a hierarchical file system, which can also be called a property file system, a root filesystem (root file system), and so on. is the file system tree that starts from a root directory and spreads down. "/" indicates the root file system. The vast majority of Linux distributions follow the FHS standard, and FHS represents the filesystem-level standard presented by the Linux Standards Board, which specifies which files must be created by the Linux distribution. So we can see some of the same directory structure in almost all Linux distributions, such as "/Boot", "/dev", "etc", and so on, which are described below.
- /boot: Used to store system boot related files, such as System kernel, Grup (bootloader), etc.
/dev: The directory where the device files are located, and all hardware devices on Linux are also recognized as files. Device files are divided into block devices and character devices.
Block device: A device that can be accessed randomly. For example, you can read data from any location on your hard drive.
Character device: A device that can only be accessed linearly, in order. For example, the keyboard to identify the characters on the keyboard must be accessed sequentially, not at random to read.
Device files are special files, no size, main device number and secondary device number on device
- /etc: the main directory where the configuration files are stored
- /home: The user's main directory, in addition to the root user, is the default home directory for each user, which is a user-named directory-Name branch. namely:/home/username. The root user's home directory is under/root and is not in//.
- /lib: Used to store library files. We made a brief introduction to the library above, knowing that the repository is the interface that the operating system abstracts from the system call to provide to the application. In fact, the library is divided into dynamic library and static library two kinds.
- Dynamic library (Shared library): Under Windows, the suffix name is. dll and the suffix under Linux is. So (shared Object). The dynamic library file only has one copy in memory, and if several software relies on a library file at the same time, they are using the same library file. The advantage of a dynamic library is that it does not require repeated loading, saving a lot of memory space. Disadvantage is inconvenient to transplant the program, in particular, a program read relies on a dynamic library execution, when moving it to other systems, but also to ensure that the system has a corresponding library files, or the program cannot execute.
- Static libraries: Unlike dynamic libraries, static libraries are part of the program and run with the program as part of the program. Because static libraries and programs are a whole, this static library file also has multiple copies in memory if multiple programs use the same static library file. The advantage of the static library is that it facilitates the porting of the program, and the disadvantage is that it cannot save memory space.
- /media and/mnt: The mount point directory of the system. Using a hardware device under Linux requires that the device be linked to a node on the filesystem to be used, and this process is mounted. Usually hangs on the/media on the mobile device, hangs on the/mnt on the extra temporary file system, but does not have the strict request.
- /misc: Miscellaneous.
- /OPT: Early is the installation directory for third-party software.
- /proc: Pseudo file system. It is called a pseudo file system because this directory is stored inside, not like other directories stored on the hard disk. Since it is stored in memory, the directory will not exist after shutdown, it is mainly used to save the kernel mapping file after the operating system is opened.
- /sys: Another pseudo file system that holds the property mapping files related to the hardware device.
- /tmp: Temp file directory. This directory clears files that are not in use every once in a while. Any user can create a file in/tmp, but can delete only the files that they have created, and cannot delete files created by other users.
- /var: used to store changeable files. such as cache, log and so on. These files are constantly changing, so store them in the/var directory.
- /bin: The executable file is stored. User commands are in the inside.
- /sbin: Store administrative commands.
- /usr: A directory created to facilitate the user's use of the operating system, such as software installation, help manuals, etc.
- /usr/local: Storage of third-party software.
rules for naming 5.Linux files
- File name cannot be longer than 255 characters
- Cannot use/when file name, except/outside, other characters are legal
- Strictly case-sensitive
- To. The file that starts with is a hidden file
6. Common Commands
- LS (list): Lists the visible file information under the specified directory, defaults to the current directory
- Ls-l or LL: Lists complete file information, including various properties of the file
- Ll-h: When the details are displayed, the default is to display in bytes, and the-h option is used to convert the number of bytes to the KB, MB, GB, and other units that are familiar with the kinky class display
- Ll-a: Displays all files, including those representing the current directory. and representing the parent directory.
- Ll-a: Show Remove. And.. All files except the
- Ll-d: Displays the details of the target file, which can be a directory or a normal file
- Ll-i: Displays the index node of the file. Kinky class is a file to find a file, and the computer is through the file index to find the relevant file
- Ll-r: Reverse Display
- Ls-r: Recursive Display of directories
- CD (change directory): Switch directory
- CD DIR: Switch to the specified directory. No parameter: Back to user home directory
- CD ~: Back to the user home directory
- CD-: Switch back and forth between the current directory and the previous directory
- Type: Determines the kind of command.
- Type command: Determines whether the parameter command is a built-in command or an external command
- Built-in commands: commands built into the Shell
External command: In a directory, there is an executable file that corresponds to the command name, such as/bin
- LS is equivalent to/bin/ls,ls is an executable file under/bin, by running this file can be listed in the current directory sub-files.
- Why do you omit the/bin in front of/bin/ls? Because/bin is written to the environment variables of Linux. What is an environment variable, without explaining three more.
- Hash: View cached commands in the Shell
- Despite the environment variables, it is convenient to execute commands in the Shell, but is it a waste of resources to execute the commands through the paths in the environment variables each time the command is executed?
- Shell has a caching mechanism, the command entered in the shell can be temporarily cached, the next time the command is executed directly from the cache to find, much faster.
- Use the hash command to see the commands cached in the shell and the number of times they were used (hits).
- The classic quote from the computer: Cache is king.
-
-
- Cal: Get Calendar
- Cal 2099: Gets the calendar for the specified year, which defaults to the current month
- Cal 12 2099: Gets the specified month calendar for the specified year
- Echo: Content output File: Identifying the type of File tree: View the directory tree structure of the specified directory (this is pretty)
- ECHO-E: recognizes escape characters. Echo-e "Memeda. \ Mamada. "
- Print: Transfer characters can be recognized directly, without adding options. print "Heheda \ t Xixida."
- mkdir: Creating a Directory
- Mkdir-p: Recursive creation. Mkdir-p Memeda/heheda/xixida
- MKDIR-V: Show creation process
- Using an expression: Mkdir-p Hehe/haha/{xixi,heihei}
- Expression combined with mathematical formula: Mkdir-p hehe/haha/{a,b}{c,d}
- (A+B) (c+d) = ab + ac + BC + BD
- Touch: Modify timestamp information for a file/create file
- Touch file: Modify the timestamp information for the file (while modifying the last access timestamp and the modification timestamp)
- There are three types of timestamp information for a file:
- File modification Time
- File last access time
- File change Time
- The difference between modification and change:
- Modify: Change the contents of a file
- Change: File attributes change, such as file type, file group, etc.
- The last access timestamp and modification timestamp of the file can be changed, and the timestamp of the file cannot be changed
- Touch-a file: Change the last access timestamp
- Touch-m file: Change the modified timestamp of the files
- When touch modifies a file's timestamp, it first determines whether the file exists, modifies the file timestamp information if it exists, and creates a new file if it does not exist. So we often use touch to create new files.
- Touch-c file: Modifies the timestamp of existing files without any action if the file does not exist.
- Touch-a-T 209912122359 file: Changes the timestamp information of the files to the specified time. This is a common trick used by hackers.
- Stat file: View timestamp information for a file
- Nano file: Create a document and edit the contents of the file
- After creation, press CTRL + O to save, CTRL + X to exit.
- RM file: Deleting files
- Ordinary users and administrators to remove the difference between files: Ordinary users delete files will not be prompted, the administrator user will be prompted to delete
- The RM command used by the administrator is a modified command, and if you want to use the original RM command, you can use the/RM FILE
- Rm-f: Forcibly Delete
- Rm-r: Recursively Delete a directory
- CP: Copying files
- CP Target Dist:dist is the target directory/file, and if it is a directory, copy it to the directory
- CP TARGET1 TARGET2 TARGET3 DIST: Copy multiple files to a directory (note that you cannot copy many-to-many files).
- The CP requires that the last parameter be a directory and not a normal file.
- Cp-r: Copy directory, if destination directory does not exist, create new directory
- Cp-i: Ignore prompts during replication
- Cp-p: Copying files and preserving the properties of the source file or directory, including owner, owning group, permissions and time
- CP-A: Copy and retain all attribute information from source file, often used for backup of files
- CP Link: The file that the link points to is copied by default, not the link itself
- Cp-d Link: Copy links themselves
- MV: Moving files
- MV TARGET DIST
- MV Haha.txt xixi.txt: Renaming files
- Mv-t DIST target: Move the file, specify the target first, specify the source file
- Install: Copy files or create directories
- install-d {Meme,hehe}: Creating a Directory
- Install meme.md xixi/: Copying files
- Install can only copy files, cannot copy directories
- Install can only create directories, cannot create files
- Cat: Display the contents of a file
- Cat file: Sequential display of file contents
- TAC file: Display the contents of the files in reverse order
- Cat-n: Display Line numbers
- CAT-E: Display Terminator
- CAT-T: Show Tabs
- Cat-v: Displays all nonprinting characters
- Cat: No parameter is represented as reading from standard input and displayed to standard output
- Cat's note section: If cat is used to read text that is very long, such as/etc/rc.d/rc.sysinit, only a small piece of content will be displayed in the terminal. We can use SHIFT + Pageup/pagedown to read the content from the buffer, but because the cache length is limited, it is not necessarily possible to read all the content. Therefore, cat is not suitable for long text reads.
- More/less file: Reads the contents of long files and is able to flip the screen
- MORE: Support Paging backward only
- Less: Supports page-flipping operations like the man command
- Head: View the first n rows of a file, default to 10
- The following two formats are supported in Linux:
- Head-n Memeda.txt
- Head Memeda.txt
- Tail: View the file's after n rows, default to 10
- Cut: Grabbing the contents of text
- -D: Specify delimiter
- -F: Displays the first fields separated by separators
- -F 1: Show first field
- -F 1, 2: Show First and second fields
- -F 1-3: Show top three fields
- The-D and-f options are not omitted, and the parameters of the options must not be omitted
- Sort: Sorts the contents of the text, sorted by default in ASCII
- Sort-n: Sort by number
- Sort-r: Descending sort
- SORT-T: Specify delimiter
- Sort-k: Sort by the specified delimited field
- Sort-t:-K 3/etc/passwd, using: Separating the/etc/passwd and sorting with the third field as a datum
- Sort-u: The same information is displayed only once
- Sort-f: Ignoring case
- Uniq: Removing duplicate rows
- Uniq: Remove duplicate rows and display, by default only repeat rows for adjacent duplicates
- UNIQ-D: Show Duplicate rows
- Uniq-d: Show all duplicate rows
- Uniq-c: Displays all rows and displays the number of repetitions per line
- WC FILE: Text statistics
- Wc-l: Count rows
- Wc-l: The longest line contains the number of characters
- Wc-w: Number of words
- Wc-c: Number of bytes (spaces are counted)
- TR: Character Conversion
- TR "Memeda" "Memeda" </tmp/memeda.md: Convert Memeda in/tmp/memeda.md to Memeda
- Tr-d "Memeda" </tmp/memeda.md: Delete all Memeda in/tmp/memeda.md
7.Bash and some of its features (including some commands)
Bash is also a command that opens a child shell in the current shell. Exit naming indicates exiting the current shell and returning to the previous shell, exiting the current user if the previous shell is already the root shell. A user who is not logged in to Linux will open a bash and can log in to multiple users at the same time. This allows Su to exit and return to the original user Shell.
Bash is a command-line tool that looks like Csh,ksh in addition to bash. Note that the Shell can be opened alternately, such as opening csh in Bash, and then opening Ksh in CSH. This means that a shell's child shell does not require the same as the original one.
Some tips on how to do bash:
- CTRL + A: Jumps to the beginning of the command
- CTRL + E: The end of the line to the command
- CTRL + U: Delete this command if at the end of the line at the cursor command. If the cursor is on a character, all characters before that character are deleted.
- CTRL + K: If the cursor is on a character, all characters after that character are deleted
- CTRL + L: Clear screen, equivalent to clear
Command history: Bash records executed commands, can be toggled using the up and down arrows, or you can use the history command to view records:
- History: Historical record of executed commands
- History-c: Emptying command history
- history-d 100: Delete the 100th command in the history
- History-w: Save history to the historical file (~. bash_history)
The executed command is stored in a buffer in memory, and when the user exits normally, the contents of the buffer are appended to the ~ bash_history, so the next time the user logs on to the system, he can continue to use history.
Tips for using commands:
- !n: How many commands are executed in the history
- !-n: Perform the last few commands in history
- !! : Executes the previous command
- !man: Executes the command beginning with man in the history (first match)
- !$: Referencing the last parameter of the previous command, CAT/ETC/PASSWD Nano!$
- ESC +.: Use a key combination to refer to the last parameter of the previous command
Command aliases:
- Alias: Displays all command aliases in the current bash
- Alias alias = command: Set the alias Unalias alias: Revoke command alias
- Alias CLS Clear
- Alias Cddesk "CD ~/desktop"
Command substitution: Similar to the magic variable in PHP
- Touch file-$ (date +%f-%h-%m-%s). txt
- Touch file-' Date +%f-%h-%m-%s '. txt
- Command substitution can use $ () or anti-quote "
File name wildcard:
8. Summary
This article mainly introduces some basic concepts and common commands of Linux, including Linux file system, and some common operation files and directory commands. In the end, we introduce the features of bash and some usage techniques, which require constant practice and review to master the above.
Charleylla Reprint Please specify the Source: http://www.cnblogs.com/charleylla/p/5972819.html
[Linux common commands for the next day]--linux