Linux Common commands

Source: Internet
Author: User

@ (Linux basics) [Ubuntu Optimizer]
Ubuntu optimization
----
[TOC]

Clears the residual profile for all deleted packages
dpkg|grep ^rc|awk'{print $2}'|sudo

If you report the following error, prove that there is no residual configuration file in your system, do not need to worry.

dpkg :--purge needs at least one package name Argumenttype  dpkg--help for help about installing and deinstalling packages [*] use   ' dselect   for user-friendly package management type  dpkg-dhelp for a list of dpkg debug flag values type  dpkg--force-help for a list of forcing Options type  dpkg-deb--help for help about manipulating *.deb files type  dpkg--license for copyright license and lack of warranty (GNU GPL) [*]. options  marked [*] produce a lot of output-pipe it through  '  Less! 
Clean up older versions of the software cache
sudo apt-get autoclean
Remove orphaned software that is no longer used by the system
sudo apt-get autoremove如果使用sudo apt-get autoremove --purge的话会把这些孤立软件的残留配置文件也一并移除
View the address of the package on the server
apt-get|cut -d\' -f2
View Kernel
uname -a
See if the system is 32-bit or 64-bit
#查看long的位数,返回32或64getconf LONG_BIT#查看文件信息,包含32-bit就是32位,包含64-bit就是64位file /sbin/init或者使用uname -m
View Ubuntu version
lsb_releasecat /etc/lsb-release
View kernel-loaded modules
lsmod
View Network card Status
sudosudo ethtool eth0
Activating the Wake-on-lan of the NIC
sudosudo ethtool -s eth0 wol g
View CPU Information
cat /proc/cpuinfo
View current hardware information
lshw
View Memory Models
sudo dmidecode -t memory
Get CPU serial number or motherboard serial number
#CPU IDsudo|grep ID#Serial Numbersudo dmidecode  |grep  Serial#CPUsudo dmidecode -t 4#BIOSsudo dmidecode -t 0#主板:sudo dmidecode -t 2#OEM:sudo dmidecode -t 11
Show current memory size
free|grep"Mem"|awk'{print $2}'

The free command provides a more concise view of system memory usage relative to top:
Free

 total used free shared buffers Cachedmem :                        255268 238332 16936 0 85540 126384-/+  Buffers/cache: 26408 228860swap : 265000 0 265000 

Related Instructions
Mem: for physical memory statistics
-/+ buffers/cached: indicates cache statistics for physical memory
Swap: Indicates the usage of the swap partition on the hard disk (we don't care about it here)
Total Physical memory of the system: 255268Kb (256M), But the actual memory currently available to the system is not the 16936Kb of the first line of the free tag, it represents only the memory that has not been allocated.
We use names such as Total1, Used1, Free1, Used2, free2 to represent the values of the above statistics, and 1, 2 represent the data for the first row and the second row respectively.
Total1: represents the total amount of physical memory.
used1: indicates that the total is allocated to the cache (containing buffers and cache), but that some of the caches may not be actually used.
free1: unallocated memory.
shared1: shared memory is not used by the general system and is not discussed here.
buffers1: The number of buffers that the system allocates but is not used.
cached1: number of caches that are allocated but not used by the system. The difference between buffer and cache is shown later.
Used2: The total amount of buffers and caches actually used, and the total amount of memory actually used.
free2: The sum of the unused buffers and the cache and unallocated memory, which is the current actual memory available to the system. The
organizes the following equations:

Total1 = used1 + free1
Total1 = used2 + free2
used1 = buffers1 + cached1 + used2
Free2 = buffers 1 + cached1 + free1
The difference between buffer and cache
buffer: The buffer is something that has not been "written" to the disk.
Cache: caching is something that is "read" from disk and stored for later use.
for shared memory , which is primarily used to share data between different processes in a UNIX environment, is a way to communicate between processes, and general applications do not request the use of shared memory. I also did not verify the effect of shared memory on the above equation.

The difference between cache and buffer:
Cache : caching is a small but high-speed memory that sits between the CPU and the main memory. because the CPU speed is much higher than the main memory, the CPU accesses the data directly from memory to wait for a certain period of time, the cache holds the CPU has just used or recycled part of the data, when the CPU re-use the part of the data can be directly called from the cache, This reduces the CPU wait time and improves the efficiency of the system. The cache is also divided into one-level cache (L1 cache) and level two cache (L2 cache), L1 cache is integrated within the CPU, L2 cache is usually soldered to the motherboard, and is now integrated into the CPU, with a common capacity of 256KB or 512KB L2 Cache.
Buffer : an area where data is transferred between devices that are not synchronized or that have different priority levels . Through buffers, you can reduce the number of waits between processes, so that when you read data from a slow device, the operating process of a fast device is uninterrupted.
Buffer and cache in free:
buffer: memory as buffer cache , is the read and write buffer of the block device.
cache: as the page cache memory, the file system cache

Note: If the cache value is large, the cache has many files. If the files that are frequently accessed are available to the cache, the disk's read Io bi is very small.

The difference between buffer and cache:
Cache (cached) is to save the read Data , re-read if hit (find the required data) do not read the hard disk, if not hit the hard drive. The data will be organized according to the frequency of reading, the most frequently read content in the most easily found in the location, the content is no longer read to the back row, until removed from it.

Buffer (buffers) is based on the disk read-write design, the decentralized write operations centralized, reduce disk fragmentation and hard disk repeatedly seek, thereby improving system performance. Linux has a daemon that periodically empties buffered content (that is, writes like a disk) or manually empties the buffer via the Sync command. For example: I have a ext2 u disk here, I went to the inside CP a 3M MP3, but the U disk's light does not beat, after a while (or manually input sync) u disk light will beat up. The buffering is emptied when the device is uninstalled, so there are times when uninstalling a device takes a few seconds.

修改/etc/sysctl.conf中的vm.swappiness右边的数字可以在下次开机时调节swap使用策略。该数字范围是0~100,数字越大越倾向于使用swap。默认为60,可以改一下试试。两者都是RAM中的数据。简单来说,buffer是即将要被写入磁盘的,而cache是被从磁盘中读出来的。buffer是由各种进程分配的,被用在如输入队列等方面,一个简单的例子如某个进程要求有多个字段读入,在所有字段被读入完整之前,进程把先前读入的字段放在buffer中保存。cache经常被用在磁盘的I/O请求上,如果有多个进程都要访问某个文件,于是该文件便被做成cache以方便下次被访问,这样可提供系统性能。

Linux memory management, in fact, and Windows memory management has a very similar place, is the concept of virtual memory, why in many cases there is a lot of physical memory, but still use the pagefile. So often to argue with a bunch of people say the size of the pagefile, and how to assign this problem, in Linux we do not have to fight what swap size problem, I personally think, swap set a 512M is enough, if you ask that 512M swap is not enough to do? Can only say eldest brother you still add memory bar, or check your application, is not really appear memory leak.

View memory under Linux We generally use command free

[[email protected] ~]# free                  total           used       free     shared    buffers     cachedMem:    386024      377116     8908       0           21280     155468-/+ buffers/cache:     200368    185656Swap:    393552            0          393552

Here is an explanation of these values:
Second line (MEM):
Total: The amount of physical memory.
Used: How large is used.
Free: How much is available.
Shared: The total amount of memory shared by multiple processes.
Buffers/cached: The size of the disk cache.
Third line (-/+ buffers/cached):
Used: How large is used.
Free: How much is available.
There is not much to explain in line four.
Difference:
The used/free of the second line (MEM) differs from the third row (-/+ Buffers/cache) used/free.
The difference between the two is that the first line is from the OS point of view, because for the os,buffers/cached are all belong to be used, so his available memory is 8908KB, the used memory is 377116KB, which includes, the kernel (OS) uses + The +buffers+cached used by Application (X,ORACLE,ETC).
The third line refers to the application from the point of view, buffers/cached is equal to the availability of the application, because buffer/cached is to improve the performance of the file read, when the application needs to use memory, buffer/cached will be quickly recycled.
So from the application's point of view, available memory = System free (memory+buffers+cached.)
As in the above example:
185656=8908+21280+155468
Next, explain when the memory will be exchanged, and by what side.
When the available memory is less than the rated value, a meeting is exchanged.
How to look at the rated value (RHEL4.0):

Cat/proc/meminfo
The exchange will reduce the number of physical pages used in the system in three ways:
1. Reduce the buffer and the size of the page cache,
2. Swap out the memory page of the System V type
3. Swap out or discard the page. (Application occupies a memory page, that is, insufficient physical memory).
In fact, a small amount of swap use does not affect the performance of the system.

To be Continued ...

Linux Common commands

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.