• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
NameHero® Blog

NameHero® Blog

Web Hosting Tips & Resources From NameHero

  • AI Agents
    • OpenClaw
    • Claude Code
    • n8n
    • Hermes Agent
    • Open WebUI
    • Docker
  • Hosting
    • Web Hosting
    • WordPress Hosting
    • WooCommerce Hosting
    • Enterprise Hosting
    • Email Hosting
    • HeroicGuard
    • GPU Hosting
    • Website Builder
  • VPS
    • Managed VPS
    • Unmanaged VPS
    • Flex VPS
  • Reseller
  • Gaming
  • Domains
  • Account
  • Blog Home
  • Categories
  • Authors

Clearing The Terminal In Linux And Windows

Bhagwad Park

Published on: July 17, 2024

Categories: Linux Command Line, VPS Hosting 0

When starting with learning terminal commands on any operating system, clearing the screen is one of the things you learn. It’s also the most frequently used command and is easy to understand. But there’s a lot more to it than meets the eye. In this article, I’ll show you not only how to clear the screen in both Linux and Windows, but also how you can improve the experience and clear not just the terminal, but the terminal history of commands.

Table of Contents
  • Command to Clear the Screen in Linux
    • Using a Shortcut to Clear the Screen
    • Creating an Alias for the Clear Command
    • Clearing vs Scrolling
  • Command to Clear the Screen in Windows
    • Windows Command Prompt
    • The Windows PowerShell
    • Clearing vs Scrolling in Windows
  • Clearing the Terminal History
    • Clearing Terminal History in Windows
  • Conclusion

Command to Clear the Screen in Linux

In Linux, you type “clear” to clear the screen like this:

clear

It’s one of the few Linux commands not to have any options you can use, even though it relies on some environment variables to control its function.

Using a Shortcut to Clear the Screen

Less well-known, is that Linux has a shortcut to clear the screen:

Ctrl+L

If you clear the screen a lot, the shortcut can make your workflow smoother.

Creating an Alias for the Clear Command

If you don’t want to use the shortcut, another option to make your work more efficient is to create an alias for the clear command so you can type that instead of “clear”. For example, here’s an alias command you can use to replace it with the letter “c” instead:

alias c='clear'

I’d written a tutorial earlier on how to create an alias using the bashrc file. As you can see, Linux allows you to customize even a simple command like “clear”.

Clearing vs Scrolling

It’s important to note that in Linux, clearing the screen merely scrolls the window down by one screen. So while it appears blank, your previous command and its output are still visible by simply scrolling up.

Command to Clear the Screen in Windows

In Windows, there are typically two terminals you will use. The command prompt and the Windows PowerShell.

Windows Command Prompt

You can open the Windows command prompt by typing “cmd” into the Start Menu. To clear the screen, you use:

cls

This is the original DOS command that oldies like me learned in school when we first started working with computers. Even though Microsoft ditched DOS a long time ago, you can still mimic the interface using the command prompt.

Creating an alias command in the Windows command prompt is possible, but complicated. For example, you can create a temporary alias like this:

doskey c=cls

Where “c” is the character used as the alias for cls. However, this alias will only last for the duration of the session. To make it permanent, you need to do the following:

  1. Create a batch file with the “doskey c=cls” command
  2. Configure it to execute when the command line starts up, by adding the batch file to the startup parameters of the program shortcut you use to run it.

As you can see, creating aliases isn’t a core functionality of the command prompt, and you need to use hacks to make them permanent.

The Windows PowerShell

The Windows PowerShell is a more complex program than the command line and allows users to carry out powerful tasks like automation and scripting, whereas cmd only allows for batch executions. In PowerShell, you can use either of the two following commands to clear the screen:

clear

or

cls

So PowerShell subsumes the functionality of the command prompt. To create a temporary alias for the “clear” command in PowerShell, use the following command:

Set-Alias c Clear-Host

To make it permanent, you need to modify the $PROFILE file and you can do that by typing in:

notepad $PROFILE

If this file exists, PowerShell will open it. You can test if it exists using the following command:

Test-Path $PROFILE

If it returns “false”, it means the file doesn’t exist. You can create it by pasting the following code into PowerShell:

if (-not (Test-Path -Path $PROFILE)) {
New-Item -ItemType File -Path $PROFILE -Force
}

Now if you use “Test-Path”, it’ll show true as shown here:

Creating the PROFILE File in PowerShell
Creating the PROFILE File in PowerShell

As you can see, we’ve just created the $PROFILE file. Now using:

notepad $PROFILE

We can type the alias command into the file and save the changes.

Clearing vs Scrolling in Windows

Unlike Linux, when you clear a screen in the PowerShell of Windows, you don’t merely scroll up. Instead, PowerShell wipes everything clean, so you can’t see what you previously entered simply by scrolling. It’s gone forever.

Clearing the Terminal History

There’s a lot more you can clear in a terminal than just the screen. For one reason or another, you might want to clear your command history as well. For example, on Linux, here’s what you see when you type in the “history” command:

History Command in Linux
History Command in Linux

As you can see, all the commands I’ve typed in the recent past show up here. What might surprise you is that the command history persists beyond shell sessions. As you can see, I’ve exited twice recently, and it still shows up! So if, for whatever reason, you need to clear the history, you can use the following command:

history -c

This wipes out all the history in the current memory, so when you type “history” again, it only shows the most recent command – namely history. However, the history commands are not erased from all storage. They persist on the hard drive in the following location:

~/.bash_history

You can see below, that despite using the “history -c” command to erase the history, the file still contains the commands:

History Still Exists in File
History Still Exists in File

So if you want to clear the terminal history permanently, you need to erase them from the “.bash_history” file as well. You can do this by entering the following command:

> ~/.bash_history

The above command will erase everything in the .bash_history file. While using it, don’t forget to use it in conjunction with “history -c”, otherwise you won’t erase everything.

Clearing Terminal History in Windows

As we saw earlier, there are two ways to access the terminal in Windows. For the simpler program – the command line, there’s no way to clear the history other than simply opening and closing the program. The history isn’t stored anywhere else, so you don’t need to worry.

For PowerShell, on the other hand, you can use the following command:

Clear-History

Here’s an illustration of how it works:

Clearing History in PowerShell
Clearing History in PowerShell

As you can see, we can use the “Get-History” command to see the terminal history in PowerShell, and the “Clear-History” command erases it. Properly speaking, these are not “command”, but “cmdlets, but for practical purposes, it’s the same thing.

Like with Linux, the history in PowerShell is also stored in a file:

~\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt

If you want a sure way to clear the terminal history, just wipe out the contents of the above file. You can even delete it altogether using the following command:

Remove-Item -Path "$env:APPDATA\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt"

As you can see, there exist methods in both Linux and Windows to clear the terminal history from both in-memory, as well as from the file that stores the history.

Conclusion

The ability to clear the terminal seems like something very basic, but it’s also the most frequently used. If you want to make sure that you’ve cleared not just the text on the screen, but also the terminal history, then you will find this article useful!

Bhagwad Park Profile Picture
Bhagwad Park

I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!

Related Posts

Curl Headers, Cookies, and Authentication

You can do a lot more with curl, than just sending requests. Here's how to change the headers, the cookies, and how to authenticate users.

How to Use Ufw to Open Port 80 in Linux

In Linux, particularly on Ubuntu system, here's how we can use ufw to open port 80. No need to mess with IPTables directly!

Dealing with Cron Job Logs in Linux

Cron job logs keep track of which cron jobs run, and their details. This helps with troubleshooting and performance management.

Nmap Scan Types: How to Scan a Server’s Network

The "nmap" command allows you to scan a remote server and determine its network configuration. Here are the various nmap scan types.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow & Subscribe

Exclusive promos, content and more!


Most Popular Posts

NameHero’s Recommended WordPress Plugin and Theme Setup

WordPress Hosting vs. Web Hosting – What’s The Difference?

How To Increase The InnoDB Buffer Pool Size

How To Fix A Stuck All-in-One WP Migration Import

How To Add A Subdomain In Cloudflare

Top Categories

  • WordPress
  • WordPress Tutorials
  • OpenClaw Hosting
  • Enterprise Hosting
  • WooCommerce
  • Web Hosting
  • Resellers
  • Website Security
  • Website Development
  • Website Performance
  • VPS Hosting
  • SEO Tips
  • Announcements
  • Domain Registration
NameHero

NameHero® proudly provides web hosting to over 40,000 customers with 99.9% uptime to over 750,000 websites.

  • Master Card
  • Visa
  • American Express
  • Discover
  • Paypal
Products
  • Web Hosting
  • Managed VPS Hosting
  • Unmanaged VPS Hosting
  • Flex VPS Hosting
  • WordPress Hosting
  • WooCommerce Hosting
  • Reseller Hosting
  • Enterprise Hosting
  • GPU Hosting
  • Email Hosting
  • HeroicGuard
  • Domains
  • Website Builder
  • AI Agent Hosting
Help & Support
  • NameHero Blog
  • NameHero Gaming Blog
  • Support
  • Help Center
  • Migrations
  • Affiliates
  • Gaming Affiliates
  • Call 1-855-984-6263
Company
  • About Us
  • Contact Sales
  • Reviews
  • Uptime
  • We're Hiring

Copyright © 2026 Name Hero, LLC. All rights reserved.
NameHero® is a registered trademark.

  • Privacy Policy
  • Terms of Use
  • Acceptable Use Policy
  • Payment Policy
  • DMCA