Linux cheatsheet

Sorting MinIO objects

mc find --older-than 0 --larger 10000 --json s3

Sorting with jq

mc ls -r --json s3/ | jq --slurp 'sort_by(.lastModified) | .[] | select(.key | contains("filenamepart"))'

debug

kubectl debug -it --image=ubuntu:latest -n my-ns pod/mypod --target=my-cont --profile=sysadmin -- /bin/bash

AWS log insight - Find size of log stream in log group

fields @logStream, @message
| stats count() as logEventCount, sum(strlen(@message))/1048576 as totalSizeKiloBytes by @logStream

AWS log insight - Find size per useragent

fields @timestamp, userAgent
| stats count(*) as log_count by userAgent
| sort log_count desc

Find Terraform "will be re-read during apply" reason

#!/bin/bash

# Input file containing the full text output of the plan
input_file="plan.txt"

# Output files for each split section
output_file_prefix="split_part"

# Initialize variables
awk '
BEGIN {
    file_number = 1;
    out_file = sprintf("%s_%d.txt", "'$output_file_prefix'", file_number);
    empty_line = 0;
}

/^$/ {
    # Flag that we encountered an empty line
    empty_line = 1;
}

/^  #/ {
    if (empty_line == 1) {
        # Only increment the file number if the previous line was empty
        file_number++;
        out_file = sprintf("%s_%d.txt", "'$output_file_prefix'", file_number);
    }
    # Reset empty line flag after processing
    empty_line = 0;
}

{
    print > out_file;
}
' "$input_file"

for i in $(grep -Lir "known after apply" split_part*); do
    echo "Found: $i"
    cat $i
done