• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Search

Leading Zeros For Numbers Below 10

August 16, 2023

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

convert () { # print the number as a string with a leading zero number=$(printf '%02d\n' "$1") echo $number } convert 5

Result

05

05

Filed Under: Linux Tagged With: calculate, leading, time, zero

Check if Multiple Arguments

August 16, 2023

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

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.

Filed Under: Linux Tagged With: arguments, bash, required, usage

Fallocate

August 14, 2023

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

fallocate -l 30G temp_30GB_file

Unlike dd which can take minutes depending on file size, fallocate is instantaneous.

Filed Under: Linux Tagged With: dummy, fallocate, file, testing

  • « Go to Previous Page
  • Go to page 1
  • Interim pages omitted …
  • Go to page 3
  • Go to page 4
  • Go to page 5
  • Go to page 6
  • Go to page 7
  • Interim pages omitted …
  • Go to page 345
  • Go to Next Page »
  • Home
  • About
  • Search

Copyright © 2023