top of page

Useful Tiny Bash Functions

  • Writer: Mahammad Rafi
    Mahammad Rafi
  • Mar 4, 2017
  • 1 min read

Super nerd people spend most of their time in CLI. As long as we use terminal for our needs, we can also unlock new features from it by appending some codes in bashrc file. Here are some examples which we can use.

History auto-completion (type sudo and press up-arrow key, history includes sudo will come up)

bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'

Countdown timer

function countdown(){
  date1=$((`date +%s` + $1)); 
  while [ "$date1" -ne `date +%s` ];
    do echo -ne "$(date -u --date @$(($date1 - `date +%s`)) +%H:%M:%S)\r";
    sleep 0.1
  done
}

Stopwatch

function stopwatch(){
  date1=`date +%s`; 
  while true; 
    do echo -ne "$(date -u --date @$((`date +%s` - $date1)) +%H:%M:%S)\r"; 
    sleep 0.1
  done
}

Alarm

alarm() {
sleep $1; 
while :; 
  do paplay /usr/share/sounds/freedesktop/stereo/alarm-clock-elapsed.oga; 
  read -t 0.01 -n 1; 
  if [ $? = 0 ]; then 
    break; 
  fi; 
  done
}

Random commands from commandlinefu.com

cfu () { 
  wget -qO - http://www.commandlinefu.com/commands/random/plaintext | \
  sed -n '/AD/!p' | sed -n '/commandlinefu.com/!p' | tee ~/.cfu; 
  read -p "Do you want to save? (y/n) " ans
  if [ $ans == y ]; then
    cat ~/.cfu >> ~/Useful_Commands;
  fi
}

Comments


adult-apple-device-business-340152.jpg

Linux .....because life is too short for reboots

I am an avid fan of Linux and open source enthusiast so I make a  decision to meet people through Technical Live Blogger. I have been enjoying Linux for the past six years. Back in 2013, I stumbled upon an article about the Ubuntu live CD. That moment changed my life. I know that statements like that belong to those exaggerators but it is actually true. Within 24 hours of reading the article, I had turned my own desktop in Ubuntu one – a platform where I have explored many Linux things ever since. If you just want to say hello, do say "Hello" at md.rafi1615@gmail.com or visit the virtualworld.

  • LinkedIn Social Icon
  • Twitter Social Icon
  • Instagram Social Icon
  • Facebook Social Icon

© 2023 by Extreme Blog. Proudly created by Mahammad Rafi

bottom of page