Mac terminal learning

Command 1:ifconfig
Function: List all network devices on this machine and their configurations, mainly referring to ip address and mac address
Insert image description here
Other usages: sudo ifconfig en4 add 10.10.10.12 netmask 255.255.255.0
Function: Add another network segment to en4
Insert image description here
Other usages: sudo ifconfig en4 delete 10.10.10.12
Function: Delete the specified network for en4 Paragraph
Insert image description here
Other uses:

ifconfig en0 down // 关闭网卡设备(这里假设是en0)
ifconfig en0 hw ether [MAC地址] // 修改MAC地址
ifconfig en0 up // 重启网卡

Function: Temporarily modify the MAC address

Other uses:

ifconfig en0 down
ifconfig en0 192.168.169.245 netmask 255.255.255.0

Function: Temporarily modify the intranet IP address

Command 2:ping
Function: Check whether the network is connected

Insert image description here
If it can be pinged, it means that their gateways are connected. Of course, you can also use it to detect whether the external network is connected.

Command 3:netstat
Function: Display various network-related information

Other usages:netstat -l
Function: List the ports that this machine listens on

Other usages:netstat -lt
Function: Only list tcp connections. Similarly, if l is followed by u, various udp listening ports will be listed

Other uses:netstat -s
Function: View statistical data

Other uses:netstat -p
Function: List process information, you can understand which program is doing what on which port

Other usages:netstat -pc
Function: Displays real-time updated process information

Other usages:netstat -r
Function: View routing table

Insert image description here
Other usages: netstat -i
Function: View interface information
Insert image description here


The commands we can execute in the terminal (ls cd cp mv, etc.) are all small programs placed under /bin.
The reason why it can be run directly is that there is no need to add a directory in front of it.
This is because these directories are added to the environment variable PATH

Command 1:set | grep PATH
Function: View environment variables
Insert image description here
Although there are many things, you can see that colons are used to separate them a>

Command 2:PATH=$PATH:~/bin
Function: Add other folder paths (bin directory under the local user) to PATH
Tips: In this case, it will still not work in the terminal we just logged in. If you If you want it to take effect immediately, you can use the source command. We enter the command 2 just now, then save and exit (use: wq under vim) If we want to customize our own profile, we can create a new file in our home directory and name it: .profile. This file will be automatically executed when you open the terminal. this file will be executed by anyone who opens the terminal. It is a system-level profile. In
This is only a one-time operation, which means that it can take effect directly in the current terminal, but when you close and reopen the terminal, this operation will not be saved.
/etc/profile


Command 3:source
Function: Make Shell read the specified Shell program file and execute all statements in the file in sequence. It is usually used to re-execute the initialization file just modified to make it It takes effect immediately without having to log out and log in again
For example: source .profile
At this point, every time you open the terminal, it will be executed by default< a command in i=4>. .profile

Guess you like

Origin blog.csdn.net/weixin_43233219/article/details/134165583