Lesson 02 - chad-p/wiki-linux-class GitHub Wiki

CLI Fundamentals

Additional CLI trainings

Cheatsheet

Gathering System Information

ls -lah

# What user is running
whoami

# List block devices
lsblk
fdisk -l

# System Resources
lscpu  # or cat /proc/cpuinfo
lsmem  # or cat /proc/meminfo

# What distro am I on
cat /etc/os-release

# Processes that are running
ps aux

# What services are running
service --status-all
systemctl list-units --type service --state running

# Open ports
ss -atu

# Network Information
ifconfig
ip -c a

# Kernel info
uname -vr

Shell

# Find what shell you are using
echo $0

Command Help

  • <command> --help
  • man <command>
  • info <command>
  • type <command>

Working with files

# Remove everything but one file
rm -v !("file_to_keep")

Using Find

find . -name myfile.txt

Input/Output

echo "redirect this to a file" > file.txt
echo "append this to a file" > file.txt

ls zepplin 2>errors.txt
ls zepplin 2>/dev/null

tr a-z A-Z < filename.txt

Vim

Globbing

ls ????.*

egrep '*-0[56]-*'  # Find all dates in May or Jone
grep '[Mm]ate' file  # Match lines with Mate or mate

Brace Expansion

echo {1..10}
echo {0001..10}
echo {0..10..2}
mkdir 20{09..11}-{01..12}

mkdir -p toplevel/sublevel_{01..09}/{child1,child2,child3}
⚠️ **GitHub.com Fallback** ⚠️