Bash-interesting-command-examples

From I Will Fear No Evil
Revision as of 09:30, 4 July 2023 by Chubbard (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Interesting one-liners

  • Find all drives and ignore loop devices
root@kvm03:/var/log# lsblk | grep -v "loop\|NAME" | grep "^[a-z]\|^[A-Z]" | awk '{print $1}'
sda
sdb
root@kvm03:/var/log# 
root@kvm03:/var/log# lsblk | grep disk | awk '{print $1}'
sda
sdb
root@kvm03:/var/log# 

Continue match until match is found

  • This is using awk, and seems quite powerful as a tool
  • found this little gem at Stack Exchange
awk '/Word A/,/Word D/' filename

/From/CONTINUE/Until/