[Linux Advanced Road] Basic Instructions (Part 2)

1. Log

One picture to understand the log :
Insert image description here

date command - view date

Directly enter the date command
Insert image description here

Illustration:
Insert image description here

  • This is different from what we usually see. Can it be output in the format we want?

Basic grammar 1

  • date + (cannot be omitted) FORMATE
  • Common options:
  • %H : hours (00…23)
  • %M: Minutes (00…59)
  • %S: seconds (00…61)
  • %X: equivalent to %H:%M:%S
  • %d: day(01…31)
  • %m: month (01…12)
  • %Y: Complete year (0000…9999)
  • %F: equivalent to %Y-%m-%d

Options can be used contiguously
. So: can be used like this.
Insert image description here
Because %F is equivalent to %Y-%m-%d, of course it can also be used in this way.
Insert image description here
Special attention is that - the + sign needs to be added after the date command.

Basic Grammar 2

  • Timestamp - A verifiable piece of data that exists at a specific point in time (the number of seconds from 0:00:00 a.m. on January 1, 1970 Green Time to the present )
  • date +%s - View the current timestamp
    Insert image description here
  • It can be seen that the values ​​here show an increasing relationship.
  • How to convert timestamp to current time?
  • Instruction: date -d @timestamp
    Insert image description here
    So how to convert it to the time we want to see?
  • Command: date format you want to convert -d @timestamp
    Insert image description here
    What about the timestamp at 0?
    Insert image description here
    Why not 0 o'clock? Because this is Chinese time, it takes 8 hours to convert from Green Time to Chinese time , so it is naturally 8 o'clock here.

cal command - view calendar

  • Calendar - The cal command can be used to display the Gregorian (Gregorian) calendar. The Gregorian calendar is the calendar currently used internationally, also known as the Gregorian calendar and commonly known as the Gregorian calendar. The "Gregorian calendar", also known as the "solar calendar", is based on the earth's orbit around the sun as one year. It is common in Western countries, so it is also called the "Western calendar".
  • Use cal instruction directly:
    Insert image description here

It will print out the calendar of the current month and display the date of today (I am blogging) - the 17th

Common options

Insert image description here

  • Supplement: cal + specific year - displays the calendar for the specified year.
    Insert image description here
  • Shown here is the calendar for 2022.

2.find - find files

  • Syntax find [directory] [options] [file to find]

Common options

-name

Show all files

Insert image description here

Display files of specified type

Example one:
Insert image description here
Example two:
Insert image description here

  • Here is the file to find test.c
  • illustrate:
    1. find actually searches for files on the disk .
    1. Which searches for instructions under the instruction file (/usr/bin).
    1. Whereis searches for files under a specific path . This specific path generally refers to - /usr/, looking for source files, compressed packages, binary files, installation packages and other files.

3. grep - line text filtering tool

grammar

  • grep [options] [content] [specified file]

Common usage

  • In order to better understand the following content, we first give the content of the specified file:
    Insert image description here

  • Find the contents of a specified file
    Insert image description here

  • Find contents except the specified file

  • Options: -v
    Insert image description here

  • Print the line number of the specified file content

  • Options: -n
    Insert image description here

  • Filter by ignoring case

  • Options: -i

Insert image description here

Supplementary knowledge - the connection between APP and server

Insert image description here

4. Packaging, compression and decompression

In order to better understand the following concepts, we can think of the process of your mother helping you pack your luggage.
Suppose your father helps you pack your things into the suitcase, and your mother helps you organize and arrange them - making reasonable use of space. At this time, the things are the same but smaller in size. When you get to school, they are smaller again. You need to open the suitcase again and put the things in their proper places. Such a process embodies packaging, compression, decompression and unpacking.

  • Packing – putting things into one piece.
  • Compression - rational use of space, putting things together, reducing space - the original 1M compression may become hundreds of KB.
  • Unpack – unpack your luggage.
  • Unpack – Put the items in your luggage where they belong.
  • illustrate:
  • The essence of packaging and compression is to turn multiple files into one file, which will not easily cause the loss of files. At the same time, the reduction of storage space will also improve the efficiency of downloading, thereby reducing time.

zip and unzip

  • Note: Some LInux may not have these two instructions, so you need to switch to the root user and use yum to download.
  • Command: yum install -y zip unzip

zip

In order to use zip we first create some files:
Insert image description here
at this point we pack and compress dir1

  • Operation: zip [file.zip] [specified file]

Insert image description here
We see that there is an additional file ending with .zip.

Move into another directory we create and move into this file:
Insert image description here

unzip

At this point we decompress and unpack the compressed package

  • Operation: unzip [compressed package]

Insert image description here

  • It's strange that there is no compression at this time!
  • why is that?
  • The reason is simple - this is because the default packaging will only be packaged as files, and files in directories will not be packaged.
  • So what to do?
  • Action: -r option

Since it is the same as the previous zip operation, the zip operation here is omitted.
Here we still move the compressed package to this directory.
Insert image description here
Now decompress dir.zip:
Insert image description here
Create a directory and decompress it to the specified directory.

  • Options: -d
    Insert image description here

tar

basic grammar

  • tar [options] [file] [file]

Common options

  • -z: Use .tar.tgz mode for compression
  • -f: Specify the name of the newly formed document.
  • -c: Pack and compress files
  • -x: Decompress and unpack files
  • -t: View compressed package file information
  • -C: Extract to the specified directory
  • uncommonly used:
  • -j: Does it also have the attributes of bzip2? That is, do I need to use bzip2 compression?
  • -v: Display files during compression! This is commonly used, but it is not recommended to be used in background execution processes!

Basic use

In order to better understand the instructions, we will give the operation file:
Insert image description here

-czf - Pack and compress files

Insert image description here

-tzf——View compressed package file information

Insert image description here

-xzf - decompress and unpack files

Insert image description here

5.bc - Linux calculator

Insert image description here

  • Usage: Just enter bc directly
  • Exit: Just enter quit

六.uname

  • Options: -a - show detailed information
    Insert image description here
  • Option -r - show version kernel
    Insert image description here

7. Commonly used hot keys

1.Tab——Complete the command

  • illustrate:

  • 1. If you directly press the Tab key twice, a line may appear here - whether to display all file commands. Enter y to print out all available commands.
    Insert image description here

  • 2. If the possibility of the command is not unique, all possible commands will be listed here.

Insert image description here

  • 3. If the possibility of a command is unique, the missing command letters will be added here.

Insert image description here

2.ctrl + r - search historical commands

Insert image description here

  • Note: The latest 1000 instructions are saved by default (can be modified) .

3.ctrl + d——Exit terminal login

Insert image description here

Supplement: Command line interpreter

Insert image description here

Guess you like

Origin blog.csdn.net/Shun_Hua/article/details/130730209