Knowledge Base

<  ~/kb/cheatsheets/bash

bash => crash course commands

by ketz
bashshellscli

The below content was included as part of the 0x02 session: #!/bin/bash => a crash course in bash.

Useful commands

You’ll never be able to memorise every single command for everything, but these are pretty major ones for most things.

command category purpose
cd navigation change directory, allows the user to move around the shell to different locations in the filesystem.
pwd navigation print working directory, notifies the user of the current directory that the shell is in.
cp files copy, copies files in a <source> <destination> type format.
ls files list, lists the current files. Also try: ls -l, and ls -la for more informative versions.
rm files remove, this isn’t “put it in the recycle bin”, this is destroy off the face of the earth, it doesn’t come with an undo method, so be careful.
touch files modify timestamps, techincally this is the intention of the command, but it also is useful just for creating empty files (e.g: touch blah creates a file called blah).
apt software updates advanced package tool, used to keep the system up to date. There are many subcommands for this tool. apt update, apt upgrade, apt install are a few handy ones.

and many, many, more…



Resources

If you are interested in finding out more or doing your own research, here are some potential starting points. None of these are mandatory reading and going through all of them in detail is definitely overkill.

resource description
ss64: Bash Hotkeys A very established cheatsheet with bash key combinations.
Red Team Field Manual Lots of security related commands in here, also Windows and Linux-based so check that you’re using the right ones on the right systems.
Ryan’s Tutorials: Linux Basics Basically a lot of things from the talk, but much more fleshed out and more in depth. Also has other important information.
Ryan’s Tutorials: Bash Scripting A tutorial dedicated specifically to bash scripting.
TLDP: Bash Programming A good introduction into scripting.
Linuxjournal: Bash Tips and Tricks Pretty short and sweet, has good explanations of brace expansion and command substitution which are both handy to know.



Off the beaten path

resource description
tmux cheatsheet A reference guide for tmux commands. tmux stands for terminal multiplexer and is a very handy tool for being able to multitask inside a single terminal window. An alternative to tmux is screen, but it appears to be harder to get used to, so tmux is the recommendation here.



Some other things that haven’t been covered to look up yourself and try to understand:

  • Fundamentals of Linux (a lot of this gets covered in first year coursework which is why it has been left out of this presentation).
    • File permissions, what they mean and how to modify them safely.
    • Networking (IP addresses, ports, protocols, etc.)
  • The meaning and potential consequences of sudo.
  • How to install and uninstall software in your distribution of Linux.
  • How to use ssh to connect to remote machines.
    • How to setup key-based ssh authentication (this can save on typing in passwords all the time. == handy)



Some things to keep in mind:

  • Don’t rush.
  • You don’t have to know all of this or even any of it unless you want to.
  • If you keep at it, you will keep learning something new.
  • Pace yourself
  • Stick to what you know when it matters, and find out what you don’t when it doesn’t.