Introduction to----linux commands [embedded training notes]

Source: Internet
Author: User
Tags clear screen echo command file copy touch command

The Linux file system is structured like a tree and is grown from a root. The root is called/. A lot of forks grow from the roots, so they grow. When we use the Linux operating system, we always fall on a fork. The LS command helps us to see all the files and sub-forks on the current fork. The PWD command can help us understand the entire path from the root to the current fork.
/* Comment */
This means that the Linux file system is stored in the form of a tree in the data structure.

The PWD command returns the following results:
/home/soft01
The root of the entire book, which is the source of the file system. Home represents a fork that grows on the root, and soft01 is a smaller fork that grows on the home fork. Use/separate between different forks.
/* Comment */
PWD command PWD Displays the current path ... The path shown is the absolute path ... The path from the root directory to the current location

The clear command can be used to erase all content on the screen.
/* Comment */
Clear command, Clear screen command, clear screen or can be restored, with the middle of the scrolling mouse can see the screen before the clear screen. If you do not want to see the situation, you can use the menu bar, terminal (T), reset and clear the screen


There is a relationship between the forks in the filesystem, assuming fork B is on the fork A, then we say fork A is the parent fork, and Fork B is the Sub fork. If we want to jump to fork A on fork B, we take the command:
Cd..
If we want to jump to fork B on fork A, you can use the following command:
CD B
The CD command also allows you to jump to a different fork that is very far away, at which point you should write the absolute position of the target fork (that is, the full path starting from the root) behind the CD command, for example:
Cd/etc
/* Comment */
cd command popular parlance, is the directory switch, from one directory to another directory.
The command format is: The target path of the CD to jump
The target path to jump can be a relative or absolute path, with two points to explain
. Represents the current directory
.. Represents the upper level directory
When you want to jump to a subdirectory of the current directory Yes, you can directly CD sub-directory

If you want to create a new fork on the current fork, you can use the command mkdir, which is followed by the name of the new fork, for example:
mkdir STARDARDC
Where mkdir is the command, STARDARDC is the name of the new fork
/* Comment */
Of course, if you want to create a directory under the specified directory, simply represent the file you want to create with a relative or absolute path, and replace the STARDARDC, for example:
Mkdir.. /stardardc
Creates a new STARDARDC directory in the upper directory of the current directory, similar to the absolute path method
* ERROR statement: STARDARDC should be STANDARDC means standard C
It's just a simple introduction to the mkdir command.


RmDir
The command can be used to delete an already existing fork, provided that there is nothing in the fork.
/* Comment */
Command format with mkdir


The chmod command can modify the properties (permissions) of a file and the command format is as follows:
chmod 755 create.sh
Where chmod is the command name, 755 is the modified property value, and create.sh is the file name of the property to be modified. 755 means that the file is a file that can be run, and 644 means that the file is not operational.
/* Comment */
Where 755 is used to describe the property values of a file, the files in the Linux system can be
7 5 5
1 2 3
Where the first number 7 represents the file owner's permissions on the file
Where the second number 5 represents the permissions of other people in the same group as the file owner
where three digits 5 represents the permission of the other person to the file

These 3 numbers are represented in binary notation as follows: (Each of the corresponding permissions is given)
7 5 5
111 101 101
RWX rwx rwx
Read Permissions W, write permissions x, execute permissions
The two most common groups of permission numbers are 755 644
6 4 4
110 100 100
RWX rwx rwx

Files that are manually written and can be run are called script files, and you can use a script file to accomplish a lot of repetitive work. The script file must be set to run with the chmod command, otherwise it cannot be used. To run a file in the current location on a Linux system, use the following method:
./File Name
/* Note */replace the file name with a executable file with a path to run the files at the specified location


chmod 755 create.sh
./create.sh
When a shell script executes a bulk command, you can enter the command you want to execute into a file, and then run

The CP command can be used to complete the file copy and paste work, the CP command example is as follows:
CP < Existing files to be copied > < target location >
Copy and paste
The CP command can also copy a file from the current location to another name
CP < Existing files to copy > < name to save > For example://Rename
CP create.sh build.sh
which
Create.sh represents a file that already exists at the current location, and build.sh represents the name of the new file to be copied.


Use the MV command to achieve the file clipping function, the MV command is as follows:
MV < original file name > < new file name >
The original file was replaced with a new file after this command was executed.
As the above command can also implement the renaming of the file, when it is two files with different paths is, the implementation of the cut operation
MV < filename to move > < target location >


The touch command can be used to create a new empty file in the current file directory, with the following command
Touch file name
The new file appears after the command is executed.

The RM command can delete an existing file with the following command:
RM file Name
File disappears after command execution
Note: RM
Also can be used to delete the directory, when the directory to be deleted is not empty, you can use the RM command to delete the directory, the command is as follows: (in fact, empty directory can also be deleted with RM)
Rm-r the non-empty directory name to delete

The echo command can be used to display all the text behind it again on the screen. For example
echo Hello World
The result of the execution of this command is
Hello World
It makes no sense to use such a command alone, but it can be very complex to combine with other commands.
In the Linux operating system, output redirection can be used to output the content that should appear on the screen to a file instead. The use method is to add the greater than sign (>) behind any command and then follow a filename so that the content that this command should have displayed on the screen appears in the text.
For example
echo mkdir day01 > create.sh
The result of the command execution will record the following line in the file create.sh mkdir day01


When using output redirection, a greater than sign (>) causes the file contents to be purged, so the output of the last command can only be recorded in the file in this way. To be able to record multiple commands in a file, we need to use two more redirect methods than good, such as
echo mkdir day01 > create.sh
echo mkdir day02 >> create.sh
The above two commands will record the following in the file create.sh
mkdir day01
mkdir day02


tab can only enter shortcut completion

Wildcard characters are an auxiliary tool provided by Linux systems that describe a name format in a command. All names that match the name format description should be manipulated using the command. It can replace some other characters, the wildcard has the following several
? : This wildcard can replace a single character, that is, wherever the wildcard character is used, the description
*: This wildcard can replace any number of characters
[] :
This wildcard is very versatile and has a very powerful ability. We only learn a very simple one, which is to use it to describe a single character within a range. For example: [3-7] represents one of the five characters of the 3,4,5,6,7.


[] Also expression--universal expression

Cat more less head tail

The cat command can be used to view the contents of a file, with the following command:
Cat create.sh
This command will show all the contents of the file create.sh on the screen.
Using the cat command to view the contents of a file is appropriate for small files, because the Cat command will display all the contents of the file on the screen, and if there are many lines, the contents of the front row are invisible. If you want to see the file need to use the more command, this command will display the contents of the main page, the return page. If you do not want to continue viewing, you can use Q to exit.

Some of the most important things in the file are in the first few lines, you can use the Head command when viewing this file. By default the head command shows the first 10 lines of the file on the screen, and we can also specify in the command to show the machine line content, for example:
Head create.sh
Head-3 create.sh
Where-3 means viewing only the first 3 rows

Some of the files in the Linux system are constantly expanding, the latest content is on the last line, and if we just want to see the latest content, we can use the tail command. By default, the tail command displays the last 10 lines of content on the screen, and we can specify the running script that we want to show. For example
Tail create.sh
Tail-3 create.sh
Where-3 represents 3 lines of display

When we want to find a name in the system, I can use the Find command. The Find command is powerful and we only introduce the simplest one. Examples are as follows:
Find. -name day03
In the above command, find is the command name, and the. Represents starting from the current position,-name day03
And up to find everything called the name day03.

Find cannot locate a file based on the contents of the file, meaning it does not open the file in the lookup
grep can give the file content a fine-grained look. This command is also very complex, and there are a lot of similar commands, and we introduce the simplest one. Use the grep command to extract a line containing some content from a file, for example:
grep create.sh
This command displays all lines containing 09 of content in the file create.sh on the screen.


Connection
In the Linux operating system can establish a connection file for the file, the connection file can be used as the representative of the original file, but it has a very small amount of storage space. The connection file is divided into two kinds of soft connection and hard connection. Soft connection file is the shadow of the original file, once the original file disappears, the soft connection file will not be used. Hard-connect files are completely equal to the original files, and they are just a shared storage location.
ln create.sh build.sh
Where create.sh is a file that already exists and build.sh is the name of the newly created hard connection file.
You can use the following command to create a soft connection file:
Ln-s create.sh build.sh
Compared to the previous command is only one-s, so that the connection file is a soft connection file.

Pipeline
The Linux system provides pipeline functionality that connects two completely unrelated commands, allowing the output of one command to be entered as another command. The use of this generally can achieve very complex effects. Examples are as follows
ls | More
In this command, the result of the LS command output is used as input to the more command, so that we can view the results of the LS command on the screen line by row.

Introduction to----linux commands [embedded training notes]

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.