Useful Linux Bash Commands
// PUBLISHED:
• // DURATION: 2 min read
// TABLE_OF_CONTENTS(6 sections) ▼
Get disk information
$ sudo lsblk -io KNAME,TYPE,SIZE,MODEL
KNAME TYPE SIZE MODEL
nvme0n1 disk 20G Amazon Elastic Block Store
nvme0n1p1 part 20G
nvme1n1 disk 46.6G Amazon EC2 NVMe Instance Storage
nvme1n1p1 part 46.6G
dm-0 lvm 46.6G
nvme2n1 disk 20G Amazon Elastic Block Store
nvme2n1p1 part 20G
Get Linux OS information
$ cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
Memory Usage
$ free -h
total used free shared buff/cache available
Mem: 3.5G 2.3G 116M 440K 1.1G 968M
Swap: 0B 0B 0B
Get current date time in different formats
# Get DateTime in UTC
$ date -u
Sun Sep 11 14:49:27 UTC 2021
# Get DateTime in ISO-8601 format
$ date +"%Y-%m-%dT%H:%M:%S%:z"
2021-09-11T14:49:47+00:00
# Get DateTime in a specific timezone
$ TZ=":US/Eastern" date '+%Y-%m-%d %H:%M:%S'
2021-09-11 10:53:02
Convert Epoch to DateTime
# Mac OS
❯ date -r 1663004743
Mon Sep 12 23:15:43 IST 2022
# Linux
$ date -d @$((1663004743))
Mon Sep 12 17:45:43 UTC 2022
Monitor CPU temparature
# Mac OS
sudo powermetrics --samplers smc | grep -i "CPU die temperature" // BROADCAST_POST: