---
title: "Bash fc Command :  Easily Wield the Bash Shell Like a Pro"
description: "Do you still re-type previously executed commands in Bash? Never again! Learn how to wield the power of Bash fc command and quickly edit and re-execute commands from the shell."
canonical: "https://adamtheautomator.com/bash-fc-command/"
---

# Bash fc Command :  Easily Wield the Bash Shell Like a Pro

> Do you still re-type previously executed commands in Bash? Never again! Learn how to wield the power of Bash fc command and quickly edit and re-execute commands from the shell.

Source: https://adamtheautomator.com/bash-fc-command/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Bash fc Command :  Easily Wield the Bash Shell Like a Pro](https://adamtheautomator.com/wp-content/uploads/2021/04/How-to-Wield-the-Bash-Shell-Like-a-Pro-with-the-Bash-fc-Command.jpg)

# Bash fc Command : Easily Wield the Bash Shell Like a Pro

[![](https://secure.gravatar.com/avatar/4147968aa2332aa682bcebf295e4e9d0eb2672dee3d9ae0523a00ac51e7d6017?s=192&d=mm&r=g)Bill Kindle](https://adamtheautomator.com/author/bill/)29 April 20215 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[Bash](/tag/bash/)[Linux](/tag/linux/)

Table of Contents

*   [Prerequisites](#h-prerequisites)
*   [About the Bash fc Command](#h-about-the-bash-fc-command)
*   [Listing Previous Commands](#h-listing-previous-commands)
*   [Editing and Re-Executing the Last Command](#h-editing-and-re-executing-the-last-command)
*   [Editing and Re-Executing a Previous Command](#h-editing-and-re-executing-a-previous-command)
*   [Editing and Re-Executing Multiple Commands](#h-editing-and-re-executing-multiple-commands)
*   [Re-Executing a Previous Command Without Editing](#h-re-executing-a-previous-command-without-editing)
*   [Conclusion](#h-conclusion)

Have you ever run a command in [Bash](https://www.gnu.org/software/bash/) and got an error because of a misspelled word? Or perhaps you forgot the last three commands you ran? Instead of re-writing or remembering previous commands, the [Bash](https://www.gnu.org/software/bash/) [`fc`](https://www.computerhope.com/unix/uhistory.htm) command can help make quick edits and re-execute previous commands.

In this article, you will learn how to leverage `fc` to edit and re-execute commands from your command history. After reading this guide, you’ll be wielding `fc` like the command line warrior you want to be!

## Prerequisites

This article will be a tutorial. If you plan on following along step-by-step, you need a Linux computer or a Windows 10 computer with [Windows Subsystem for Linux (WSL)](https://docs.microsoft.com/en-us/windows/wsl/about) enabled. This tutorial will be using [Ubuntu 20.04 LTS](https://adamtheautomator.com/install-ubuntu/).

Related:[The Ultimate Guide to Windows Subsystem for Linux (Windows WSL)](https://adamtheautomator.com/windows-subsystem-for-linux/)

## About the Bash `fc` Command

`fc` is not a Linux application but a built-in shell utility in Bash. Bash is available in most major Linux distributions. With a few keystrokes, the Bash `fc` command allows you to list, edit, or execute previous commands.

> _The `fc` command is also available in [Z Shell (ZSH)](https://en.wikipedia.org/wiki/Z_shell). But the example in this article will use `fc` in Bash._

Did you run a long command that turned out to be wrong? `fc` will save you from re-typing the whole command. Instead, `fc` lets you edit the command using the text editor of your choice. After saving your edits, the edited command(s) will automatically execute!

Ready to take `fc` for a spin? Let’s dive in!

## Listing Previous Commands

Have you moved away from your computer, came back, and forgot which command you ran last? Or maybe you can’t recall if you’ve executed multiple commands in the right sequence. What do you do? Relax, `fc` will help you remember. Here’s how.

1\. Open a Bash terminal on your computer.

2\. For `fc` to be of any good, it must have some kind of command history to work with. Since you’ve just opened a new terminal window, there may not be a command history yet. To build up a command history for testing, copy each command below and run it in your terminal. These commands are non-intrusive, and you’re not putting your computer in danger.

```bash
# Clear the screen
 clear
 
# print a string to the terminal session
 echo 'working on the command line with fc'
 
# show some system information
 uname -a
 
# use PS command to get process information
 ps aux
```

3\. Next, list all commands in the history by running the command below. The `-l` option instructs `fc` to only list all previous commands and not execute them.

```bash
fc -l
```

As you can see below, the `fc` command displayed all four commands that you previously issued. The numbers on the left indicate the order of when you executed each command.

![Listing command history with fc](https://adamtheautomator.com/wp-content/uploads/2021/04/Untitled-59-2.png)

Listing command history with fc

## Editing and Re-Executing the Last Command

Imagine a situation where you are installing an application, and you made a spelling mistake. As a result, the command fails. Instead of re-typing the whole command, why not edit the command and automatically re-execute? To do so, follow these steps.

1\. Simulate installing a non-existing application by running the command below in your terminal. Notice that you’ll intentionally misspell the application name `caffiene`.

```bash
sudo apt install caffiene -y
```

As a result, the attempted installation fails. You will get a message similar to the one below.

![Failed installation message](https://adamtheautomator.com/wp-content/uploads/2021/04/Untitled-60-2.png)

Failed installation message

2\. To correct the last command you executed, run the command below in the terminal. Doing so will open the command history buffer in the default text editor. In this example, the default text editor is [nano](https://www.nano-editor.org/).

```powershell
fc
```

The screenshot below shows the last command inside the nano editor.

![Editing the last command with nano. ](https://adamtheautomator.com/wp-content/uploads/2021/04/Untitled-61-2.png)

Editing the last command with nano.

> _If nano isn’t your preferred text editor, you can instruct `fc` to use a different editor, such as [vi](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/vi.html). To do so, include the `-e` option followed by the text editor name. For example, `fc -e vi` will open the command history in the vi text editor._

3\. Once you’re in the nano text editor, correct the application name spelling from `caffiene` to `caffeine`.

4\. After correcting the application name, press `CTRL+X` to exit nano.

5\. At the next prompt asking you to **Save modified buffer?**, press `Y` —> `Enter` to save the changes.

![Editing the last command and saving changes to the history buffer ](https://adamtheautomator.com/wp-content/uploads/2021/04/Untitled-62-2.png)

Editing the last command and saving changes to the history buffer

Immediately after exiting the text editor, `fc` automatically executes the command you edited.

![Automatically re-executing the edited command](https://adamtheautomator.com/wp-content/uploads/2021/04/Untitled-63-1.png)

Automatically re-executing the edited command

## Editing and Re-Executing a Previous Command

With `fc`, not only can you edit the last command you’ve run, but you can edit any of the previous commands you executed. For example, to edit the command `echo 'working on the command line with fc'`, follow these steps.

1\. List the previous command in the terminal by running the command below.

```bash
fc -l
```

2\. Find the command you want to edit from the command history list and take note of the number to its left. In this example, the command number is 2.

![Listing the command history and finding the command number to edit](https://adamtheautomator.com/wp-content/uploads/2021/04/Untitled-65-2.png)

Listing the command history and finding the command number to edit

3\. To edit the command with the entry number of 2, run the command below in the terminal. The command will open in the text editor for editing.

```powershell
fc 2
```

4\. Once in the text editor, now edit the command as needed.

5\. After editing the command, press `CTRL+X` to exit nano.

6\. At the next prompt asking you to **Save modified buffer?**, press `Y` —> `Enter` to save the changes.

![Editing a past command entry in the history buffer](https://adamtheautomator.com/wp-content/uploads/2021/04/Untitled-66-2.png)

Editing a past command entry in the history buffer

After saving the command and exiting the text editor, the command you edited automatically executes in the shell.

## Editing and Re-Executing Multiple Commands

If you think `fc` can only edit and execute one previous command at a time, then you’re in for a treat. Why? `fc` allows you to edit multiple previous commands, too! How is editing multiple previous commands useful? For one, you can change the order of command execution.

Suppose you want to edit the previous command numbers 2 to 7. To do so, proceed as follows.

1\. Run the below command in your Bash terminal and press **Enter**. The command below reads as `fc <space> 2 <space> 7`, which means that `fc` will open commands 2 to 7 for editing.

```bash
fc 2 7
```

2\. Next, edit the commands as needed. For this example:

*   Delete the `sudo apt install caffiene -y` command.
*   Swap the order of `uname -a` and `ps aux`.
*   Delete `clear`.

![Editing command history entries 2 through 7 at once](https://adamtheautomator.com/wp-content/uploads/2021/04/Untitled-67-3.png)

Editing command history entries 2 through 7 at once

3\. After editing the commands, press `CTRL+X` to exit nano.

4\. At the next prompt asking you to **Save modified buffer?**, press `Y` —> `Enter` to save the changes.

The commands you edited will automatically execute after exiting the text editor.

![Automatically re-executing the edited command](https://adamtheautomator.com/wp-content/uploads/2021/04/Untitled-68-2.png)

Automatically re-executing the edited command

## Re-Executing a Previous Command Without Editing

Suppose you only need to execute a previous command without editing first. `fc` has an option for that. Follow the steps below to execute a previous command from a specified entry in the history.

1.  List the previous command in the terminal by running the command below.

```bash
fc -l
```

2\. From the command history list, find the command you want to run again and take note of the number to its left. In this example, the command number is 2.

![Listing the command history and finding the command number to execute](https://adamtheautomator.com/wp-content/uploads/2021/04/Untitled-70-2.png)

Listing the command history and finding the command number to execute

3\. To execute the specific previous command, run the command below in the shell. The `-s` option instructs `fc` to skip editing and continue to execute command number 2.

```bash
fc -s 2
```

The screenshot below shows fc executed command number 2 from the command history.

![Executing a previous command from the history buffer without editing](https://adamtheautomator.com/wp-content/uploads/2021/04/Untitled-71-2.png)

Executing a previous command from the history buffer without editing

## Conclusion

This article set out to pique your interest in a useful but often missed and forgotten command called `fc`. You learned how to use `fc` to avoid re-typing previously executed commands, which can be a waste of time.

With the knowledge that you now have about `fc`, is it something you think you’d use? Or will you still favor re-typing commands in the shell instead? Make a wise choice!

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fbash-fc-command%2F&text=Bash%20fc%20Command%20%3A%20%20Easily%20Wield%20the%20Bash%20Shell%20Like%20a%20Pro)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fbash-fc-command%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fbash-fc-command%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2022/06/Understanding-Bash-If-Else-and-other-Conditional-Statements.jpg)

### [Understanding Bash If Else and other Conditional Statements](/bash-if-else/)

Discover the ins-and-outs of Bash If Else and Bash Case scripting in this example-driven tutorial by ATA Learning!

![](https://adamtheautomator.com/wp-content/uploads/2022/11/bash-xargs.jpg)

### [Learning the Bash Xargs Command Through Examples](/bash-xargs/)

Bash Xargs is a complicated and useful command. In this ATA Learning tutorial learn to take advantage of its many uses!

![](https://adamtheautomator.com/wp-content/uploads/2022/11/Echo-Command-in-Bash-Shell-Discover-the-Many-Uses.jpg)

### [Echo Command in Bash Shell : Discover the Many Uses](/echo-command-in-bash/)

Learn about all the ways to utilize the echo command in Bash to create better scripts and master the Bash shell!

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
