“This is the ninth day of my participation in the August More Text Challenge. For details, see: August More Text Challenge.”
Linux command
1 What is embedded
Embedded is an application-centered computer system based on computer technology. Hardware and software can be tailored to power consumption, volume and cost
Linux: is an operating system () Ubuntu is a distribution of Linux
Linux itself is a kernel, Linux kernel five functions: 1. File management 2. Memory management process management (application engineer) 4. Device management (driver engineer) 5. Network Management (Application Engineer)
Everything in Linux is a file: All resources in Linux are operated as a file, (o\r\w\c)
Linux is a multi-task, multi-user, time-sharing operating system
Linux command: ls\ CD \cp\mv\touch\mkdir\rm\cat\echo
The essence of a command is an executable program
2 Software Package Management
First of all, determine whether Ubuntu can connect to the network terminal input
ping www.baidu.com
Online installation (with networking)
Sudo apt-get install Name of software to be installed sudo apt-get download Software package to be downloadedCopy the code
64-bit operating systems can sudo apt install the name of the software to be installed
Install code rain online
sudo apt-get install cmatrix
Downloading software Packages
Ubuntu packages are suffixed with.deb
Redhat software packages contain.rpm
Linux download path: /var/cache/apt/archives$
Offline installation
No Internet connection but must have packages and does not check for installation dependencies (prone to unsuccessful installations)
Sudo DPKG -i Name of the software package to be installed cmatrix_2.2a-5Build3_AMD64. Deb CMatrix_ 1.2a-5Build3_AMD64Copy the code
Software uninstall
Online Installation Online uninstallation
Sudo apt-get autoremove software name
Offline installation Use offline uninstallation
Sudo dpkg-r Specifies the software name
3 Compression and compression
Linux under
Compression is for files
An archive is for a directory
The archive
Tar Space Parameter Space File name to be archived or compressed space Source file name
The benefits of archiving reduce the number of files, facilitate sending multiple files as E-mail attachments, and back up files.
The command | function |
---|---|
-c | Create a file |
-v | Shows the archive/decompression process |
-f | Create and release file names |
-x | Release archive |
Eg: the lib directory
Tar lib // Archive the lib directory to lib.tar tar -xvf lib.tar // Release the archive lib.tar fileCopy the code
The compression
Compression: the use of algorithms to lossy or lossless file processing, in order to retain the most file information, and make the size of the file smaller.
The benefits of compression are to save disk space, reduce the size of E-mail attachments, and improve transmission efficiency.
Gzip compression generated. Gz | decompression gunzip XXX. Gz bzip2 compression generates the.bz2 | decompression bunzip2 XXX..bz2 xz compression generates the xz | decompression unxz XXX. XzCopy the code
Eg: 1. TXT file
Gz compressed file bzip2 1. TXT Generates 1.bz2 compressed file xz 1. TXT Generates 1.xz compressed fileCopy the code
File compression
Archive first and then compress
Archive compression: Add compression parameters to the -c archive command and add the compression parameters to the VF
The command | function |
---|---|
-z | The archive is compressed to.gz |
-j | The archive is compressed to.bz2 |
-J | Archive compressed to.tiz |
Eg: the lib directory
Gz lib Archive the lib directory and compress it into lib.gz sudo tar-cjvf lib.tar.bz2 lib sudo tar-cjvf lib.tar.xz libCopy the code
Unpack the archive
Decompress archive: Add compression parameters to the -x archive command and add the compression parameters to the VF
Gz sudo tar -xjvf lib.tar.bz2 Decompresses.bz2 sudo tar -xjvf lib.tar.xz Decompresses.xzCopy the code
4 Modify file permissions
Chmod space Parameter space File name whose permission you want to change
parameter | meaning |
---|---|
-u | The user |
-g | group |
-o | Other users |
-a | all |
permissions | role |
---|---|
– | Without permission |
r | read |
w | write |
x | perform |
Eg: 1. TXT file
TXT // Add the write permission for the owning user of the file chmod g-r 1. TXT // Reduce the read permission for the owning group of the file chmod o-w 1. TXT // Reduce the write permission for other users of the fileCopy the code
5 Linked Files
Command ln
The command | role |
---|---|
– | Common file |
b | Block device file |
s | Socket files |
p | Pipeline file |
l | Link to the file |
c | Character device file |
d | Directory file |
5.1 Hard Link and Soft Link
Link files are classified into soft link files and hard link files. Soft link files are similar to shortcuts in Windows
Create a hard link file
Ln Indicates the name of the hard link to be generated for the source file
Ln XXX SSS The hard link file for creating the XXX file is named SSS
Ln -s Specifies the name of the hard link file to be generated for the source file
Ln 1. TXT hh// Create the hard link hh of the 1. TXT file
Create a softlink file
Ln -s 1. TXT ss // Create the soft connection file ss of the 1. TXT file
Comparison of hard and soft links
Hard link file | Softlink file |
---|---|
Hard link file creation will == change == number of source files and children | Soft link file creation == Unchanged == Number of source files and children |
The source file is the same as the hard link file ionde | The iNode number of the softlink file is different from that of the source file |
Data modification in source files or hard link files affects each other | Data modification in source files or soft link files affects each other |
Delete source file hard link file is still valid == = | If the soft link file is deleted from the source file == Invalid == |
πinode is an index node that stores basic information about files and directories, including time, file name, user, and group.
6 Command for viewing files
The command | role |
---|---|
ls > filename | Redirects the output printed by ls to filename |
cat file1 > file2 | Redirect the result of cat file1 to file2; If file2 does not exist, create it |
> | Data redirection |
>> | additional |
diff file1 file2 | Compare two files for consistency; Consistent no print; Inconsistent Print the corresponding line number and content |
head | The first 10 lines of the default print file can be modified by parameter |
head filename | Prints the first 10 lines of the filename file to the terminal |
head -n filename | Prints the first n lines of the filename file |
tail | By default, the last 10 lines of the print file to the terminal can be modified by parameter |
tail filename | Prints the contents in the last 10 lines of the filename file to the terminal |
tail -n filename | Print n lines after the filename file |
cat /etc/passwd > file | Redirect the /etc/passwd data to the current path file |
π exercise: Display line 20 of the file to the terminal using head and tail
head -20 file | tail -1
Will be 20 lines before the file to the 20 lines as the input parameter of tail – 1 the last line, as a result, the file file line 20, pipe |.
7 File content search
-
β grep
Grep Space “Contents to Be searched” Space Space of the file to be searched -rn
Grep “systemd” file -rn // Search for the location where “systemd” appears in the file // and print the line number
-r indicates that all directories in the current path will be searched
-n Displays the line number
Specify the file name to search within the specified file
π’ Note: \ : escape character, grep retrievals the string [] as a special symbol so need to escape a[10]
8 User Management
In Linux, add the user name adduser to change the user name to the root user
Su root or sudo -i
The newly added user does not have sudo permission. You need to configure /etc/sudoers
Add operation rights for a new user
Because the /etc/sudoers file is read-only, you need to change the file permissions
π’ Note: ***** Do not chmod 777 /etc/sudoers chmod u+w /etc/sudoers
vi /etc/sudoers
- Copy root ALL=(ALL:ALL) ALL
- Paste it under root ALL=(ALL:ALL) ALL
- Change the new replication line root to the new user name
- Save the exit
Exit root user exit or su Linux
Switch to new user su. New user name. New user can use sudo
β