FactorPad
Faster Learning Tutorials

Linux bash command summary with examples

bash allows you to interact with the terminal.
  1. Purpose - Learn what bash is for and how to find help.
  2. Options - Review a few common options and arguments.
  3. Examples - Walk through code examples with bash.
  4. A tip - Finish off with one more insight.
Paul Alan Davis, CFA, October 7, 2016
Updated: July 26, 2018
In this tutorial, 9 of 100, below find a 3-4 minute introductory video, a text-based tutorial and all of the code examples from the video.

Outline Back Next

~/ home  / technology  / linux essentials  / bash command


The Linux bash command

Beginner

Learn to interpret what bash does at the Linux command line.

Video Tutorial

Linux bash command summary with examples (3:43)

Videos can also be accessed from the YouTube Playlist.

Video Script

The Command and Why You Need It

Our ninth word, or command to memorize is bash from the category System.

bash allows you to interact with the terminal. In our last video we noted the challenge in finding a handy man page for the cd command. This is because the cd command is contained within the bash command. Sound confusing? I'll explain.

It may help to think of commands as mini programs and most follow this structure: command -option(s) argument(s).

The bash command has 22 options and the list of arguments is vast so here I've listed two ways to find helpful information.

So why is bash an important command? Simply, it's the way we interact with the computer. And now you know how to do that.

Demonstration

Okay, the best way to embed this in your memory is by typing in your own terminal window.

Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows 10.

Here we go, so bash is running by default. Type bash --help for usage, long options, and look here is a useful command bash -c help.

$ bash --help GNU bash, version 4.3.30(1)-release-(x86_64-pc-linux-gnu) Usage: bash [GNU long option] [option] ... bash [GNU long option] [option] script-file ... GNU long options: --debug --debugger --dump-po-strings --dump-strings --help --init-file --login --noediting --noprofile --norc --posix --rcfile --restricted --verbose --version Shell options: -ilrsD or -c command or -O shopt_option (invocation only) -abefhkmnptuvxBCHP or -o option Type `bash -c "help set"' for more information about shell options. Type `bash -c help' for more information about shell builtin commands. Use the `bashbug' command to report bugs.

Next, let's try it. bash -c with the argument help.

$ bash -c help GNU bash, version 4.3.30(1)-release (x86_64-pc-linux-gnu) These shell commands are defined internally. Type `help' to see this list. Type `help name' to find out more about the function `name'. Use `info bash' to find out more about the shell in general. Use `man -k' or `info' to find out more about commands not in this list. A star (*) next to a name means that the command is disabled. job_spec [&] history [-c] [-d offset] [n] or hist> (( expression )) if COMMANDS; then COMMANDS; [ elif C> . filename [arguments] jobs [-lnprs] [jobspec ...] or jobs > : kill [-s sigspec | -n signum | -sigs> [ arg... ] let arg [arg ...] [[ expression ]] local [option] name[=value] ... alias [-p] [name[=value] ... ] logout [n] bg [job_spec ...] mapfile [-n count] [-O origin] [-s c> bind [-lpsvPSVX] [-m keymap] [-f file> popd [-n] [+N | -N] break [n] printf [-v var] format [arguments] builtin [shell-builtin [arg ...]] pushd [-n] [+N | -N | dir] caller [expr] pwd [-LP] case WORD in [PATTERN [| PATTERN]...)> read [-ers] [-a array] [-d delim] [-> cd [-L|[-P [-e]] [-@]] [dir] readarray [-n count] [-O origin] [-s> command [-pVv] command [arg ...] readonly [-aAf] [name[=value] ...] o> compgen [-abcdefgjksuv] [-o option] > return [n] complete [-abcdefgjksuv] [-pr] [-DE] > select NAME [in WORDS ... ;] do COMM> compopt [-o|+o option] [-DE] [name ..> set [-abefhkmnptuvxBCHP] [-o option-> continue [n] shift [n] coproc [NAME] command [redirections] shopt [-pqsu] [-o] [optname ...] declare [-aAfFgilnrtux] [-p] [name[=v> source filename [arguments] dirs [-clpv] [+N] [-N] suspend [-f] disown [-h] [-ar] [jobspec ...] test [expr] echo [-neE] [arg ...] time [-p] pipeline enable [-a] [-dnps] [-f filename] [na> times eval [arg ...] trap [-lp] [[arg] signal_spec ...] exec [-cl] [-a name] [command [argume> true exit [n] type [-afptP] name [name ...] export [-fn] [name[=value] ...] or ex> typeset [-aAfFgilrtux] [-p] name[=va> false ulimit [-SHabcdefilmnpqrstuvxT] [lim> fc [-e ename] [-lnr] [first] [last] o> umask [-p] [-S] [mode] fg [job_spec] unalias [-a] name [name ...] for NAME [in WORDS ... ] ; do COMMAND> unset [-f] [-v] [-n] [name ...] for (( exp1; exp2; exp3 )); do COMMAN> until COMMANDS; do COMMANDS; done function name { COMMANDS ; } or name > variables - Names and meanings of so> getopts optstring name [arg] wait [-n] [id ...] hash [-lr] [-p pathname] [-dt] [name > while COMMANDS; do COMMANDS; done help [-dms] [pattern ...] { COMMANDS ; }

And voila, there are the 60 or so commands called builtins. Shift-PgUp (to scroll up one page), Shift-PgDn (to scroll down one page). bash includes this set of commands. Are you still confused?

This discussion is unique, because we're in bash, we've been using bash every time we open the terminal, and it's the default program loaded at startup. And you've seen builtins. Look (above) there's cd from video 8, exit from video 1 and pwd from video 6.

So why did I, unconventionally, explain the bash command this early in the Playlist? Well, I hope this helps you understand the relationship between bash, its builtins, and how to find help.

A Final Tip

Okay now you know how to use bash. And you know the syntax for commands, options and arguments.

One last tip about the bash command. Many Linux distributions come with a variety of shell options like bash and in the next tutorial I'll show you how to find which ones are available.

Okay, thanks for visiting today. I hope this was a fun introduction to the bash command.


Learn More About The Series

For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:


What's Next?

The learning journey never stops. Subscribe to be a part of it.

  • For the Outline to all 100 tutorials, click Outline.
  • To go back to the cd command, hit Back.
  • To learn to print to the screen with the cat command, click Next.

Outline Back Next

~/ home  / tech  / linux essentials  / bash command



 
 
Keywords:
linux bash shell
linux bash
bash shell commands
bourne again shell
bash terminal
default shell
bash builtins
bash built-in
unix bash
bash basics
linux shell commands
default shell in Linux
bash command
bash tutorial