mac vs linux date

Converting Mac and Linux Dates Linux #!/bin/bash start_time=$(date +%s) log=$(date -d @$start_time +%Y%m%d-%H%M%S) start=$(date -d @$start_time) echo $start_time echo $log echo $start sleep 10 stop_time=$(date +%s) stop=$(date -d @$stop_time) echo $stop_time echo $stop Mac #!/bin/bash start_time=$(date +%s) log=$(date -r $start_time +%Y%m%d-%H%M%S) start=$(date -r $start_time) echo $start_time echo $log echo $start sleep 10 stop_time=$(date +%s) stop=$(date -r $stop_time) echo $stop_time echo $stop Same output for both 1692292771 20230817-171931 Thu Aug 17 05:19:31 PM UTC 2023 1692292781 Thu Aug 17 05:19:41 PM UTC 2023

August 17, 2023 · 1 min · ulysses

check if multiple arguments

If your Bash script calls for 3 arguments, here’s how to check it. if [ "$#" -ne 3 ] then echo "Usage: ./script.sh project diskname policy" exit fi You can adjust -ne 3 to any number based on the number of required arguments.

August 16, 2023 · 1 min · ulysses

leading zeros for numbers below 10

When displaying in a time format, it’s best to display numbers below 10 with leading zeros. Here’s a nice function you can call to covert numbers below 10. convert () { # print the number as a string with a leading zero number=$(printf '%02d\n' "$1") echo $number } convert 5 Result 05

August 16, 2023 · 1 min · ulysses

fallocate

If you want to create dummy files, there’s a faster command than ‘dd’ called ‘fallocate.’ Create a 30GB called temp_30GB_file. fallocate -l 30G temp_30GB_file Unlike dd which can take minutes depending on file size, fallocate is instantaneous.

August 14, 2023 · 1 min · ulysses

bash global variables

Just a few things about Bash variables. Every variable in Bash is global and are accessible anywhere in the script. They can be used in a function, loop, or conditional statement within the script. # setting a variable a = "hello" # printing a variable echo $a # using a variable inside a function hello_function () { echo $a } # passing a variable to a function hello_function $a

July 27, 2023 · 1 min · ulysses

clear the line

Another time saving command if you want to clear the entire line on a terminal is Ctrl+K. Ctrl+K

July 26, 2023 · 1 min · ulysses

move to start or end of line

If a command is too long, you can move your cursor to the beginning or the end of the line. Move to start of the line. ctrl+A Move to end of the line. ctrl+E

July 26, 2023 · 1 min · ulysses

pdfunite

How to merge several PDFs into one file. Install apt install poppler-utils Merging PDF files pdfunite one.pdf two.pdf three.pdf output.pdf

July 25, 2023 · 1 min · ulysses

gcp vm display label

Here’s how to display GCP VM labels. Display all labels. gcloud compute instances describe VM --zone ZONE --project PROJECT_ID --format="value(labels)" Display a specific label. gcloud compute instances describe VM --zone ZONE --project PROJECT_ID --format="value(labels.key)"

July 12, 2023 · 1 min · ulysses

run debian on docker container

Here’s how to run Debian on a Docker container. docker pull debian docker run -it debian /bin/bash

July 2, 2023 · 1 min · ulysses