Know Your Environment

Updated: 2018-11-30

CPU

CPU count

$ python -c "import os; print(os.cpu_count())"
8

Linux Only:

$ cat /proc/cpuinfo

Memory

LINUX ONLY:

$ cat /proc/meminfo
MemTotal:       xxxx kB
MemFree:        xxxx kB
...

Show sum of memory usage

$ ps aux | awk '{sum +=$4}; END {print sum}'

Show memory in mega(linux only)

$ free -m

Show memory, human readable(linux only)

$ free -h

Disk

Check disk. (-h for "human readable")

$ df -h

Mac OS X only:

$ diskutil list

Disk Usage

depth 1

$ du -d1

human readable

$ du -h

sum

$ du -s

OS

By uname:

on Mac OS

$ uname
Darwin

$ uname -r
14.5.0

on Linux

$ uname
Linux

$ uname -r
2.6.32-431.11.2.el6.x86_64

LINUX ONLY:

LSB = Linux Standard Base

$ lsb_release -a
LSB Version:	:base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID:	RedHatEnterpriseServer
Description:	Red Hat Enterprise Linux Server release 6.5 (Santiago)
Release:	6.5
Codename:	Santiago

LINUX ONLY:

$ cat /etc/issue
Ubuntu 12.10 \n \l

Show kernel version

$ cat /proc/sys/kernel/osrelease
3.5.0-17-generic
$ python -m platform
Darwin-15.4.0-x86_64-i386-64bit

env

List all variables

$ env
TERM=xterm-256color
SHELL=/bin/sh
JAVA_HOME=...
HADOOP_HOME=...

env is equivalent to printenv

$ printenv

Show A Specific Variable

$ env | grep TERM
xterm-256color

or

$ echo $TERM
xterm-256color

Remove A Variable

$ unset <VAR_NAME>

List of Built-in Variables

  • HOME - Home directory of the user.

  • MAIL - Contains the path to the location where mail addressed to the user is stored.

  • IFS - Internal Field Separator. Contains a string of characters which are used as word separators in the command line. The string normally consists of the space, tab and the newline characters. To see them you will have to do an octal dump as follows:

    $ echo $IFS | od -bc
  • PS1 and PS2 - Primary and secondary prompts in bash. PS1 is set to $ by default and PS2 is set to > . To see the secondary prompt, just run the command :

    $ ls |
  • USER - User login name.

  • TERM - indicates the terminal type being used. This should be set correctly for editors like Vim to work correctly.

  • SHELL - Determines the type of shell that the user sees on logging in.

  • LOGNAME - login name

ulimit

Per user limit

Check limits

$ ulimit -a

Check limits by PID

$ cat /proc/<pid>/limits

Set limits

$ ulimit -n 64000 -u 64000
  • nofile: number of open files
  • nproc: number of processes

Check Runlevel

$ who -r

or (not working on OSX)

$ runlevel

Partitions

$ cat /proc/partitions

Hostname

$ hostname
$ cat /etc/hosts

Set hostname

$ hostname newname
  • /etc/hostname: the hostname of the machine
  • /etc/hosts: list of hosts
  • host <host_name>: DNS lookup

Unknown Host Error in sudo: make sure the names match

$ cat /etc/hosts
127.0.1.1   example-hostname

$ cat /etc/hostname
example-hostname

$ host example-hostname
example-hostname.foo.bar.example.com has address 10.64.xxx.xxx