BASH Cheat Sheet With StackOverflow References

Count lines in file

wc -l laravel.log
169613 laravel.log

Word count lines in Laravel.log

Truncate lines from the beginning of a file

tail -n +169000 laravel.log > laravel2.log
wc -l laravel2.log
614 laravel2.log

If statements

Example If Then Else Statement

if [ $BACKUP_STATUS = 1 ] ; then

wget -q "https://backup-manager.test/api/job?api_token=xyz&id=1&status=$result"

How to Output the Date

Calculate time differences

Source a file in the same directory

Truthy / falsy (boolean) values

Can you nest if statements in Bash?

4 Bash If Statement Examples ( If then fi, If then else fi, If elif else fi, Nested if )

Typical error:

line 44: [: =: unary operator expected

What does “unary operator expected” mean in Bash?

how to see in bash if a variable is set

Output hostname in Bash


Getting Hostname in Bash in Linux in 3 Ways

How to concat variable in Bash

A Bash function with variables


greeting () {
   echo "Hello $1"

greeting "Joe"

That was fun!

Share this article

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top