First introduction to Linux (Part 2). Mom no longer has to worry about me finding the way to Linux.


Preface

"I will regularly share my study and work experience, and welcome everyone to leave messages and communicate so that we can learn and make progress together! Thank you for your support!"


Series of articles

First introduction to Linux (Part 1). My mother no longer has to worry about me finding the way to Linux.

First introduction to Linux (Part 2). My mother no longer has to worry about me finding the way to Linux.

First introduction to Linux (Part 2). My mother no longer has to worry about me finding the way to Linux.

1. Date and time related instructions

1.1 date

Syntax: date display

date specifies the format to display time: date +%Y:%m:%d
date usage: date [OPTION]… [+FORMAT]

1. In terms of display, the user can set the format to be displayed. The format is set to a plus sign followed by several marks. The list of commonly used marks is as follows:

%H :: 小时(00..23) 
%M : 分钟(00..59) 
%S : 秒(00..61) 
%X : 相当于 %H:%M:%S 
%d : 日 (01..31) 
%m : 月份 (01..12) 
%Y : 完整年份 (0000..9999) 
%F : 相当于 %Y-%m-%d

1.2 In terms of setting time

date -s //设置当前时间,只有root权限才能设置,其他只能查看。
date -s 20080523 //设置成20080523,这样会把具体时间设置成空00:00:00 
date -s 01:01:01 //设置具体时间,不会对日期做更改
date -s “01:01:01 2008-05-23″ //这样可以设置全部时间
date -s “01:01:01 20080523″ //这样可以设置全部时间
date -s “2008-05-23 01:01:01″ //这样可以设置全部时间
date -s “20080523 01:01:01″ //这样可以设置全部时间

Examples are as follows:

Import entrydate
Insert image description here
Import entry
date +%Y-%m
Insert image description here

Input
date +%Y-%m-%d_%H:%M:%S
Insert image description here
format can be freely controlled

Inputdate +%Y:%m-%d_%H/%M-%S
Insert image description here
Time is a very important concept, such as checking logs


1.3 Timestamp

Time->Timestamp: date +%s
Timestamp->Time: date -d@1508749502
Unix timestamp ( Unix epoch, Unix time, POSIX time or Unix timestamp in English) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), regardless of leap seconds.

Examples are as follows:

You can see that every time I enterdate +%s, the number printed below is increasing. This number is the timestamp
Insert image description here
So how to convert the timestamp?
Enter·date +%Y:%m-%d_%H/%M-%S -d @0
Insert image description here


2. Cal command

Command format: cal [parameter][month][year]

Function: Used to view calendar and other time information. If there is only one parameter, it represents the year (1-9999). If there are two parameters, it represents the month and year.

Common options:

-3 显示系统前一个月,当前月,下一个月的月历
-j  显示在当年中的第几天(一年日期按天算,从1月1号算起,默认显示当前月在一年中的天数)
-y  显示当前年份的日历

Examples are as follows:

Insert image description here
Enter a year and display all months of that year
Insert image description here

Similar to windows

Insert image description here


3. find command: (very important) -name

Syntax: find the path you want to find -opt(name) filename

Function: Used to search for files in the file tree and process them accordingly (possibly accessing the disk)
Common options:

actually searches for files in the tree structure of the system, so the search is relatively slow.
But the second search is faster because the historical results of the last query will be cached by the operating system when find is running.

The find command under Linux searches for files in the directory structure and performs the specified operation.
The find command under Linux provides quite a lot of search conditions and is very powerful. Because find has powerful functions, it also has many options, most of which are worth our time to understand. Even if the system contains a Network File System (NFS), the find command is also valid in the file system, as long as you have the corresponding permissions. When running a very resource-intensive find command, many people tend to execute it in the background, because traversing a large file system may It will take a long time (here refers to file systems above 30G bytes).



Examples are as follows:

Start searching from the root directory:
Insert image description here
Start searching from If you specify a path, it is equivalent to searching only The path under this path is equivalent to only searching for sub-paths, so the search is faster. /root/a
Insert image description here

Similar to windows

Insert image description here


4. grep command

Syntax: grep [options] Search string file

Function: Search for a string in a file and print out the found lines

Common options:

-i :忽略大小写的不同,所以大小写视为相同
-n :顺便输出行号
-v :反向选择,亦即显示出没有 '搜寻字符串' 内容的那一行

Examples are as follows:

Display the contents of "321.txt" in the specified file line by line according to the corresponding keyword "999"
Insert image description here

Similar to windows

You can press the ctrl + f shortcut key in Notepad to find content
Insert image description here


5. zip/unzip command:

Syntax: zip compressed file.zip directory or file

Function: Compress directories or files into zip format

Why package and compress?

1. Reduce the size, occupy less disk space, and download quickly
2. Files will not be lost easily
If the command is not found, you need to An Zhaoyum install -y unzip zip

Examples are as follows:

Package directory a asa.zipNote that only the directory is packaged, which is an empty directory
Insert image description here
Then how to package the directory, including this directory What about all the content?
Use -r, for example, package a as a2.zip
Enterzip -r a2.zip a

Insert image description here
If you want to decompress other directories, you can use -d,x
, such as decompressing a2.zip into directory b; < a i=3> Enter and check in the b directory and you will find that everything is decompressed, which also proves that the previous compression is indeed all compression
unzip a2.zip -d b
Insert image description here
treea
Insert image description here

Similar to windows

Insert image description here


6. tar command (important): pack/unpack, don’t open it, look at the content directly

Syntax: tar [-cxtzjvf] files and directories...
Common parameters:

-c :建立一个压缩文件的参数指令(create 的意思);
-x :解开一个压缩文件的参数指令!
-t :查看 tarfile 里面的文件!
-z :是否同时具有 gzip 的属性?亦即是否需要用 gzip 压缩?
-j :是否同时具有 bzip2 的属性?亦即是否需要用 bzip2 压缩?
-v :压缩的过程中显示文件!这个常用,但不建议用在背景执行过程!
-f :使用档名,请留意,在 f 之后要立即接档名喔!不要再加参数!
-C : 解压到指定目录

Examples are as follows:

Combination optionsczf (fixed writing method) c: Create a new z: Compressed package f: File If you want to view the process, add vThat's it a>cvzfDecompression is the same, the suffix file istgz/tar.gz
Insert image description here

If you want to decompress, just change czf to xzf
Note: I will change a>test.tgz was moved to the b directory usingmv

Insert image description here

Extract to the specified directory, use-C+路径
to entertar -xzf test.tgz -C new
Note: c must be capitalized

At this point we enter the new directory and tree to verify

Insert image description here


7. bc command:

The bc command can easily perform floating point operations
It is indeed the calculator in the Linux system

Examples are as follows:

Insert image description here
Note: Press ctrl+c or enter quit to exit
Insert image description here
You can use echo Perform a calculation with|


8. uname –r command:

Syntax: uname [options]

Function: uname is used to obtain information about the computer and operating system.

Common options:

-a or –all output all information in detail, in order: kernel name, host name, kernel version number, kernel version, hardware name, processor type, hardware platform type, operating system name

Additional explanation: uname can display basic information such as the version of the operating system used by the Linux host and the name of the hardware.

Examples are as follows:

Inputuname - rCorresponds to the selected kernel version of the current Linux operating system
Insert image description here
View the current system versioncat /etc/redhat-release
Insert image description here
View the current CPU Informationcat /proc/cpuinfo
Insert image description here
View current memorycat /proc/meminfo
Insert image description here

Similar to windows

Insert image description here


9. Several important hotkeys [Tab], [ctrl]-c, [ctrl]-d

[Tab]按键---具有『命令补全』和『档案补齐』的功能
[Ctrl]-c按键---让当前的程序『停掉』
[Ctrl]-d按键---通常代表着:『键盘输入结束(End Of File, EOF 或 End OfInput)』的意思;另外,他也可以用来取代exit

[Tab]+[Tab] auto-complete

Insert image description here
When the last inputwhoa is completed, whoami will be added

Ctrl+R searches historical commands

Recall historical input commands through input command fragments


10. Shut down

If it is a cloud server, it is not recommended to shut it down.

Syntax: shutdown [options] ** Common options: **

-h : 将系统的服务停掉后,立即关机。
-r : 在将系统的服务停掉之后就重新启动
-t sec : -t 后面加秒数,亦即『过几秒后关机』的意思

file transfer

Linux to Windows connection

Upload from Linux to Windows: sz file name
Upload from Windows to WIndows: rz

Linux to Windows connection

scp file name root@public network ip:/path


Conclusion

Thank you for reading my blog, I hope you can get some inspiration and help from it. If you enjoyed this blog, please share it with your friends and family, and please leave your comments and feedback. Your support is my motivation to continue sharing and creating. Thanks! Hope we can see each other again in a future blog. I wish you all the best and look forward to seeing you again!
————————————————

Guess you like

Origin blog.csdn.net/2203_75397752/article/details/134739052