Open In App

fc Command in Linux with Examples

Last Updated : 22 Mar, 2024
Like Article

As we all know that LINUX is command friendly and while working on LINUX, you may deal with very long commands that may include long paths or really difficult syntax, and imagine what if working with such commands you do a minor mistake which will require re-writing of the entire command synopsis and its arguments in order to execute it again successfully. Now, there are two solutions to this – either re-write the entire syntax or simply use


command that allows you to




the commands previously entered to a shell without re-writing them again. This command line utility really comes to help while editing long commands. So, the


command is used to list, edit or re-execute the commands previously entered into an interactive shell. Here’s the syntax of fc command :

//syntax of fc command

fc [-e ename] [-lnr] [first] [last]
fc -s [pat=rep] [command]

where the


refers to the options available for



-e ename

refers to the editor you want to use for editing.




here is for specifying the range .

Using fc command

To easily understand the use of fc command and how does it work let’s take a simple example where you want to change your working directory to


and by mistake while changing your directory you write


instead of


, in this case you can simply use

fc command

to edit the previously entered path. After you enter the incorrect directory path you’ll see something like this :

then you can just simply type


command and after writing fc command your editor will open up so that you can now edit the previously entered command like shown below :


after editing your path you can exit your editor and after exiting


command will



cd kt/kartik/thakral

like shown below :

Using fc command with options

  • Using -l option : This option allows you to see some of the previously entered commands in your terminal i.e this lists the lines of previously entered commands instead of editing.
  • Using -n option : As shown above while using -l option fc command lists the lines along with the line numbers, but in case if you want to list the lines without line numbers you can simply use -n option with -l option as shown below :
  • Using -r option : This option can also be used with -l option to just reverse the order of lines i.e newest commands are listed first now as shown below :
  • Using first and last : Suppose you want to just edit a particular set of commands, in that case you can use first and last arguments as shown below :
  • Using -e option : The choice of editor to edit the demands totally depends on user and with the help of -e option user can choose editor of his choice, you just have to pass the name of editor with -e option as shown below :

Applications of fc command

  • fc command is the best way to edit the previously entered commands in the case of a minor mistake without re-writing the entire command syntax and argument again.
  • It can also be used to list the previously entered commands in the terminal which can be helpful in case you are working with some new commands.
  • fc command in a way lets you know the command history.

Previous Article
Next Article

Similar Reads

Ccat – Colorize Cat Command Output command in Linux with Examples
ccat is a command-line tool for Linux and OSX, which is similar to the cat command in Linux. But the difference between cat and ccat is that the ccat shows the content of the file with the syntax highlighted. Currently, ccat supports the following programming languages. JavaScriptJavaRubyPythonGoCJSONInstallation of Ccat First, we are going to see
2 min read
How to Display Command History in Linux | history Command
The command-line interface in Linux provides powerful tools for users, and mastering command history is essential for efficient navigation and retrieval of previously executed commands. The history command is a valuable utility that allows users to view and search through their command history. In this comprehensive guide, we will explore the vario
4 min read
select command in Linux with examples
select command in Linux is used to create a numbered menu from which a user can select an option. If the user enters a valid option then it executes the set of command written in select block and then ask again to enter a number, if a wrong option is entered it does nothing. If user enters nothing and simply press 'enter' the option menu gets print
1 min read
ZIP command in Linux with examples
ZIP is a compression and file packaging utility for Unix. Each file is stored in a single .zip {.zip-filename} file with the extension .zip. Zip is used to compress files to reduce file size and is also used as a file package utility. Zip is available in many operating systems like Unix, Linux, windows, etc.If you have limited bandwidth between two
7 min read
atrm command in Linux with examples
atrm command is used to remove the specified jobs. To remove a job, its job number is passed in the command. A user can only delete jobs that belong to him. Only superuser can delete any job even if that belongs to another user. Syntax: atrm [-V] job [job...] Options: -V : Used to print the version number atrm -V job : Job number of the job which i
1 min read
comm command in Linux with examples
comm compare two sorted files line by line and write to standard output; the lines that are common and the lines that are unique. Suppose you have two lists of people and you are asked to find out the names available in one and not in the other, or even those common to both. comm is the command that will help you to achieve this. It requires two so
5 min read
cmp Command in Linux with examples
cmp command in Linux/UNIX is used to compare the two files byte by byte and helps you to find out whether the two files are identical or not. When cmp is used for comparison between two files, it reports the location of the first mismatch to the screen if difference is found and if no difference is found i.e the files compared are identical.cmp dis
5 min read
expand Command in LINUX with examples
Whenever you work with files in LINUX there can be a situation when you are stuck with a file containing many tabs and whatever you need to do with a file requires that file with no tabs but with spaces. In this situation, the task looks quite simple if you are dealing with a small file but what if the file you are dealing with is very big or you n
3 min read
df Command in Linux with examples
There might come a situation while using Linux when you want to know the amount of space consumed by a particular file system on your LINUX system or how much space is available on a particular file system. LINUX being command friendly provides a command line utility for this i.e df command that displays the amount of disk space available on the fi
8 min read
tee command in Linux with examples
tee command reads the standard input and writes it to both the standard output and one or more files. The command is named after the T-splitter used in plumbing. It basically breaks the output of a program so that it can be both displayed and saved in a file. It does both the tasks simultaneously, copies the result into the specified files or varia
2 min read