Page cover

Bash Cheat Sheet

  • One Liners

    • Block Bad IPs

  • If Statements

    • Check if args are passed

    • Check if required variables exist

    • Check if environment variables exists

  • While Loops

    • Run for 5 Seconds

  • Redirecting Outputs

    • Stdout, Stderr

Commands

tr command

Remove whitespace:

$ echo 'foo - bar' | tr -d '[:space:]'
foo-bar

One Liners

Block Bad IPs

Use iptables to block all bad ip addresses:

Get the data to show only IPs:

Get the uniqe IP addresses:

Redirect the output to iptables:

If Statements

Check if args are passed

Check if required variables exist

Check if environment variables exists

While Loops

Run process for 5 Seconds

Redirecting Outputs

Stdout, Stderr

Redirect stderr to /dev/null:

Redirect stdout to one file and stderr to another file:

Redirect stderr to stdout (&1), and then redirect stdout to a file:

Redirect both to a file:

Thing that are basic but I need to work on

cat mv chmod

------------ I Got to 41 minutes of the video ------------------------

Last updated

Was this helpful?