Basics
Learn the basics.
The prompt
The prompt will usually look something like this username@hostname: ~$ or this [username@hostname ~]$ .
You can type commands after the prompt.
If you’re in sudo mode, # will be displayed
instead of $. ~ is your current working directory.
Output redirect
You can redirect the output of a command to a file or something else with appending >PATH.
You can redirect errors with 2>PATH.
Chaining commands
<cmd1> || <cmd2>: only execute cmd2 if cmd1 failed<cmd1> && <cmd2>: only execute cmd2 if cmd1 was successful<cmd1> ; <cmd2>: run both commands no matter the result of the first one<cmd1> | <cmd2>: feed the results of cmd1 into cmd2 (“piping”)<cmd1> &: run the command in background
Useful shortcuts
Ctrl+A: jump to start of lineCtrl+E: jump to end of lineCtrl+C: stop/abort/exit commandCtrl+Z: interrupt processCtrl+D: exit session/terminal
General Commands
exit: end a terminal (or ssh) sessionhistory: view the command historyclear: empty terminalreset: reset terminal (use when issues arise regarding weird symbols)echo <args>: print arguments to default output
Getting help
<command> --help: common argument for most commandsman [group] <command>: get man pages (group is a number, e.g. 1 stands for user commands)info <command>: get info pages
System
shutdown <time> "<message>"<time>: z. B. 22:00, +5, now-r: reboot-F: Dateisystem bei nächstem Neustart überprüfen-c: cancel-p: explizit ausschalten (in virtualisierten Systemen z. T. notwendig)-f: force (bis zu 2x angeben)
halt: same asshutdown nowpoweroff: same asshutdown nowinit 0: same asshutdown nowreboot: same asshutdown -r now
Variables
Common variables
$SHELL: path to the current shell$HOME: path to the current user’s home directory$HOSTNAME: name of current device$?exit code of last command
Shell variables
set: print all shell varsset | more: print shell varsset | grep VAR=: get a specified shell var$VAR: use a shell varecho $VAR: print a shell varVAR=CONTENT: set a shell variable
Environment variables
printenv: print all environment varsprintenv VAR VAR2...: print one or more environment varsexport VAR=CONTENT: set an environment var
Both var types
unset VAR: unset a shell or environment variableexport VAR: promote a shell to an environment variableexport -n VAR: demote an environment to a shell variable
Persistent env vars
To make environment variables persistent, their export statements have to be saved in files.
User-specific vars can be stored in ~/.bashrc (accessable in non-login bash shells), ~/.bash_profile (acessible only
by Bash) or ~/.profile (accessible in any Bourne shell).
System-wide vars can be stored in /etc/environment (accessible by every shell) or /etc/profile and the files
in /etc/profile.d/ (accessible by bash login shells; using files in the folder is recommended).
More
export PATH="$PATH:<path-to-add>": add a path to PATH