DevOps Buzz
Search…
Bash / Shell
Bitbucket
Distros
Elasticsearch
General
Guidelines / Standards
microk8s
Prometheus
RabbitMQ
VirtualBox
Cheat Sheet
Useful bash commands and snippets.

apt

Install specific package version

apt-cache policy kubelet
apt-get install kubelet=1.13.4-00

Hold version

apt-mark hold kubelet kubeadm kubectl

Remove hold version

apt-mark unhold kubelet kubeadm kubectl

crontab

List crontab for all users

for user in $(cut -f1 -d: /etc/passwd); do crontab -u $user -l; done

du

Hidden files

du -sch .[!.]* * |sort -h

Sort by size

du -hsc * |sort -h

ncurses interface

sudo apt install ncdu
ncdu

find

find and du -hsc

find . \
-name "*.txt" \
-maxdepth 2 \
-type d \
-exec du -csh --block-size=1M {} \;

find and rm

find . -name "server.log-2018*" \
-print0 | xargs -0 rm -f

Find and sed

find . -type f -print0 | xargs -0 sed -i 's/OLD/NEW/g'

Tools

fzf

GitHub - junegunn/fzf: A command-line fuzzy finder
GitHub

grep

Sort by second column:
grep -air "count-" file-name* |sort -k2

Hard drive management

List all hard drives and partitions:
sudo lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL

journalctl

Get all logs

Get 20 most recent:
journalctl -n 20

Get process logs

journalctl -u kubelet

Processes management

Check if process is running

#!/bin/bash
service=mongod
if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))
then
echo "$service is running!!!"
else
/etc/init.d/$service start
fi

Swap management

Create swap partition

sudo /bin/dd if=/dev/zero of=/var/swap.0 bs=1M count=1024
sudo /sbin/mkswap /var/swap.0
sudo /sbin/swapon /var/swap.0
echo "/var/swap.0 swap swap defaults 0 0" >> /etc/fstab
Replace 1024 with your desired swap size in MB.

Disable swap

sudo swapoff -a

systemctl

Check if process is enable

systemctl is-enabled PROCESS-NAME-HERE

List all services

systemctl list-units --type service --all

telnet

Client close connection

Input ctrl+]
Then execute:
close

wget

Backup entire website.

wget \
--recursive \
--no-clobber \
--page-requisites \
--html-extension \
--convert-links \
--restrict-file-names=windows \
--domains devops.buzz \
--no-parent \
https://www.devops.buzz/public/

References

Copy link
Outline
apt
Install specific package version
Hold version
Remove hold version
crontab
List crontab for all users
du
Hidden files
Sort by size
ncurses interface
find
find and du -hsc
find and rm
Find and sed
Tools
grep
Hard drive management
journalctl
Get all logs
Get process logs
Processes management
Check if process is running
Swap management
Create swap partition
Disable swap
systemctl
Check if process is enable
List all services
telnet
Client close connection
wget
Backup entire website.