Bash, the magic that empowers the Cloud
Tags: bash, deployments, linux, deploypro
Published: 2023-08-23 16:12:14

---
title: Bash, the magic that empowers the Cloud
published: true
description: Bash, a popular command-line shell and scripting language used in Unix-like operating systems - Short Intro & related tools
tags: bash, deployments, linux, deploypro
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/399jjvkqbrm87wv8ylsr.jpg
canonical_url: https://www.docs.deploypro.dev/script-languages/bash/intro
---
Hello Coders! 

This article is not about ML, Generative AI, automation, or any other hot topic. It’s about Bash, also known as `Bourne Again Shell` the workhorse that empowers Cloud Computing and Services like AWS, GCP, Azure or Digital Ocean.

> 🚀 Provided by [DeployPRO - Deployment process simplified](https://deploypro.dev/) — Works with `AWS`, `DO`, `GCP` and `Azure`

With decent Bash knowledge, anyone can manage a Linux system with ease, deploy projects LIVE, schedule backups, and execute maintenance tasks using the CRON System. If this sounds like something useful, let’s move forward and point out a few Bash-related topics and tools.

---

## What is Bash?​

Bash, short for “Bourne Again Shell” is a command-line interface and scripting language used in Unix-like operating systems. It provides a way to interact with the operating system by running commands, and it also supports writing scripts to automate tasks.

### Getting Started

- Open a terminal on your Linux system. This is where you’ll interact with Bash.
- Type a command and press Enter to execute it. For example, ls lists files in the current directory.
- Arguments can be added after the command, like ls -l to list files in long format.

> **Basic Commands** 

- `ls`: List files and directories in the current location.
- `cd`: Change directory.
- `pwd`: Print the current working directory.
- `mkdir`: Create a new directory.
- `touch`: Create an empty file.
- `cp`: Copy files or directories.
- `mv`: Move or rename files or directories.
- `rm`: Remove files or directories (use with caution).

> **Variables**

Bash uses variables to store and manipulate data.

```bash
name="John"
echo "Hello, $name!"
```

> **Input and Output**

- `echo`: Print text to the screen.
- `read`: Read input from the user.

```bash
echo "What's your name?"
read name
echo "Hello, $name!"
```

> **Conditional Statements**

Bash supports `if` statements for conditional execution.

```bash
age=25
if [ "$age" -lt 18 ]; then
    echo "You're a minor."
else
    echo "You're an adult."
fi
```

> **Loops** 

```bash
for fruit in apple banana orange; do
    echo "I like $fruit."
done
```

> **Functions** 

```bash
greet() {
    echo "Hello, $1!"
}
greet "Alice"
```

> **Simple Calculator Script** 

```bash
#!/bin/bash
read -p "Enter first number: " num1
read -p "Enter second number: " num2
sum=$((num1 + num2))
echo "Sum: $sum"
```

--- 

## Bash & Linux Tools

This section presents a few tools we can use to manage different aspects of a Linux box like backups, text browsing, and file editing.

### [Cron System](https://www.docs.deploypro.dev/script-languages/bash/cron-system)

The `cron system` is a time-based job scheduling mechanism in Unix-like operating systems. It allows you to automate repetitive tasks by scheduling them to run at specific intervals. The term “cron” comes from the Greek word “chronos,” meaning time.

> **Components of the Cron System**

- Cron Daemon (cron): The cron daemon is a background service that manages the scheduling and execution of cron jobs. It constantly checks the system's crontab files to determine when to run scheduled tasks.
- Cron Jobs: A cron job is a command or script that you want to run automatically at a specified time or interval. Each cron job consists of a command and a schedule defined by cron syntax.

Cron Syntax: Cron uses a specific syntax to define when a job should be executed. The syntax consists of five fields (plus an optional command field):

```bash
* * * * * command_to_run
| | | | |
| | | | +----- Day of the week (0 - 6) (Sunday = 0)
| | | +------- Month (1 - 12)
| | +--------- Day of the month (1 - 31)
| +----------- Hour (0 - 23)
+------------- Minute (0 - 59)
```

> Cron Samples

- Run a Script Every Night at Midnight

```bash
0 0 * * * /path/to/script.sh
```

- Send System Statistics Every Hour

```bash
0 * * * * /usr/bin/collect_stats.sh
```

---

### [cURL](https://www.docs.deploypro.dev/script-languages/bash/curl) — Client URL

`curl` (short for "Client URL") is a command-line tool and library for transferring data with URLs. It supports various protocols, including HTTP, HTTPS, FTP, FTPS, SCP, SFTP, LDAP, and more. curl is widely used to interact with web services, download files, and perform data transfers from the command line in Unix-like operating systems.

> cURL Samples

- Downloading a File

```bash
curl -O https://www.example.com/file.txt
```

- Fetching Only Headers

```bash
curl -I https://www.example.com
```

- Sending POST Data

```bash
curl -X POST -d "key=value" https://www.example.com/post_endpoint
```

--- 

### [Gzip](https://www.docs.deploypro.dev/script-languages/bash/gzip)

`gzip` is a command-line utility used to compress and decompress files in Unix-like operating systems. It is named after the "GNU zip" project, which aims to provide a free and efficient replacement for the older compress utility.

> **Basic Usage**

```bash
gzip [options] file
```

> **Gzip Samples** 

- Compressing a File

```bash
gzip file.txt
```

- Decompressing a File

```bash
gzip -d file.txt.gz
```

- Testing Compressed Files

```bash
gzip -t file.txt.gz
```

`gzip` is commonly used to compress individual files and is often used in combination with other tools and utilities. It produces files with the .gz extension and these compressed files can save disk space and accelerate data transfer when distributing or storing files.

---

### [Lynx](https://www.docs.deploypro.dev/script-languages/bash/lynx)

`lynx` is a text-based web browser that allows users to browse the internet and view web pages from the command line in Unix-like operating systems. It's a versatile tool for accessing information from websites without requiring a graphical user interface.

While it doesn’t render images or complex layouts like modern graphical browsers, it’s useful for quick access to text-based content, checking links, and accessing web resources in a terminal environment.

> **Basic Usage** 

```bash
lynx [options] [URL]
```

> **Lynx Samples**

- Viewing a Web Page

```bash
lynx https://www.example.com
```

- Viewing Page Source

```bash
lynx -source https://www.example.com
```

- Viewing Plain Text Version

```bash
lynx -dump https://www.example.com
```

--- 

### [Rsync](https://www.docs.deploypro.dev/script-languages/bash/rsync)

Using the rsync command in Bash, you can synchronize the contents of a directory between two locations, either locally or across different machines over a network.

> **Basic Usage** 

```bash
rsync [options] source_directory destination
```

> **Rsync Samples**

- Local Sync

```bash
rsync -av source/ destination/
```

- Remote Sync over SSH

```bash
rsync -av source/ user@remote_host:destination/
```

- Excluding Files with Progress Indicators

```bash
rsync -av --progress --exclude '*.txt' source/ destination/
```

These examples cover some of the common use cases for rsync. The command offers many more options and functionalities for more complex synchronization scenarios.

---

### [Wget](https://www.docs.deploypro.dev/script-languages/bash/wget)

`wget` is a command-line utility used for downloading files from the internet. It supports various protocols, including HTTP, HTTPS, FTP, and FTPS. wget is commonly used to retrieve files and web content from the command line in Unix-like operating systems.

> **Basic Syntax** 

```bash
wget [options] [URL]
```

> **Wget Samples** 

- Downloading with Custom Output Name

```bash
wget -O output.txt https://www.example.com/file.txt
```

- Recursively Downloading a Website

```bash
wget -r https://www.example.com
```

`wget` is a reliable tool for downloading files and web content from the command line. Its simplicity and range of features make it a preferred choice for tasks that involve fetching resources over the Internet.

--- 

> Thanks for reading! For more resources and [deployment](https://deploypro.dev/) assistance feel free to access:

- 👉 Read more about [Bash](https://www.docs.deploypro.dev/script-languages/bash) & related tools
- 👉 [Deploy Projects](https://deploypro.dev/) using your own cloud provider (AWS, GCP, Azure)