# Cheat Sheet

## apt

### Install specific package version

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

### Hold version

```bash
apt-mark hold kubelet kubeadm kubectl
```

### Remove hold version

```bash
apt-mark unhold kubelet kubeadm kubectl
```

## crontab

### List crontab for all users

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

## du

### Hidden files

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

### Sort by size

```bash
du -hsc * |sort -h
```

### ncurses interface

```bash
sudo apt install ncdu
ncdu
```

## find

### find and du -hsc

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

### find and rm

```bash
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

{% embed url="<https://github.com/junegunn/fzf>" %}

## grep

Sort by second column:

```bash
grep -air "count-" file-name* |sort -k2
```

## Hard drive management

List all hard drives and partitions:

```bash
sudo lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL
```

## journalctl

### Get all logs

Get 20 most recent:

```bash
journalctl -n 20
```

### Get process logs

```bash
journalctl -u kubelet
```

## Processes management

### Check if process is running

```bash
#!/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

```bash
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
```

{% hint style="info" %}
Replace **1024** with your desired swap size in MB.
{% endhint %}

### Disable swap

```bash
sudo swapoff -a
```

## systemctl

### Check if process is enable

```bash
systemctl is-enabled PROCESS-NAME-HERE
```

### List all services

```bash
systemctl list-units --type service --all
```

## telnet

### Client close connection

Input `ctrl+]`

Then execute:&#x20;

```bash
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

<https://www.linuxjournal.com/content/downloading-entire-web-site-wget>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.devops.buzz/public/bash/cheat-sheet.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
