Loading
All articles
C++ 20 min read

What Is Bash? A Simple Guide to the Bourne Again Shell and the Command Line

A friendly, jargon-free guide to Bash, the program inside the black text window that developers type into. Have a first real conversation with it, see what happens when you press Enter, rename 1,000 photos in under a second and read your first script.

nbkhope
On this page

You've seen it in movies: a hacker in a dark room, typing into a black window full of glowing text. Real life is less dramatic, but that window is real, and millions of people use it every day. Very often, the program inside it is called Bash.

Bash is a shell: a program that lets you control a computer by typing commands instead of clicking icons. Its name stands for Bourne Again SHell, a pun we'll explain later. It runs on most of the world's web servers, comes with nearly every Linux system, is still included on every Mac and can run on Windows too. This article explains, in plain language, what Bash is, how it works and why something so old-fashioned-looking is still everywhere.

What is a shell?

When you use a phone or a laptop, you usually talk to it with taps and clicks. A shell is another way in: you type what you want in words, and the computer answers in words.

A good way to picture it is a restaurant:

The shell is a go-between. In the computer: you type a command and press Enter; the terminal is the window that shows the text; Bash reads the command and starts programs; the programs and the kernel, the core of the system, do the work. The answer travels back the same way and appears on your screen. In a restaurant: the customer orders in plain words; the table is where orders and food go back and forth; the waiter understands the order and passes it on; the kitchen does the real work. People often mix up the words. The terminal is just the window. The shell is the program inside it that understands what you type. Bash is the most famous shell. Others include zsh, fish and Windows PowerShell

You are the customer. The terminal is the table: just the window where text goes in and out. Bash is the waiter: it understands your order and passes it to the kitchen. The kitchen is the rest of the computer: the programs that do the actual work, and the kernel, the core of the operating system that controls the hardware.

That's why people say "open a terminal" and "type it in the shell" almost as if they were the same thing. They work together, but they're different programs. On a Mac, for example, the window is an app called Terminal, and the shell inside it can be Bash or its cousin zsh.

A first conversation with Bash

Here is a real session. We typed these commands into Bash 5.2 on Ubuntu Linux, as a user named maria, on a computer named laptop, and copied the answers exactly:

A first conversation with Bash, using real commands and their real answers, typed into Bash 5.2 on Ubuntu Linux. 1, pwd, which means print working directory, answers /home/maria. 2, mkdir vacation makes a new folder. 3, cd vacation goes into it. 4, touch beach.jpg sunset.jpg notes.txt creates three empty files. 5, ls lists what is here: beach.jpg, notes.txt and sunset.jpg. 6, ls *.jpg lists only the names ending in .jpg: beach.jpg and sunset.jpg. 7, echo "Hello, $USER" answers Hello, maria, because Bash fills in your user name. 8, echo $((365 * 24)) answers 8760, the hours in a year, so it is a calculator too. 9, bash --version answers GNU bash, version 5.2.21. No mouse, no menus: you type a request, press Enter and read the reply

A few things to notice:

  • Each line starts with maria@laptop:~$. That's the prompt: Bash's way of saying "I'm listening".
  • After cd vacation, the prompt changed to ~/vacation$. Bash always shows you where you are.
  • Many commands, like mkdir and touch, print nothing at all when they work. In the shell, silence means success.
  • $USER was replaced with the word maria. Words that start with $ are variables: names that stand for a value.

Anatomy of a command

Every command follows the same simple pattern. Here's one that copies a photo into a folder called backup:

Anatomy of a command. The prompt, maria@laptop:~$, is Bash telling you it is listening: maria is who you are, laptop is which computer, the tilde is which folder (tilde means your home folder), and the dollar sign means "ready, go ahead and type". The command cp -v beach.jpg backup/ has four parts. cp is the command: what to do, copy. -v is an option: how to do it, v for verbose, tell me what you did. beach.jpg is argument 1: copy what. backup/ is argument 2: copy to where. The real reply from cp is 'beach.jpg' -> 'backup/beach.jpg'. Spaces separate the pieces, which is why file names with spaces need quotes. Options usually start with a dash
  • The command is the verb: what to do. Here, cp means copy.
  • Options change how it's done. They usually start with a dash: -v asks cp to tell us what it did.
  • Arguments are what to do it to: copy beach.jpg into backup/.

Command names are short because people type them all day: cp for copy, mv for move, ls for list, rm for remove. They look cryptic at first, but there are only a handful you use often.

What Bash does when you press Enter

Bash doesn't just pass your words along. Before running anything, it reads your command and rewrites it. Bash has a feature, set -x, that shows the rewritten command, so we used it to watch this happen:

What Bash does when you press Enter, a real example traced with Bash's set -x feature, in a folder with beach.jpg, sunset.jpg and notes.txt. Step 1, read the line: you typed cp *.jpg ~/old. Step 2, split it into words at the spaces: cp, *.jpg and ~/old. Step 3, expand the shortcuts, where the star means any name and the tilde means your home folder: the command becomes cp beach.jpg sunset.jpg /home/maria/old. Step 4, find the program by checking each folder listed in the PATH variable: /usr/local/sbin, /usr/local/bin, /usr/sbin and finally /usr/bin, where cp is found. Step 5, run /usr/bin/cp with 3 arguments and wait for it to finish. Step 6, show the prompt again, ready for the next command. The copy program never sees the star or the tilde. Bash rewrites the command first, so that every program gets wildcards for free

The most useful trick here is the *, called a wildcard. *.jpg means "every name that ends in .jpg". Bash swaps it for the real list of files before the program even starts. So cp, mv, rm and every other program get wildcards for free, without having to know anything about them.

One quirk to know about: if nothing matches, Bash leaves the * as it is. When we emptied the folder and ran the same kind of copy, we got this real error:

cp: cannot stat '/home/maria/vacation/*.jpg': No such file or directory

cp went looking for a file literally named *.jpg. It's a classic surprise for beginners, and a good reminder that it's Bash, not the program, that handles the *.

Ten everyday commands and five handy keys

You can get surprisingly far with very few commands:

Ten everyday commands and five handy keys. Commands: pwd shows which folder you are in. ls lists the files in this folder. cd photos goes into the photos folder. cd .. goes up one folder. mkdir trip makes a folder named trip. cp a.txt b.txt copies a.txt to b.txt. mv a.txt notes/ moves, or renames, a file. cat a.txt shows what is inside a file. grep pizza a.txt finds the lines that say pizza. man ls opens the manual for ls, and q quits. Keys: Tab finishes a name for you, for example type cd Doc and press Tab. The up and down arrows scroll through the commands you typed before. Ctrl + C stops the command that is running. Ctrl + R searches your past commands. Ctrl + L clears the screen. Careful with rm, remove: it deletes files right away. There is no trash can to get them back

The keys matter as much as the commands. Experienced users rarely type a full file name: they type the first few letters and press Tab, and Bash finishes it. The up arrow brings back the last command, so fixing a typo takes a second. And Ctrl + C is the emergency brake when something runs longer than you expected.

Bash can also connect commands together. The | symbol, called a pipe, sends one command's output into the next, and > saves output to a file:

ls *.jpg | wc -l          # list the photos, then count the lines: prints 2
ls *.jpg > photos.txt     # save the list of photos in a file

Pipes are one of the great ideas from Unix, and the Unix article shows six small programs piped together to find the most common words in a story.

Why type when you can click?

For one file, clicking is fine. The shell shines when you need to do the same thing many times. Imagine your camera named 1,000 vacation photos IMG_0001.jpg to IMG_1000.jpg, and you want them called beach-trip-0001.jpg and so on. We tried it:

Rename 1,000 photos: clicking vs one line of Bash. Turn IMG_0001.jpg through IMG_1000.jpg into beach-trip-0001.jpg through beach-trip-1000.jpg. By hand: about 83 minutes, if each file takes 5 seconds: click, F2, type, Enter. With Bash: under 1 second, measured. The one line is: for file in IMG_.jpg; do mv "$file" "beach-trip-${file#IMG_}"; done. "for file in IMG_.jpg" means for every file whose name matches IMG_*.jpg. "do" means do this. mv "$file" "beach-trip-${file#IMG_}" renames it, because mv takes the old name and the new name, and ${file#IMG_} is the name with IMG_ cut off, like 0001.jpg. "done" is the end of the loop. Measured in an Ubuntu container: the loop renamed 1,000 files in 0.80 to 0.91 seconds over six runs. The 5 seconds per file by hand is an estimate

That one line is a loop: "for every file matching IMG_*.jpg, do this, then you're done". In our test it renamed all 1,000 files in less than a second, every time. By hand, even at a brisk 5 seconds per file, it would take well over an hour, and you'd probably make a few typos along the way.

This is the real reason the shell has survived for 50 years. Clicking is easy to learn, but it doesn't scale. Typing commands takes a little learning, and then it lets you do a thousand things as easily as one.

Scripts: recipes of commands

If you find yourself typing the same commands again and again, you can save them in a file and run the file. That file is a Bash script, and it's where Bash stops being just a command line and becomes a programming language:

A Bash script is a recipe of commands saved in a file, called backup.sh. Line 1, #!/bin/bash, is the "shebang": run this file with Bash. Line 2 is a comment, a note for humans only. Line 3, destination=~/backup, is a variable: it gives a value a name. Line 4, mkdir -p "$destination", makes the folder, and the dollar sign reads the variable. Line 5, shopt -s nullglob, makes the loop run zero times if there are no photos. Line 6, count=0, starts counting at zero. Lines 7 to 10 are a loop: for every photo in ~/vacation/*.jpg, copy it and add 1 to the count. Lines 11 to 15 are a decision: if the count is 0, say "No photos found.", otherwise say how many photos were copied. fi, "if" backwards, is the end of the decision. Running it, for real: chmod +x backup.sh allows it to run, x for execute. ./backup.sh runs it. Its reply: Copied 2 photos to /home/maria/backup

The script has everything a programming language needs: variables to remember things, loops to repeat things and decisions (if) to choose what to do. Line 5 handles the quirk from earlier: without it, an empty folder would make cp complain about a file called *.jpg. With it, the script correctly says "No photos found." We tested both cases.

Scripts like this quietly run the modern world:

  • Servers use them to start up, make backups and clean old files, often on a schedule, like every night at 2 AM.
  • Installing software on Linux often means running a script someone else wrote.
  • Automated builds, like GitHub Actions, run their steps with Bash by default on Linux. Every time a developer pushes new code, Bash scripts test it and ship it.
  • Docker containers, the boxes most cloud apps run in, are usually set up with shell commands.

Where you'll find Bash

  • Linux: Bash is the standard shell on most Linux systems, from Ubuntu laptops to the servers that run websites and the cloud.
  • Mac: Bash was the Mac's default shell from 2003 to 2019. Since macOS Catalina, new accounts use zsh instead, but Bash is still installed. Apple ships an old version, 3.2, because newer versions use a license (the GPLv3) that Apple avoids.
  • Windows: Windows has its own shells, Command Prompt and PowerShell. Since 2016, it can also run real Bash through WSL, the Windows Subsystem for Linux. Many developers also use Git Bash, which comes with Git for Windows.
  • Small computers: the Raspberry Pi, routers and many other gadgets run Linux, and usually have a Bash or Bash-like shell inside.

How many people actually use it? In the 2025 Stack Overflow Developer Survey, nearly half of the developers who answered said they had worked with Bash or another shell in the past year:

About half of developers surveyed use Bash or another shell. 2025 Stack Overflow Developer Survey: which languages did you work with in the past year, with 31,771 answers. JavaScript 66.0%, HTML/CSS 61.9%, SQL 58.6%, Python 57.9%, Bash/Shell 48.7%, TypeScript 43.6%, Java 29.4%, C# 27.8%, C++ 23.5%, PowerShell 23.2%, C 22.0%, PHP 18.9%, Go 16.4%, Rust 14.8%. People could pick several languages, so the bars add up to more than 100%. Bash/Shell comes fifth, just ahead of TypeScript and ahead of Java, C# and C++

Bash is rarely anyone's main language. Nobody builds a phone app in it. But it's the glue that holds everything else together, which is why it ranks above famous languages like Java and C++.

Bash keeps growing

Bash is over 35 years old, and it's still being improved. We downloaded six versions from GNU's official archive and measured two things: how long the printed manual is, and how many lines of code the program has:

Bash keeps growing, measured in each release package on ftp.gnu.org. Pages in the printed manual: version 1.14 from 1996, 37 pages; 2.0 from 1996, 46; 3.0 from 2004, 63; 4.0 from 2009, 68; 5.0 from 2019, 81; 5.3 from 2025, 96. Lines of source code: 1.14, 79 thousand; 2.0, 89 thousand; 3.0, 145 thousand; 4.0, 163 thousand; 5.0, 188 thousand; 5.3, 231 thousand. The manual, man bash, was typeset with groff on US letter pages. Lines of code count every C, header, grammar and builtin file in the package, including bundled libraries such as Readline, which handles typing and history. Version 1.14 is the oldest one GNU still offers

The manual more than doubled, from 37 to 96 pages, and the code nearly tripled. Yet a script written for Bash in the 1990s will usually still run today. Bash's maintainers work hard not to break old scripts, because so much of the world depends on them.

You can read that 96-page manual yourself: type man bash (press q to quit). It's famously long, and famously complete.

The family of shells

Bash didn't appear out of nowhere. It's part of a family of Unix shells going back to 1971:

The family tree of shells. The Thompson shell, from 1971, was the first Unix shell. From it descend the Bourne shell, sh, by Stephen Bourne in 1979, and the C shell, csh, by Bill Joy in 1978. From the Bourne shell descend ash, later dash, from 1989, light and fast; the KornShell, ksh, by David Korn in 1983; and Bash, by Brian Fox for GNU in 1989. Bash also borrowed features from the C shell. From the C shell descends tcsh, an improved csh from 1981. The Z shell, zsh, by Paul Falstad in 1990, borrowed features from ksh, Bash and tcsh. Separate families: fish, from 2005, with its own rules, and PowerShell, from Microsoft in 2006. The name is a pun: the "Bourne Again SHell" is the Bourne shell born again as free software

In 1979, Stephen Bourne at Bell Labs wrote the Bourne shell, known simply as sh. It became the standard Unix shell, and its way of writing commands and scripts is still the basis of most shells today.

But the Bourne shell belonged to AT&T. In the 1980s, the GNU Project, started by Richard Stallman to build a completely free Unix-like system, needed a free shell. In 1988, programmer Brian Fox started writing one for the Free Software Foundation, and released it in 1989. It understood Bourne shell scripts, added the best features from other shells, and got a playful name: the Bourne Again SHell, a pun on "born again".

A few years later, Chet Ramey took over its care. He has maintained Bash for more than three decades, which makes him one of the longest-serving caretakers of any important piece of software.

When Linux appeared in 1991, it combined Linus Torvalds's kernel with GNU's tools, Bash among them. Linux took Bash everywhere Linux went, which today means most servers on the internet.

The day Bash made headlines

In September 2014, a security researcher named Stéphane Chazelas found a bug in Bash that had gone unnoticed since 1989. It was nicknamed Shellshock.

The problem was in how Bash read certain settings passed to it by other programs. A carefully crafted piece of text could trick Bash into running commands nobody asked for. Because many web servers used Bash behind the scenes, attackers could sometimes take control of a server just by visiting a web address with the wrong text in it.

Fixes went out within days, and system administrators around the world rushed to update. The episode was a wake-up call: some of the most important software in the world is maintained by very few people, often as a labor of love.

A short history

A short history of Bash, as a timeline. 1971: the Thompson shell, the first Unix shell. 1979: Stephen Bourne's shell ships with Unix Version 7. 1989: Brian Fox releases Bash for the GNU project. 1996: Bash 2.0, and Linux spreads Bash everywhere. 2003: Mac OS X 10.3 makes Bash the default shell. 2009: Bash 4.0 adds lists of named values. 2014: Shellshock, a 25-year-old bug, is found and fixed. 2016: Windows can run Bash, via Linux inside it. 2019: Bash 5.0, and the Mac switches to zsh. 2025: Bash 5.3, still maintained by Chet Ramey

Try it yourself

You almost certainly have a shell on your computer right now:

  • Mac: open the Terminal app (search for it with Cmd + Space). The shell will be zsh, which understands all the basic commands in this article. Type bash and press Enter to switch to Bash, and exit to go back.
  • Linux: open the Terminal app. It's very likely Bash already.
  • Windows: open PowerShell as an administrator and run wsl --install. After a restart, you'll have Ubuntu Linux with Bash inside Windows. Or install Git for Windows, which comes with Git Bash.

Then try a few safe commands:

1pwd                      # where am I?
2ls                       # what's here?
3echo "Hello, $USER"      # say hello
4echo $((60 * 60 * 24))   # seconds in a day
5date                     # today's date and time
6history                  # everything you've typed so far

Two safety tips: be careful with rm, which deletes immediately with no trash can, and never paste commands from strangers on the internet into your terminal without understanding them. A shell does exactly what you tell it to, including the bad things.

Common questions

Is Bash a programming language? Yes. Bash is both a shell you type into and a scripting language, with variables, loops and decisions. It's great for gluing programs together and automating chores, and not meant for building big apps.

What's the difference between Bash and zsh? They're close cousins. Both understand nearly all the everyday commands, and most simple scripts work in both. zsh adds extra conveniences for typing, and Bash is more common on servers and in scripts.

Is the Windows Command Prompt the same thing? It's the same idea, a shell, but a different family. Command Prompt descends from DOS, and PowerShell is Microsoft's modern shell. Their commands are different: dir instead of ls, for example. See What Is the DOS Operating System? for that branch of the story.

What is sudo? A command that runs another command as the administrator, the user who's allowed to change anything. You'll see it in installation instructions, like sudo apt install firefox. It asks for your password because it's powerful.

Do I need Bash if I'm not a programmer? No, but a little goes a long way. If you ever need to rename hundreds of files, fix a Raspberry Pi project or follow technical instructions, knowing ten commands makes it much less scary.

Glossary

  • Shell: a program that reads commands you type and runs them.
  • Bash: the Bourne Again SHell, the most widely used shell, made for the GNU Project in 1989.
  • Terminal: the window that shows the shell's text. Also called a terminal emulator.
  • Command line: typing commands, as opposed to clicking in a graphical interface.
  • Prompt: the text, like maria@laptop:~$, that shows the shell is ready for a command.
  • Command: the first word you type, the thing to do, like cp.
  • Option: a setting that changes how a command works, usually starting with a dash, like -v.
  • Argument: what the command should work on, like a file name.
  • Wildcard: a pattern like *.jpg that Bash expands into matching file names.
  • Variable: a name that holds a value, read with $, like $USER.
  • Pipe: the | symbol, which sends one command's output into another.
  • Script: a file of commands that can be run like a program.
  • Shebang: the #!/bin/bash first line that says which program should run a script.
  • PATH: the list of folders where Bash looks for programs.

Wrapping up

Bash is the waiter between you and your computer's kitchen. You type a request in words, it expands your shortcuts, finds the right program, runs it and shows you the answer. Save a few of those requests in a file, and you have a script that can do in a second what would take an hour of clicking.

It was born in 1989 as a free copy of an older shell, named with a pun, and it now runs on most of the servers that make up the internet. You don't need to become an expert. Open a terminal, type pwd, then ls, then press the up arrow. You've just had your first conversation with Bash.

Thanks for reading!

Know someone who would enjoy this? Send it their way.

More articles

Read next

Comments

Be kind and specific. Comments with links from new accounts appear after a moderator reviews them.