Raspberry Pi Fun with LINUX-Part1 Shell

Chapter 5 Raspberry Pi in a Shell

The performance of Raspberry Pi is not high, and the presentation of computer graphics consumes resources. Fortunately, Linux provides a way to interact with Raspberry Pi more easily-Shell

5.1 Initial Shell Test

Open the terminal, and a black background window will appear on the desktop. The window says:
pi@raspberrypi:~ $
where pi is the user name, raspberrypi is the name of the computer, and it is the naming prompt. If you hit the keyboard, the characters will be displayed at the naming prompt. If you hit the keyboard, the characters will be displayed inIs life name mention shown operator . As if knocking hit key plate , then it word character will significantly shown in the prompt, the formation of a string of text commands. In English, Shell is a shell like shell. In Linux, the so-called shell is a text interactive program running in the terminal. Shell analyzes the text input and then converts the text into corresponding computer actions. The user touches the computer through the "shell" of the shell.
In the following content, will be usedto represent the Shell command prompt of the Linux system, for example, enter the data command: 'to represent the Shell command prompt of the Linux system, for example, enter the data command: `To Table shows L I n- U X -based system of S H E L L command makes mention shown symbols , cases such as input into D A T A command command : ' data`
related data for the date and time functions. After pressing Enter, Shell will display the current time of the system.
Shell looks simple, but it is actually much more powerful than graphical desktops. The Linux operating system is inherited from the UNIX operating system. Both the Linux operating system and the UNIX operating system initially only provided Shell, a user operating system interface. If you are used to this text operation, you will gradually realize its benefits.

5.2 Use commands to understand Raspberry Pi

1.Linux general query commands

  • First, use lscputhe command to query the information CPU:

$lscpu
The CPU information will be printed out in the terminal window:

Architecture:	armv7l
Byte Order:	Little Endian
CPU(s):	4
On-line CPU(s) list: 0-3
Thread(s) per core:	1
Core(s) per socket:	4
Socket(s):	1
Model name:	ARMv7 Processor rev 4(v7l)
CPU max MHz:	1200.0000
CPU min MHz:	600.0000
  • Then, you can use freecommands to understand memory usage:

$free -h
When using the above command, the -h option (option) is added. By adding options to the command, you can change the behavior of the command. The letter h here means human readable. If the -h option is not used, the free command will display the result in bytes. With the -h option, free can convert the result into a unit more suitable for display.
The results printed by Shell are as follows:

			total		used		free		shared	buffers		cached
Mem:			862M		739M		122M		14M		44M			397M
-/+ buffers/cache:	298M		563M
Swap:			99M				0B			99M

As you can see, the total memory is 862MB, and the used and available memory space is also displayed in the other columns. By increasing the selection, the functions of Linux commands become more abundant.

  • Look at the storage situation of the SD card again, use the command fdisk:

$sudo fdisk -l
The command fdisk is used to display disk information. Options -lrepresent lists all disks. You can see that sudo is added before the command. Some commands require special permissions to run, and sudo provides the system administrator to execute the following commands, ie fdisk -l. The last two lines of the result are as follows: The
code needs to be supplemented by the screenshot of the actual machine

The entire SD card is divided into two partitions, one of which has 60MB and is dedicated to booting the Raspberry Pi; the other is used to store all other data.

  • Use lsusb, you can find all USB peripherals:

$lsusb
Shell will print:

Bus 001 Device 005: ID 0e8f:2517 GrennAsia Inc.
Bus 001 Device 006: ID 045e:0750 Microsoft Corp.	Wired Keyboard 600
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.S<SC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
  • Use unamecommand, you can print out the information of the operating system

$uname -a
Option -adisplays all relevant information, Shell will print

	Linux raspberrypi 4.1.19-v7+ #858 SMP Tue Mar 15 15:56:00 GMT 2016 armv7l
GNU/Linux

The kernel used by the system here is Linux version 4.1.19, and the release time of the kernel is March 15, 2016

  • Finally, use ifconfigthe command to view the network interfaces:

$ifconfig
The result of the command operation is as follows: The
code needs to be supplemented by the screenshot of the real machine.
Among them, eth0 represents the Ethernet interface, wlan0 represents the Wi-Fi interface, and lo is the virtual local interface, which is used to represent the machine. In the interface connected to the Internet, we can see the IP address of the interface and other information. For example, the IP address of wlan0 is 192.168.0.108. Because the network cable is not plugged in, eth0 does not have an IP address.

2. Special query commands for Raspberry Pi

  • In addition to common Linux commands, the Raspberry Pi also provides the vcgencmd command for direct interaction with the Raspberry Pi hardware. For example, execute in Shell:

$vcgencmd measure_temp
In the above command, the second segment measure_tempis a parameter of the command. Parameters are another way to provide additional information to the command in addition to options. The above command will return the temperature of the CPU:
temp=51.5'C
use the following command to measure the core voltage of the Raspberry Pi:
$vcgencmd measure_volts core
return the voltage value:
volt=1.2000V

5.3 What is Shell

$free -h

A total of 7 characters including spaces. Shell procedures by spaces distinguish between the different part of the command. The first part is the command name, and the remaining parts are options and parameters. In this example, Shell will be further analysis of the second part, found at the beginning of this section is "-" character, so they know it is an option .

With the command name, Shell will execute the action corresponding to the command name next. It sounds like it’s on a theatrical stage where actors act according to script. Shell commands are divided into the following three categories.

  - Shell内建函数(built-in function)。
  - 可执行文件(executable file)。
  - 别名(alias)

Shell's built-in functions are stored in the internal Shell's script. Correspondingly, executable files are scripts saved outside the Shell. Shell must find the executable file corresponding to the command name in the system to execute it correctly. We can use the absolute path to tell the Shell where the executable file is located. The so-called path , refers to the location in a document storage space, for example:
/bin/date
the date the executable file path surfaces within the bin file folder located in the root directory.
If the user only gives the command name, but not the exact location, the Shell must search for some special locations by itself, which is the so-called default path. Shell will execute the first executable file with the same name as the command. This is equivalent to Shell automatically filling in the location information of the executable file for us. We can whichdetermine the command command name which corresponds to the executable file:
$which date
alias is a short name for a command from the future in the Shell can be invoked through the command corresponding abbreviation. In Shell, we can aliasdefine aliases:
$alias freak="free -h"
Shell will remember our alias definitions. After entering this command in the Shell in freaktime, will be equivalent to the inputfree -h

In the Shell, you can typecome to understand the type of command command. If a command is an executable file , it typewill print out the path of the file.
$type data
$type pwd
In general, Shell is based on spaces and other special symbols to let the computer understand and perform the actions requested by the user.

5.4 Shell selection

  • Shell is a general term for text interpreter programs, so it includes more than one Shell.
  • In the Raspberry Pi, sh and bash are installed
  • Bash is an improved version of sh. Generally speaking, bash is recommended
  • $echo $SHELL View the current Shell type
    • echo terminal for printing text, but $is a new Shell special symbols, it prompts Shell, is not followed by the general text, but rather are used to store variable data. The shell will find the real text based on the variable name and replace it with the location of the variable. Shell SHELL variable to store the information currently in use, can be used in bash shstartup command, with exitcommand exits.

5.5 Command options and parameters

  • It is known in the command line may contain options and parameters . In general, the options for behavior control command, and parameter describes the role of the object of the command, for example:

$uname -m

  • In the above command, option -m affects command unamebehavior, resulting in unamethe output of the Raspberry Pi CPU models. If it is not affected by this option. Then the unameoutput will be LINUX. We might as well regard each command as a multi-functional Swiss army knife, and options enable commands to switch between different functions. By a "-" to lead an English alphabet, this is known as short options . The letters of multiple short options can be combined, followed by the same "-". For example, $uname -m -r $uname -mrit is equivalent. There is also a long option , is to use "-" to lead an English single break, for example: $date --versionthe version information output from the date of the program.
  • If the option to control the behavior of the Swiss Army knife, then parameter provides the raw material purpose Swiss Army knife play. To echocommand as an example, he can print to a terminal character. The object he chooses to print is its parameters:$echo hello
  • Sometimes, options will also carry variables to illustrate the raw materials of the option's behavior, such as:

$sudo date --set="1999-01-01 8:00:00"

  • Options "-set" is used to set the time, with an equal sign link is its parameters. date will set the date to the date represented by this variable. If the short option , it is necessary to use a space to replace the equal sign:

$sudo date -s "1999-01-01 08:00:00"

  • It is worth noting that Shell is sensitive to spaces. When the parameter information contains spaces, we need to use quotation marks to wrap up the parameters, so that Shell can recognize it as a whole.
  • Options and parameters are additional information provided to the command. Therefore, what the command will do with these strings in the end is determined by the command itself.

5.6 How to understand an unfamiliar command

  • whatis

$whatis ls
**whatis **The function of the command is to introduce the command in a short sentence

  • man

$man ls
man will return the manual for command help. For most of the commands that come with Linux, when the author writes, he will write a help document telling users how to use this command. Man can be said to be the best encyclopedia for us to understand Linux. It not only tells you the functions of Linux's own commands, but also can query Linux system files and system calls. If you want to learn Linux in depth, you must know how to use man to query related documents.

  • info

$info ls
info will return more detailed help information.

5.7 Shell tips

Command completion

Most Shells have the function of command completion. When you $input the back part of the command, such as "dat", press the TAB key, Linux will it supplement called "date". In this process, Shell will search all the possibilities of the command name. If there is only one possibility, Shell will fill in the file name. If there is more than one type, there will be no response when you press the TAB key for the first time. When you press the TAB key for the second time, the terminal will print out all possible command names. For example, input "da" and press TAB twice, the terminal will output: dash date
This prompt can help you remember the command you want to enter.

File name completion

If the input is a file name as a parameter, it can also be filled as above.

History command

In the Shell, the up arrow may be used, or historybefore the command to view the input command.

Abort and pause commands

When a command is running, if you want to stop it halfway, you can use the shortcut key Ctrl+C. If you just want to stop temporarily, you can use the shortcut key Ctrl+Z. Suspend and pause refer to the ** signal (Signal) mechanism in Linux, which will be introduced later.

Guess you like

Origin blog.csdn.net/qq_31714533/article/details/109276887