Skip to content

Instantly share code, notes, and snippets.

View harishkannarao's full-sized avatar

Harish Kannarao harishkannarao

View GitHub Profile
@harishkannarao
harishkannarao / practical_rsync_command_and_options.md
Last active June 17, 2025 08:58
Practical rsync command and options

Copy new files from source to target and skip files if it already exist in target

rsync --dry-run -avzurh --stats --delete --progress /tmp/source/ /tmp/target/

Explanation of flags:

  • -a -> Archive mode, preserve the file system properties
  • -v -> Verbose output
  • -vv -> Higher Verbose output
  • -vvv -> Even Higher Verbose output

Bash Script Example

The following blog post shows a sample bash script covering some inportant aspects in writing a bash script.

Important aspects covered in this script:

  • Validate if input arguments are passed
  • Parse positional arguments
  • Handle parameter values with white space
  • Validating the arguments (using regex)
  • While loop to iterate through varargs
  • Usage of unit functions
@harishkannarao
harishkannarao / calculate.sh
Last active June 10, 2025 21:36
Basic bash script example to calculate addition, subtraction, multiplication and division of two numbers
#!/bin/bash
# Make the script to abort if any command fails. Use set +e to change the behaviour and ignore failed command.
set -e
# Uncomment below line to print the commands as it is executed. Useful for debugging. Use set +x to disable debugging.
# set -x
# Function to print usage of the script with different options
function print_usage()