灵活使用getconf命令来获取系统信息

我们时常需要查询系统相关的信息,比如页面大小,整数大小之类,如果编写程序去计算会比较繁琐,这里有一个很有用的命令,可以用来获取系统相关信息。它就是getconf。

getconf 用途将系统配置变量值写入标准输出,比如:

getconf PAGE_SIZE 查看系统内存分页大小

getconf LONG_BIT 看linux是32位还是64位最简单的方法

getconf -a 查看全部系统变量

$ getconf PAGE_SIZE

4096

$ getconf INT_MAX

2147483647

$ getconf LONG_BIT

64

可以取得的相关信息如下(参考相关资料,在又在版本上会有些不同):

_CS_PATH Value for the PATH environment variable used to find commands.
ARG_MAX Maximum length, in bytes, of the arguments for one of the exec subroutines, including environment data.
BC_BASE_MAX Maximum value allowed for the obase variable with the bc command.
BC_DIM_MAX Maximum number of elements permitted in an array by the bc command.
BC_SCALE_MAX Maximum value allowed for the scale variable with the bc command.
BC_STRING_MAX Maximum length of a string constant accepted by the bc command.
CHARCLASS_NAME_MAX Maximum number of bytes in a character class name.
CHAR_BIT Number of bits in a type character.
CHAR_MAX Maximum value of a type character.
CHAR_MIN Minimum value of a type character.
CHILD_MAX Maximum number of simultaneous processes for each real user ID.
CLK_TCK Number of clock ticks per second returned by the time subroutine.
COLL_WEIGHTS_MAX Maximum number of weights that can be assigned to an entry in the LC_COLLATE locale stanza in a locale-definition file.
CS_PATH Value of the PATH environment variable used to find commands.
EXPR_NEST_MAX Maximum number of expressions that can be nested within parentheses by the expr command.
INT_MAX Maximum value of a type int.
INT_MIN Minimum value of a type int.
LINE_MAX Maximum length, in bytes, of a command‘s input line (either standard input or another file) when the utility is described as processing text files. The length includes room for the trailing new-line character.
LONG_BIT Number of bits in a type long int.
LONG_MAX Maximum value of a type long int.
LONG_MIN Minimum value of a type long int.
MB_LEN_MAX Maximum number of bytes in a character for any supported locale.
NGROUPS_MAX Maximum number of simultaneous supplementary group IDs for each process.
NL_ARGMAX Maximum value of digit in calls to the printf and scanf subroutines.
NL_LANGMAX Maximum number of bytes in a LANG name.
NL_MSGMAX Maximum message number.
NL_NMAX Maximum number of bytes in an N-to-1 collation mapping.
NL_SETMAX Maximum set number.
NL_TEXTMAX Maximum number of bytes in a message string.
NZERO Default process priority.
OPEN_MAX Maximum number of files that one process can have open at one time.
PATH Sequence of colon-separated path prefixes used to find commands.
RE_DUP_MAX Maximum number of repeated occurrences of a regular expression permitted when using the interval-notation parameters, such as the m and n parameters with the ed command.
SCHAR_MAX Maximum value of a type signed char.
SCHAR_MIN Minimum value of a type signed char.
SHRT_MAX Maximum value of a type short.
SHRT_MIN Minimum value of a type short.
SSIZE_MAX Maximum value of an object of type ssize_t.
STREAM_MAX Number of streams that one process can have open at one time.
TMP_MAX Minimum number of unique path names generated by the tmpnam subroutine. Maximum number of times an application can reliably call the tmpnam subroutine.
TZNAME_MAX Maximum number of bytes supported for the name of a time zone (not the length of the TZ environment variable).
UCHAR_MAX Maximum value of a type unsigned char.
UINT_MAX Maximum value of a type unsigned int.
ULONG_MAX Maximum value of a type unsigned long int.
USHRT_MAX Maximum value of a type unsigned short int.
WORD_BIT Number of bits in a word or type int
时间: 2024-08-25 13:35:05

灵活使用getconf命令来获取系统信息的相关文章

java 获取系统信息及CPU的使用率(转)

java 获取系统信息及CPU的使用率 原文:http://kakaluyi.javaeye.com/blog/211492 最近做个项目,就是要取得cpu占有率等等的系统信息,一开始以为要用动态链接库了,但后来发现可以像下面这样做,不去调用jni,这样省去了很多看新技术的时间o(∩_∩)o... 在Java中,可以获得总的物理内存.剩余的物理内存.已使用的物理内存等信息,下面例子可以取得这些信息,并且获得在Windows下的内存使用率.     首先编写一个MonitorInfoBean类,用

Linux命令之查看系统信息

查看磁盘相关信息 df 查看磁盘使用情况,这个已经介绍过了. fdisk 用来进行磁盘分区.我们只是需要它的-l命令查看磁盘的分区情况.如下: m@sys:~/program/C_codes/algorithms$ sudo fdisk -l [sudo] password for m: Disk /dev/sda: 500.1 GB, 500107862016 bytes 255 heads, 63 sectors/track, 60801 cylinders, total 976773168

psutil——获取系统信息的Python第三方模块

本文摘自廖雪峰大神个人网站:https://www.liaoxuefeng.com/wiki/1016959663602400/1183565811281984 用Python来编写脚本简化日常的运维工作是Python的一个重要用途.在Linux下,有许多系统命令可以让我们时刻监控系统运行的状态,如ps,top,free等等.要获取这些系统信息,Python可以通过subprocess模块调用并获取结果.但这样做显得很麻烦,尤其是要写很多解析代码. 在Python中获取系统信息的另一个好办法是使

Linux学习之命令行获取公网IP方法详解

本文和大家分享的主要是主要是linux命令行获取公网IP相关内容,一起来看看吧,希望对大家学习linux有所帮助. curl ipinfo.io $ curl ipinfo.io { "ip": "36.10.25.4", "city": "Hangzhou", "region": "Zhejiang", "country": "CN", &quo

用Linux命令行获取本机外网IP地址

用Linux命令行获取本机外网IP地址 $ curl ifconfig.me$ curl icanhazip.com$ curl ident.me$ curl ipecho.net/plain$ curl whatismyip.akamai.com$ curl tnx.nl/ip$ curl myip.dnsomatic.com$ curl ip.appspot.com$ curl -s checkip.dyndns.org | sed 's/.*IP Address: \([0-9\.]*\)

java执行cmd命令并获取输出结果

1.java执行cmd命令并获取输出结果 1 import java.io.BufferedReader; 2 import java.io.InputStreamReader; 3 4 import org.apache.commons.lang3.text.StrBuilder; 5 6 /** 7 * 8 * @author user1 9 */ 10 public class DeleteProgram { 11 public static void run() { 12 Runtime

python获取系统信息psutil

python获取系统信息psutil:psutil获取系统cpu使用率的方法是cpu_percent(),其有两个参数,分别是interval和percpu,interval指定的是计算cpu使用率的时间间隔,percpu则指定是选择总的使用率还是每个cpu的使用率. import psutil #cpu使用率 cpu=(str)(psutil.cpu_percent(1))+'%' #剩余内存.free 总共.total memory=str(psutil.virtual_memory().f

getconf 命令

用途 将系统配置变量值写入标准输出. 语法 getconf [ -v specification ] [ SystemwideConfiguration | PathConfiguration PathName] [ DeviceVariable DeviceName ] getconf -a 描述 用 SystemwideConfiguration 参数调用 getconf 命令,将 SystemwideConfiguration 参数所指定的变量值写到标准输出. 用 PathConfigur

直接从命令行获取MySQL查询语句结果

如果你需要直接从命令行获取MySQL查询语句结果,那么你可以使用-B和-N这两个参数来达到目的. 例:获取MySQL用户数. [[email protected] ~]# mysql -BN -uroot -predhat mysql -e 'select count(*) from user' 6 [[email protected] ~]# -B参数:去掉边框 -N参数:只显示结果