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.
- Host: GitHub
- URL: https://github.com/karl-horning/bash-notebook
- Owner: Karl-Horning
- License: mit
- Created: 2025-07-18T10:08:33.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-07-28T20:45:45.000Z (7 months ago)
- Last Synced: 2025-07-28T22:28:30.299Z (7 months ago)
- Topics: automation, bash, cheatsheet, cli-tools, command-line, learning-resources, linux, macos, scripting, shell, shell-scripts, utilities
- Language: Shell
- Homepage:
- Size: 10.7 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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)