bash 确定Mac终端中几个系统变量的值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5446134/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 23:41:08  来源:igfitidea点击:

Determine values of several system variables in the terminal in a Mac

bashunixterminalsystemenvironment

提问by Kevin Burke

I'm on a Mac. In the terminal, how would you figure out each of the following values?

我在 Mac 上。在终端中,您将如何计算出以下每个值?

  • Word size (64 bit vs. 32 bit)
  • L1/L2 cache size
  • Determine how much memory is being used (like df, but for RAM)
  • 字大小(64 位与 32 位)
  • L1/L2 缓存大小
  • 确定正在使用多少内存(如df,但用于 RAM)

Thanks! I know you can find these in Activity Monitor, System Profiler etc. but I am trying to boost my knowledge of the terminal, and UNIX.

谢谢!我知道您可以在 Activity Monitor、System Profiler 等中找到这些,但我正在努力提高我对终端和 UNIX 的了解。

回答by geekosaur

System Profiler is a GUI wrapper around /usr/sbin/system_profiler.

System Profiler 是一个围绕/usr/sbin/system_profiler.

mress:10008 Z$ system_profiler -listDataTypes 
Available Datatypes:
SPHardwareDataType
SPNetworkDataType
SPSoftwareDataType
SPParallelATADataType
SPAudioDataType
SPBluetoothDataType
SPCardReaderDataType
SPDiagnosticsDataType
SPDiscBurningDataType
SPEthernetDataType
SPFibreChannelDataType
SPFireWireDataType
SPDisplaysDataType
SPHardwareRAIDDataType
SPMemoryDataType
SPPCIDataType
SPParallelSCSIDataType
SPPowerDataType
SPPrintersDataType
SPSASDataType
SPSerialATADataType
SPUSBDataType
SPAirPortDataType
SPFirewallDataType
SPNetworkLocationDataType
SPModemDataType
SPNetworkVolumeDataType
SPWWANDataType
SPApplicationsDataType
SPDeveloperToolsDataType
SPExtensionsDataType
SPFontsDataType
SPFrameworksDataType
SPLogsDataType
SPManagedClientDataType
SPPrefPaneDataType
SPStartupItemDataType
SPSyncServicesDataType
SPUniversalAccessDataType
mress:10009 Z$ system_profiler SPHardwareDataType
Hardware:

    Hardware Overview:

      Model Name: iMac
      Model Identifier: iMac10,1
      Processor Name: Intel Core 2 Duo
      Processor Speed: 3.33 GHz
      Number Of Processors: 1
      Total Number Of Cores: 2
      L2 Cache: 6 MB
      Memory: 16 GB
      Bus Speed: 1.33 GHz
      Boot ROM Version: IM101.00CC.B00
      SMC Version (system): 1.52f9
      Serial Number (system): QP0241DXB9S
      Hardware UUID: 01C6B9E9-B0CB-5249-8AC7-069A3E44A188

You can also get some useful information from /usr/sbin/sysctl(try sysctl -a).

您还可以从/usr/sbin/sysctl(尝试sysctl -a)中获取一些有用的信息。

mress:10014 Z$ sudo sysctl -a | grep cache
Password:
hw.cachelinesize = 64
hw.l1icachesize = 32768
hw.l1dcachesize = 32768
hw.l2cachesize = 6291456
kern.flush_cache_on_write: 0
vfs.generic.nfs.client.access_cache_timeout: 60
vfs.generic.nfs.server.reqcache_size: 64
net.inet.ip.rtmaxcache: 128
net.inet6.ip6.rtmaxcache: 128
hw.cacheconfig: 2 1 2 0 0 0 0 0 0 0
hw.cachesize: 17179869184 32768 6291456 0 0 0 0 0 0 0
hw.cachelinesize: 64
hw.l1icachesize: 32768
hw.l1dcachesize: 32768
hw.l2cachesize: 6291456
machdep.cpu.cache.linesize: 64
machdep.cpu.cache.L2_associativity: 8
machdep.cpu.cache.size: 6144