| by Arround The Web

How to Use getopts in Bash

In Linux, tasks can be automated by writing several commands in one script and then executing the script whenever the same set of commands are needed. These scripts accept a variety of command-line arguments, which are often passed collectively when the script is executed. The good thing is that a built-in function (called getopts) is available […]

The post How to Use getopts in Bash appeared first on Linux Today.

Share Button
Read More
| by Arround The Web

Learn Bash base64 Encode and Decode With Examples

Want to learn about base64 encode and decode method? Here in this tutorial, we explain the base64 encode and decode steps using bash shell scripting with various examples.
The post Learn Bash base64 Encode and Decode With Examples appeared first on Lin…

Share Button
Read More
| by Arround The Web

How To Use Case Statement In Bash Scripts

This guide explains what Bash case statement is and how to use case statement in Bash shell scripts, with examples.
The post How To Use Case Statement In Bash Scripts appeared first on Linux Today.

Share Button
Read More
| by Arround The Web

10 Amazing and Mysterious Uses of (!) Symbol or Operator in Linux Commands

The ‘!’ symbol or operator in Linux can be used as Logical Negation operator as well as to fetch commands from history with tweaks or to run previously run command with modification. All the commands below have been checked explicitly in ba…

Share Button
Read More
| by Arround The Web

Bash Scripting: Associative Array Explained With Examples

Bash supports two types of arrays, namely Indexed Array and Associative Array. This guide explains the Bash associative array in Linux.
The post Bash Scripting: Associative Array Explained With Examples appeared first on Linux Today.

Share Button
Read More
| by Arround The Web

Bash Scripting’s Indexed Array Explained with Examples

Bash supports two types of arrays namely Indexed Array Associative Array. This guide explains Bash indexed array in detail with examples.
The post Bash Scripting’s Indexed Array Explained with Examples appeared first on Linux Today.

Share Button
Read More
| by Arround The Web

Bash Scripting – For Loop Explained With Examples

Loops are useful for automating repetitive tasks in Bash shell scripting. In this guide, we will learn about the for loop with examples.
The post Bash Scripting – For Loop Explained With Examples appeared first on Linux Today.

Share Button
Read More
| by Arround The Web

Bash Scripting – Functions Explained With Examples

In Bash scripting, functions are ways to group the set of instructions together to get a specific outcome. This guide explains how to use functions in bash scripts in Linux with examples.
The post Bash Scripting – Functions Explained With Examples appe…

Share Button
Read More
| by Arround The Web

Bash Heredoc Tutorial For Beginners

When working with Bash scripts, you may end up in a situation where you have to process a series of inputs using the same command. Fortunately, there is a way in Bash to achieve this in a more optimal way using HereDoc. HereDoc, an acronym for Here Document, is an input redirection method to pass multiple […]

The post Bash Heredoc Tutorial For Beginners appeared first on Linux Today.

Share Button
Read More
| by Arround The Web

Bash Redirection Explained With Examples

Redirection and piping are two useful features in bash scripting that sysadmins and developers use often. This guide explains what Bash Redirection is and how to work with Redirection in Bash with example commands.
The post Bash Redirection Explained W…

Share Button
Read More
| by Arround The Web

Edit sshd_config Using a Bash Script

Using Bash scripts can ensure consistent configuration of SSH and other services. Bash is the default shell on most Linux systems these days. It can be used as an interactive command-line interpreter as well as a scripting language to automate common tasks. This article shows you how to use a Bash script to ensure specific […]

The post Edit sshd_config Using a Bash Script appeared first on Linux Today.

Share Button
Read More
| by Arround The Web

Bash Script to Monitor Memory Usage on Linux

This shell script will trigger an email when more than 60% of your system memory is used.
The post Bash Script to Monitor Memory Usage on Linux appeared first on Linux Today.

Share Button
Read More
| by Arround The Web

Linux for Starters: Your Guide to Linux – Get Started with the Terminal – Part 9

There are many reasons why it’s useful to use bash and the command line. For example, command-line skills help with building repeatable data processes, the command-line makes working with text files easier, it uses fewer resources, can improve productivity and workflow, it’s great for scripting, and command-line skills are useful for cloud services. This is […]

The post Linux for Starters: Your Guide to Linux – Get Started with the Terminal – Part 9 appeared first on Linux Today.

Share Button
Read More
| by Scott Kilroy

Using an editor to create commands

If you have a long group of commands you need to run press Ctrl-X, followed by Ctrl-E This will open your default editor.  When you’re done close the editor (saving the file) and the command will run.

Share Button
Read More
| by Scott Kilroy

Print the total bytes of files in a directory grouped by date

ls -l|awk ‘length($6)==3{x[$6″ “$7]+=$5};END{for(i in x)printf”%s:\t%d\n”,i,x[i]}’

Share Button
Read More
| by Scott Kilroy

Filter duplicate lines from a sorted files

cat list-1 list-2 list-3 | sort | uniq > final.list

Share Button
Read More
| by Scott Kilroy

Debugging bash scripts

Debugg bash scripts by runing with option -x example bash -x scriptname.sh

Share Button
Read More
| by Scott Kilroy

lowercase filen names

#! /bin/bash DIR=$1 for a in `ls $DIR` do fname=`echo $a | tr A-Z a-z` mv $DIR/$a $DIR/$fname done; exit 0

Share Button
Read More
| by Scott Kilroy

bashprofile

# .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin:/sbin export JAVA_HOME=/usr/java/jdk1.6.0_05/bin/java export PATH=$PATH:/usr/java/jdk1.6.0_05/bin export HISTIGNORE=”&” export EDITOR=nano export PATH unset USERNAME alias rm=’rm -i’ alias cp=’cp -i’ alias ls=’ls –color’ alias zf=’zf.sh’ echo -e “\033[36m########################## \033[0m” echo -e “\033[36mServer $HOSTNAME \033[0m” echo -e “\033[36mWelcome back $USER \033[0m” echo -e “\033[36musers loggged in: \033[0m” echo -e “\033[36m `users ` \033[0m” echo -e “\033[36m`uptime` \033[0m” echo […]

Share Button
Read More
| by Scott Kilroy

bashrc

Here is my typical .bashrc file # .bashrc # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi # append commenads to bash_history (when using more then one window) shopt -s histappend PROMPT_COMMAND=’history -a’ # User specific aliases and functions PATH=$PATH:$HOME/bin:/sbin #export JAVA_HOME=/usr/java/jdk1.6.0_05/bin/java export HISTIGNORE=”&” export EDITOR=nano export PATH unset USERNAME #function PWD { #pwd | awk -F\/ ‘{print $(NF-1),$(NF)}’ | sed ‘s/ /\\//’ #} #export PS1=”\[\033[0;32m\]\u@\h \[\033[33m\]\$(pwd 3)\[\033[0m\] \$ “;

Share Button
Read More