Created
February 19, 2018 12:17
-
-
Save eugenestarchenko/ed30582d611beacdf1153a7693b1a591 to your computer and use it in GitHub Desktop.
Change Timezone on Linux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| ZONEFILEDIR="/usr/share/zoneinfo" | |
| ZONEFOLDERNAME=$(echo $ZONEFILEDIR | awk 'BEGIN { FS="/" } { print $NF }') | |
| usage() { | |
| echo "usage: change-timezone.sh <-l [SEARCH] | -s ZONE>" | |
| echo " -l -> List available timezones and search for SEARCH" | |
| echo " -s -> Set timezone to ZONE (requires sudo/root access)" | |
| } | |
| if [ -z "$1" ]; then | |
| usage | |
| else | |
| if [ "$1" == "-l" ]; then | |
| if [ -z "$2" ]; then | |
| find -L $ZONEFILEDIR -type f | sed 's/^.*\/'"$ZONEFOLDERNAME"'\///g' | egrep -v '^right|^posix' | sort -d | more | |
| else | |
| find -L $ZONEFILEDIR -type f | sed 's/^.*\/'"$ZONEFOLDERNAME"'\///g' | egrep -v '^right|^posix' | sort -d | grep "$2" | more | |
| fi | |
| elif [ "$1" == "-s" ]; then | |
| if [ -f "$ZONEFILEDIR/$2" ]; then | |
| rm /etc/localtime | |
| ln -s $ZONEFILEDIR/$2 /etc/localtime | |
| else | |
| echo "Timezone $2 doesn't exist" | |
| fi | |
| else | |
| usage | |
| fi | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment