国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Table of Contents
2. top or htop : real-time monitoring is clearer
3. View /proc/meminfo : More detailed data sources
4. Other practical tips
Home System Tutorial LINUX How to check memory and swap usage from the command line?

How to check memory and swap usage from the command line?

Jun 19, 2025 am 12:10 AM
memory usage Use swap

Check memory and swap partition usage under Linux, and you can use the command line tool to quickly obtain information. 1. Use the free command to directly view the overall usage of memory and swap, such as: free -h; 2. Real-time monitoring is performed through top or htop to display dynamic data; 3. View /proc/meminfo file to obtain more detailed memory data; 4. Process memory query and system load analysis can be implemented in combination with ps, cat /proc/swaps and other commands, and sync and drop_caches can be used to clean the cache and release the memory. These methods are suitable for performance inspection and daily inspection, which facilitates remote operation and script development.

How to check memory and swap usage from the command line?

Checking the usage of memory and swap partitions under Linux, you can actually understand it without using a graphical interface. Command line tools are not only fast, but also come in handy on remote servers. The following commonly used commands can quickly grasp the current memory and swap usage status of the system.


1. free command: the most direct way

free is the easiest and intuitive way to view it quickly, and can display physical memory and swap usage.

Run this command:

 free -h
  • -h means "human-readable", displaying units (such as MB, GB) in an easy-to-read manner.

The output is roughly as follows:

 total used free shared buff/cache available
Mem: 7.7G 2.3G 4.1G 350M 1.3G 6.9G
Swap: 2.0G 0B 2.0G
  • The Mem line shows the total amount of physical memory, used, idle and other information.
  • The Swap line shows the usage of the swap partition. If you see that swap used is not 0, it means that the system has started to use swap space, which may mean that the memory is a bit tight.

2. top or htop : real-time monitoring is clearer

If you want to see dynamic memory usage, top is a good choice. run:

 top

You can see the memory and swap usage overview at the top:

 KiB Mem : 8050960 total, 4321234 free, 1234567 used, 2495159 buff/cache
KiB Swap: 2097148 total, 2097148 free, 0 used.
  • If you install htop (usually need to be manually installed), it will provide a more friendly interface and clearer colors, suitable for long-term observation.

3. View /proc/meminfo : More detailed data sources

The Linux system places a lot of runtime information in the /proc directory, and /proc/meminfo contains detailed memory usage data.

You can use cat to view:

 cat /proc/meminfo

There will be content like this:

 MemTotal: 8050960 kB
MemFree: 4321234 kB
Buffers: 123456 kB
Cached: 765432 kB
SwapCached: 0 kB
SwapTotal: 2097148 kB
SwapFree: 2097148 kB
  • This file is suitable for extracting specific values ??when writing scripts.

  • For example, if you want to obtain the currently available memory, you can use grep to extract it:

     grep MemAvailable /proc/meminfo

4. Other practical tips

Sometimes we want to know how much memory a process uses or how the overall system loads, we can combine the following commands:

  • Check the memory usage of a process (for example, the PID is 1234):

     ps -p 1234 -o %mem,rss
  • If you want to see the memory, swap and load situation at once, you can combine several commands:

     free -h && echo && cat /proc/swaps
  • Clean the cache and release memory (for test, frequent execution is not recommended):

     sudo sync; sudo echo 3 > /proc/sys/vm/drop_caches

    Basically these are the methods. Whether it is troubleshooting performance problems or daily inspections, mastering these commands is enough. Although it doesn't seem complicated, it is easy to ignore some details, such as unit conversion, whether it includes cache, etc., and just pay attention to distinguishing it when using it.

    The above is the detailed content of How to check memory and swap usage from the command line?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1502
276
How to view the memory usage graph on Redmi K70pro? How to view the memory usage graph on Redmi K70pro? Feb 11, 2024 pm 09:15 PM

Redmi K70Pro has attracted much attention and is known for its excellent processing performance and memory management capabilities. Understanding the memory usage of mobile phones is very important for users to help them optimize mobile phone performance and provide a smoother user experience. In this article, we will introduce how to use Redmi K70Pro to view memory usage graphs to help users better manage phone memory. How to view the memory usage graph on Redmi K70pro? 1. First turn on your Redmi K70 phone. 2. Swipe up on the home screen or tap the app library icon, find the "Settings" app and tap to enter. 3. In the settings menu, find and click the "About phone" option. 4. On the About Phone page, find the "Memory" or "Storage" option and click to enter. 5. In memory

CPython compared to other Python implementations CPython compared to other Python implementations Mar 06, 2024 pm 08:10 PM

CPython: Cpython is a reference implementation of Python, created by Guido van Rossum. It is written in C and uses a virtual machine to interpret Python bytecode. CPython is widely used in development and production and is available on most platforms. Performance: CPython is known for its excellent performance as it executes bytecode in machine code. However, due to its interpreted nature, it may not be as fast as other compiled implementations such as PyPy. Memory usage: CPython has moderate memory usage since it is an interpreter and needs to convert bytecode to machine code at runtime. Platform support: CPython supports a wide range of platforms, including windows and linu

How to debug memory usage of PHP functions with Blackfire? How to debug memory usage of PHP functions with Blackfire? Apr 23, 2024 pm 05:24 PM

How to use Blackfire to analyze the memory usage of PHP functions: Install Blackfire: Use the specified command to install. Configure Blackfire: Create the blackfire.yaml configuration file and set the server URL, client ID, client token, and log saving options. Annotate PHP functions: Add BlackfireProbe annotations around functions to record memory usage. Run Application: Execute your PHP application to generate analytics data. View the results: View the memory usage graph of the PHP function in the "Memory" tab in the Blackfire interface.

How to optimize and tune your Linux system's memory usage to improve performance How to optimize and tune your Linux system's memory usage to improve performance Jun 29, 2023 am 11:38 AM

How to optimize and tune the memory usage of your Linux system to improve performance Summary: Linux is a commonly used operating system, but it may experience performance degradation after running for a long time. This article will introduce some methods to optimize and adjust the memory usage of Linux systems to improve system performance. Use Swap partition more: Swap partition is the virtual memory of Linux system. When the physical memory is insufficient, the system will save some data to the Swap partition. It is recommended to set a Swap partition equal to the physical memory size.

How to optimize memory usage in Redis How to optimize memory usage in Redis May 11, 2023 pm 03:22 PM

Redis is a popular open source in-memory database used in various application scenarios such as caching and message queues. Although Redis is an in-memory database, memory resources are limited, so optimizing memory usage is very important. This article will introduce how to optimize memory usage in Redis. Use appropriate data structures Redis supports a variety of data structures, including strings, hash tables, lists, sets, ordered sets, etc. Choosing appropriate data structures can significantly reduce memory usage. For example, if you store a set of unique values, you can use

How to measure and optimize memory usage of Java functions? How to measure and optimize memory usage of Java functions? Apr 21, 2024 am 09:51 AM

It is crucial to measure and optimize the memory usage of Java functions, and memory usage can be obtained through JMX. In order to optimize memory usage, you can use reference types, avoid memory leaks, and use pool mechanisms; actual cases show that through optimization technology, memory usage can be reduced from 150MB to 10MB, significantly improving function performance.

Optimize memory usage and garbage collection efficiency of Go language applications Optimize memory usage and garbage collection efficiency of Go language applications Sep 27, 2023 pm 11:27 PM

Optimizing memory usage and garbage collection efficiency of Go language applications Introduction: With the wide application of Go language in the fields of cloud computing and web application development, memory usage and garbage collection optimization are becoming more and more important. An efficient Go application can not only reduce resource usage, improve performance, but also reduce costs. This article will explore how to optimize the memory usage and garbage collection efficiency of Go language applications, and give specific code examples. 1. Reduce memory usage Using pointer types The pointer types of the Go language can reduce data copy overhead. In creation

How to check memory and swap usage from the command line? How to check memory and swap usage from the command line? Jun 19, 2025 am 12:10 AM

Check memory and swap partition usage under Linux, and you can use the command line tool to quickly obtain information. 1. Use the free command to directly view the overall usage of memory and swap, such as: free-h; 2. Real-time monitoring is performed through top or htop to display dynamic data; 3. View /proc/meminfo file to obtain more detailed memory data; 4. Process memory query and system load analysis can be implemented in combination with ps, cat/proc/swaps and other commands, and sync and drop_caches can be used to clean the cache and release the memory. These methods are suitable for performance inspection and daily inspection, which facilitates remote operation and script development.

See all articles