Ubuntu

How do I Clear/Delete the Current Line in the Terminal in Ubuntu 22.04?

How do I Clear Delete the Current Line in the Terminal in Ubuntu 22.04

Typing and spelling mistakes are quite common while typing commands in Terminal. When a wrong command is typed, an argument is missed, or spelling mistakes are made, a user usually utilizes the delete button to delete characters one by one in a forward direction or the backspace key on the keyboard to delete the characters one by one in a backward direction. Keyboard shortcuts enable an efficient way to Clear/Delete current lines in the Terminal.

This article will demonstrate the process of clearing/deleting the current line in Terminal on Linux/Ubuntu 22.04 LTS.

How to Clear/Remove the Current Line in the Ubuntu Terminal?

Linux/Ubuntu’s command line offers keyboard shortcuts that enable users to perform tasks more easily, efficiently, and productively. For example, if a current line has some errors, and needs to be erased. Then, instead of deleting characters one by one, a user can follow one of the below methods to delete an entire line in the Terminal:

  • Method 1: Reposition the Cursor at the Start and Clear the Current Line.
  • Method 2: Reposition the Cursor at the End and Clear the Current Line.

Method 1: Reposition the Cursor at the Start and Clear the Current Line

  • Launch the terminal with the shortcut key [Ctrl + Alt + T].

  • Press the Ctrl+A shortcut key on the keyboard to reposition the cursor at the start:

  • Now you are all set to clear the current line. For this purpose, all you need to do is hit the Ctrl+K shortcut key on your keyboard, consequently, you will see the following output:

  • All the text from the current line has been cleared successfully.

Method 2: Reposition the Cursor at the End and Clear the Current Line

  • Launch the terminal with the shortcut key [Ctrl + Alt + T].
  • Press the Ctrl+E shortcut keys to move the cursor at the end of the line:

  • Now press the CTRL + U to remove all the text of the current line:

  • All the text from the current line has been cleared successfully.

Bonus Tip: Recalling Deleted Commands

A few other useful terminal shortcuts are:

  • Ctrl+Y: Recall the deleted command.
  • Alt+Y: Recall the second last deleted command. This command is usually followed after Ctrl+Y.

Conclusion

The current line can be cleared by repositioning the cursor to the start of the line by using Ctrl+A and then by pressing Ctrl+K. Alternatively, you can hit the Ctrl+E keys to reposition/move the mouse cursor to the end of the line, and then pressing the Ctrl+U will delete all the text of the current line. This article has discussed how to clear the current line in Terminal on Linux/Ubuntu 22.04 LTS.

Similar Posts