Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the commands about system status in Linux

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you what the Linux commands about the status of the system, I believe most people do not know much, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Check the running time of the system-uptime

Sometimes we want to know when the system was last reset or how long the system has been running, we can get this information through the uptime command:

Uptime20:47:06 up 50 min, 1 user, load average: 0.75, 0.84, 0.93

The information displayed from left to right is the current time, the running time, the number of user logins, and the average load of the system in 1 minute, 5 minutes, and 15 minutes.

View the logged-in user of the system-- who

Who-ahyb tty7 2018-09-30 19:57 (: 0)

The who command allows you to see which users have logged in to the host through which ip.

View information related to the system version-uname

For example:

Uname-aLinux ubuntu16.04 4.15.0-34-generic # 37~16.04.1-Ubuntu SMP Tue Aug 28 10:44:06 UTC 2018 x86 "64 GNU/Linux

From the results, you can see the operating system version (ubuntu16.04), CPU type (x86 / 64) and other information.

View the current environment variable-export

Environment variables affect the operation of the program, so sometimes you need to look at the environment variables of the current environment:

Export

View directory and file footprint-du

The du command directly displays the space occupied by each directory and its files under the current directory. Combined with the-- max-depth parameter, you can specify the directory level that is displayed.

For example, if you only want to display the total space occupied by each directory under the current directory, you can use:

Du-h-- max-depth=1 19m. / python 9.0m. / git 321M. / hexo 17M. / lua 28K. / vim 1.4m. / shell 81m. / redis 316m. / books 48m. / c 810M. Du-sh # only counts the total size of the current directory 810m

Where-h indicates that the size is displayed in easy-to-read units, that is, MMagi Murray Maxwell depthods 1 indicates the directory level. From the command results, we can see the amount of space occupied by each subdirectory under the current directory, as well as the total space size.

View the space of each mount point-df

For example:

Df-h file system capacity used available mount point udev 3.9G 0 3.9G 0 / dev tmpfs 786M 9.5M 776m 2% / run / dev/sda10 24G 9.8G 13G 45% / tmpfs 3.9G 43m 3.8G 2% / dev/shm tmpfs 5.0M 4.0K 5.0m 1% / run/lock tmpfs 3.9G 0 3.9G 0% / sys/fs/cgroup / dev/sda11 454M 274M 153M 65% / boot/ dev/sda15 55G 5.2G 47G 10% / home / dev/sda1 256M 31M 226M 12% / boot/efi / dev/sda14 4.6G 9.9M 4.4G 1% / tmp tmpfs 786M 60K 786m 1% / run/user/1000

From the results, we can see the total space and available space for each mount point. When the disk file takes up a large amount of space, it may cause the system to run slowly, so you can clean up the disk accordingly according to the result.

Check the memory availability-- free

The free command can be used to display the physical memory available on the system, swap memory, and the buffer used by the kernel:

Free-h total used free shared buff/cache available Mem: 7.7G 2.3G 2.6G 268m 2.8G 4.7G Swap: 7.6G 0B 7.6G

From the execution results, you can see the situation of used memory and free memory. Similarly, when there is insufficient memory, it may cause the program to run abnormally or the system to stutter.

Check the memory usage of the process-- pmap

The pmap command is used to view information about process memory:

Pmap pid # pid is the process id You can obtain 6030:. / main 00000000400000 4K rmurmuri-main 00000000600000 4K rashashi-main 0000000000601000 4K rw--- main 00000000017d2000 132K rw--- [anon] 00007fc3843e8000 1792K Rafael-libc-2.23.so 00007fc3845a8000 2048K-libc-2.23.so 00007fc3847a8000 16K Rafue-libc-2.23.so 00007fc3847ac000 8K rw--- libc-2.23.so 00007fc3847ae000 via ps command 16K rw--- [anon] 00007fc3847b2000 152K Rafael-ld-2.23.so 00007fc3849b9000 12K rw--- [anon] 00007fc3849d7000 4K Rafaq-ld-2.23.so 00007fc3849d8000 4K rw--- ld-2.23.so 00007fc3849d9000 4K rw--- [anon] 00007ffcf2018000 132K rw--- [stack] 00007ffcf2175000 12K Rafael-[anon] 00007ffcf2178000 8K Rafael-[ Anon] ffffffffff600000 4K rmurxmuri-[anon] total 4356K

We can constantly optimize our program according to the space occupied by each part of the process.

View virtual memory statistics-vmstat

Vmstat procs-memory- swap---io-----system---cpu- r b swpd free buff cache si so bi bo in cs us sy id wa st 2214960 407828 2572148 00 126 57 377 1006 82 88 2 0

The output value of vmstat can help us understand the performance of the current system. For example, if the values of si (the amount of memory written from the swap area to memory per second) and so (the amount of memory written to the swap area per second) are often greater than 0, there may not be enough memory, so swap space is needed. For example, when the value of us (percentage of user process execution time) is high, it means that the user process consumes more CPU resources. When the value of wa (percentage of IO wait time) is high, it indicates that the IO wait situation is serious.

Check the ip address-- ip

Sometimes you may not be able to see all the ip addresses using the ifconfig command, so you can use:

Ip addr

Check the network connection status-- netstat

The netstat command can view the network connection status and is usually used to diagnose network-related problems. For example, check whether the port is occupied, whether the connection has been released, whether the service is listening, and so on.

View the relationship between processes-- pstree

The parent-child relationship between processes can be seen through the pstree command, which displays this information in a tree structure:

Pstree systemd ─┬─ ModemManager ─┬─ {gdbus} │ └─ {gmain} ├─ NetworkManager ─┬─ dhclient │ ├─ dnsmasq │ ├─ {gdbus} │ └─ {gmain} ├─ accounts-daemon ─┬─ {gdbus} │ └─ {gmain} ├─ acpid ├─ atd ├─ avahi-daemon ─── avahi-daemon ├─ bluetoothd ├─ colord ─┬─ {gdbus} │ └─ {gmain} ├─ cron ├─ cups-browsed ─┬─ {gdbus} │ └─ {gmain} ├─ cupsd ─── 3 * [dbus] ├─ dbus-daemon ├─ gnome-keyring-d ─┬─ {gdbus} │ ├─ {gmain} │ └─ {timer} (only part of the content is displayed)

Summary

In fact, many of the relevant command information mentioned earlier are obtained from system files, for example, / proc/meminfo saves memory-related information and / proc/net/dev saves network traffic-related information. However, they are all static values, but we can observe this information dynamically in combination with the watch command, such as:

Watch-n 1 cat / proc/meminfo watch-n 1 cat / proc/net/dev

The above command indicates that cat / proc/meminfo or cat / proc/net/dev is executed every second, so we can see the memory information or Nic traffic information refreshing in real time.

The above is all the contents of the article "what are the commands about system status in Linux?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report