An open API service indexing awesome lists of open source software.

https://github.com/karl-horning/bash-notebook

A personal collection of Bash scripts and notes for learning, automation, and quick reference. Includes file utilities, folder flatteners, and a growing cheatsheet for common shell tasks.
https://github.com/karl-horning/bash-notebook

automation bash cheatsheet cli-tools command-line learning-resources linux macos scripting shell shell-scripts utilities

Last synced: 6 months ago
JSON representation

A personal collection of Bash scripts and notes for learning, automation, and quick reference. Includes file utilities, folder flatteners, and a growing cheatsheet for common shell tasks.

Awesome Lists containing this project

README

          

# Bash Notebook Cheatsheet

---

## ๐Ÿ“– Table of Contents

- [Bash Notebook Cheatsheet](#bash-notebook-cheatsheet)
- [๐Ÿ“– Table of Contents](#-table-of-contents)
- [๐Ÿค“ Overview](#-overview)
- [๐Ÿ“ Basic Navigation](#-basic-navigation)
- [๐Ÿ“„ File \& Directory Operations](#-file--directory-operations)
- [โš™๏ธ Variables](#๏ธ-variables)
- [๐Ÿง  Conditionals](#-conditionals)
- [๐Ÿ” Loops](#-loops)
- [๐Ÿ“ฆ Functions](#-functions)
- [๐Ÿงช Test Operators](#-test-operators)
- [๐Ÿงน Useful One-Liners](#-useful-one-liners)
- [๐Ÿงช Exit Codes](#-exit-codes)
- [๐Ÿ”— Script Template](#-script-template)
- [๐Ÿ“„ Licence](#-licence)
- [๐Ÿ‘ค Author](#-author)

---

## ๐Ÿค“ Overview

A collection of handy Bash syntax, commands, and examples. For learning, quick reference, and scripting!

---

## ๐Ÿ“ Basic Navigation

```bash
pwd # Print working directory
ls # List files
ls -la # Long format with hidden files
cd foldername # Change directory
cd .. # Go up one directory
```

---

## ๐Ÿ“„ File & Directory Operations

```bash
touch file.txt # Create an empty file
mkdir myfolder # Create a directory
rm file.txt # Delete a file
rm -r folder # Delete a directory and contents
cp file.txt backup.txt # Copy file
mv old.txt new.txt # Rename or move file
```

---

## โš™๏ธ Variables

```bash
name="Karl"
echo "Hello $name"
```

---

## ๐Ÿง  Conditionals

```bash
if [ "$name" == "Karl" ]; then
echo "Hi Karl"
else
echo "Who are you?"
fi
```

---

## ๐Ÿ” Loops

```bash
# For loop
for i in {1..5}; do
echo "Loop $i"
done

# While loop
count=1
while [ $count -le 5 ]; do
echo "Count is $count"
((count++))
done
```

---

## ๐Ÿ“ฆ Functions

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

greet "Karl"
```

---

## ๐Ÿงช Test Operators

```bash
[ -f file.txt ] # File exists
[ -d mydir ] # Directory exists
[ -z "$var" ] # String is empty
[ "$a" -eq "$b" ] # Numbers equal
```

---

## ๐Ÿงน Useful One-Liners

```bash
grep "word" file.txt # Search for "word"
cat file.txt | less # Page through a file
find . -name "*.sh" # Find all .sh files
chmod +x script.sh # Make script executable
head -n 10 file.txt # First 10 lines
tail -f logs.txt # Follow file live
```

---

## ๐Ÿงช Exit Codes

```bash
echo $? # Shows the exit code of the last command
```

---

## ๐Ÿ”— Script Template

```bash
#!/bin/bash

# Script to greet the user
name="$1"
echo "Hello, $name!"
```

Make it executable:

```bash
chmod +x myscript.sh
./myscript.sh Karl
```

---

## ๐Ÿ“„ Licence

MIT ยฉ 2025 Karl Horning

---

## ๐Ÿ‘ค Author

Made with โค๏ธ by [Karl Horning](https://github.com/Karl-Horning)