linux_4 practical operation

Practical operation

hot key

If you enter a wrong command, or the program wants to stop early, you can press ctrl+c to stop it forcibly.

ctrl+d can log out of the current account, or exit the exclusive page of the current program.

historyView the commands entered in history.

! can automatically match the content of the last input, matching the prefix. If entered !p, the last entered command beginning with p is pythonwill be executed python.

But this bottom-up matching is not so convenient. If you want to find a historical record farther away, you can use ctrl+r, similar to the ctrl+f we usually use.

Cursor movement: ctrl+a is home, ctrl+e is end, ctrl+← is the cursor jumps a word to the left, ctrl+→ is a word to the right.

ctrl+l or clear to clear the screen.

Software Installation

The installation package, such as the .exe file or .msi file commonly downloaded by windows, click to install. Mac commonly used dmg pkg files.

Linux is rpm, deb files, centos is installed through yum, and ubuntu is installed through apt.

yum

yum [-y] [install | remove |search] fileName

-y: confirm without order, install directly.

yum requires networking and needs root or sudo privileges.

apt

apt [-y] [install | remove |search] fileName

systemctl

Many software in linux use systemctl to start, stop, and start automatically.

systemctl start | stop| status | enable | disable 服务名

enable disable is used to adjust whether to boot automatically.

Services such as:

  • NetworkManager main network service

  • network Secondary network service

  • firewalld firewall

  • sshd, ssh service (finalshell is used to remotely control linux service)

status has active and inactive.

Many systems or third-party software are automatically inherited from systemctl. But there are many not, and I will talk about how to deal with this kind of software later.

soft link

Link files and folders to other locations, similar to windows shortcuts.

ln -s 被链接的文件或文件夹 要链接到的目的地

date and time zone

date [-d] [+格式化字符串]

image-20230319160307898

likedate "+%H-%M-%S"

-d can perform date calculations, such as:

date -d "-1hour" "+%H-%M-%S", based on the current time -1.

image-20230319160715459

modify time zone

Delete the current time zone file first.

rm -f /etc/localtime

Then pick Shanghai from the time zone file and create a soft link.

ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

ntp automatically calibrates system time

First the ntp program needs to be installed.

Then systemctl start ntpd system enable ntpdntpd will automatically connect to the Internet to help us calibrate the time.

It seems that the ubuntu system needs to enter ntp to start the ntp service? Or is this the setting of the new version of ntp? Anyway the code I execute issystemctl start ntp

Manual update time: ntpdate -u ntp.aliyun.com(ntpdate seems to be updated too)

network transmission

IP

The IP address is unique to each networked computer to identify itself and communicate with other computers.

There are two versions, V4 and V6, and V6 is not commonly used.

An IP address is a combination of four numbers from 0 to 255. It can be viewed through ifconfig (you need to install net-tools if you can’t view it), the main network card: the inet option in ens33 is the IPV4 address. The lo network card is the local loopback network card, and the virbr0 is the dedicated network card for the virtual machine.

127.0.0.1: refers to the local machine.

0.0.0.0: Refers to the local machine; or determines the binding relationship in port binding; or indicates that all IP addresses are released in some IP restrictions.

the host

In addition to the IP address, each computer has its own name called a hostname. linux input hostnameview .

image-20230320103048195

You can modify the current host name hostnamectl set-hostname newNamethrough , and you need to log in to finalshell again to view it.

DNS

We know that generally we visit websites through domain names that are easier to remember (such as www.baidu.com).

Domain names and IPs are mapped through the DNS system. First check whether the local DNS library has a record of the domain name to be accessed, and if not, go to the DNS public server to find the address.

The windows local domain name storage file is in: C:\Windows\System32\drivers\etc\hosts, and the linux is in/etc/hosts

When we set up the mapping between linux IP address and domain name locally in windows, we can input the host name instead of the IP address when connecting through finalshell.

Configure a fixed IP address

The IP address of linux is dynamically obtained through DHCP, so the domain name mapping we configured cannot be applied as it is updated, and needs to be changed frequently.

VMWare WorkStation - Edit - Virtual Network Adapter - VMnet8, the subnet is set to 192.168.88.0, the subnet mask is 255.255.255.0, and the NAT setting is 192.168.88.2

image-20230320105512706

The ubuntu system is different here, it is configured /etc/network/interfacesin .

And if we are using the desktop version of ubuntu, it is not configured here. Refer to this article: Ubuntu Server20.04 static ip configuration (netplan)_Brady-wdh's Blog-CSDN Blog

ethernets: ens33: # 配置的网卡名称,可以使用ifconfig -a查看本机的网卡 dhcp4: no # 关闭动态IP设置,因为要设置固定IP addresses: [192.168.88.130/24] # 要设置为的固定IP,后面的24为子网掩码的位数 gateway4: 192.168.88.2 # 要设置的网关地址 nameservers: addresses: [192.168.88.2,8.8.8.8] # 要设置的DNS地址 ———————————————— 版权声明:本文为CSDN博主「Brady-wdh」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/qq_45949008/article/details/118862854

In the end systemctl restart network, netplan is: netplan generategenerate the required configuration for the renderer, netplan applyapply the configuration for the renderer.

After that, ifconfig has been fixed at 192.168.88.130 and will not change.

ping

Test whether the server is reachable by pinging.

ping [-c num] IPAddress, -c is to limit the number of pings, if not limited, it will check infinitely.

Here we can first add vim /etc/resolv.confin nameserver 8.8.8.8, which is the IP address of a free DNS server provided by Google, which should be able to resolve the mapping of domain names such as baidu.

If unable to ping: display unreachable.

wget

Non-interactive download tool.

wget [-b] url, -b is to download in the background, and save the download information to the wget-log file in the current working directory. You can keep track with tail -f.

curl

Send http requests to get information or download files.

curl [-O] url

-O: Download the file.

For example curl cip.cc, the website will tell us the public IP address of the machine.

port

Physical port: Visible, such as a USB port.

Virtual port: The internal port of the computer, invisible, and used by the operating system to interact with the outside world.

image-20230320181540486

The IP address is the address of a community, the program is the resident, and the process is the house number used to find each user.

image-20230320183846899

Linux uses the nmap command to view the exposed ports of the specified host.

nmap 被查看的 IP

22: ssh port. finalshell remote connection will be used.

netstat: View port usage.

netstat -anp | grep portNo

process management

In order to facilitate management, the operating system assigns process IDs to running programs.

ps [-e -f]View process information.

-e: View all processes.

-f: View all information.

  • PPID: Parent process ID.

  • C: CPU usage.

  • STIME: start time.

  • TTY: The serial number of the terminal that started this process, ? Indicates that it was not started by the terminal.

  • TIME: Accumulated CPU usage time.

  • CMD: Launch command or path.

shutdown process: kill [-9] PID, -9 force shutdown. If it is not forced to close, it just sends a close request, not necessarily closed. For example, tail will be terminated automatically after receiving the kill command, but if it is forced to close, it will be killed.

Host status monitoring

View system resource usage

top command, refresh every 5s, similar to task manager.

image-20230323184326044

image-20230323232340079

image-20230323233928213

image-20230323234504022

View disk usage

df [-h], -h is displayed in KMG units.

View disk speed

iostat [-x] [num1] [num2], -x displays more information, num1 refresh interval, num2 refresh times.

Check network status

sar, the command is more complicated. Therefore, to deal with network statistics, we only remember a fixed syntax:

sar -n DEV num1 num2, -n means to view the network, and DEV only views the network interface. num1 refresh interval, num2 refresh times.

environment variable

We know that instructions are executable programs one by one, which can be found.

But why can the instruction be executed without jumping to a specific directory? Like windows, thanks to environment variables.

Environment variable is a key-value pair structure, which records a series of key information needed for system operation. You can use envthe command to view.

Among them, PATH stores a series of instruction search paths.

Add the $ symbol at the beginning of the environment variable to get the value of the environment variable. Can be used in conjunction with echo. Such as: echo ${PATH}ABC.

In this way, we can add our own program to the environment variable, or put the program under the PATH path.

Setting environment variables takes effect temporarily:export virableName virableValue

Permanently effective for the current user: in the ~/bashrc file.

Permanently valid for all users: in /etc/profile.

You can pass source 配置文件or restart finalshell to take effect immediately.

Configure PATH: echo PATH, export PATH=$PATH:路径, or add the following sentence to the user or system environment variable.

Write $PATH: here first, in order to splice with the previous PATH value, this step must not be ignored.

finalshell transfer files

Right-click the file to download the file from the virtual machine to the local. Which account is used to log in, what you see is the content that can be seen by that account.

Upload: Drag and drop local files directly into finalshell.

Or download the lrzsz command. Download: sz 文件; Upload: rz, a file box will automatically pop up randomly for selection.

However, the drag and drop efficiency of uploading large files is > rz.

compression decompression

image-20230324012526297

tar: Simple assembly of files, there is no big difference in size before and after compression.

tar.gz: The compression algorithm is used, which is greatly reduced.

tar [-c -v -x -z -C -f]Can be decompressed or compressed.

-c: compression.

-v: Show progress.

-v: decompress.

-z: Added is gzip mode, not added is tarball mode.

-C: decompress destination.

-f: refers to the file to be created/decompressed.

Directives can be combined, but -z must be at the beginning and -f must be at the end. liketar -zcvf 1.tar.gz 1.txt 2.txt 3.txt

-C should be written separately.tar -zxvf test.tar.gz -C /home/jingqing

zip is compressed, and -r can be added to represent recursive processing of folders.zip -r test.zip /test 1.txt

unzip decompresses the zip file, -d specifies the address similar to -C.unzip test.zip -d /home/jingqing

Guess you like

Origin blog.csdn.net/jtwqwq/article/details/129742879