ThisCalculator

Everyday

How to Exit the man Command in Linux (q, ZZ, and More)

Updated · Standard formula, shown below

This guide shows you how to leave the man command in Linux once you are done reading a manual page. You will learn the standard quit key, alternative exit methods, and what to do if the screen appears stuck. No prior knowledge is needed beyond having a terminal open.

What You’ll Need

  • A Linux or Unix-like system with the man command installed (present on virtually all distributions).
  • A terminal window or SSH session.
  • An open manual page (for example, type man ls and press Enter).

Step-by-Step

  1. Open a manual page – In your terminal, type man followed by the command you want to read, for instance man cp, and press Enter. The page will fill your screen, and you will be in the pager (usually less).
  2. Press the q key – The simplest and most common way to exit is to press the lowercase letter q on your keyboard. You do not need to press Enter or Ctrl – just tap q. You will be returned to your shell prompt immediately.
  3. If q does not work, try ZZ – Type Z twice in a row (uppercase, so hold Shift and press Z twice). This is the exit command for the less pager and works in most man pages.
  4. Use the exit command (rare) – If the man page is displayed with a different pager like more, you can type exit and press Enter. This is less common but works in some configurations.
  5. Press Ctrl+C or Ctrl+Z as a fallback – If the pager is unresponsive, press Ctrl+C (hold Control and press C) to interrupt, or Ctrl+Z to suspend the process. After Ctrl+Z, you will be back at the shell; type kill %1 to close the suspended job if needed.
  6. Close the terminal window as a last resort – If nothing else works, you can close the terminal window or tab. This will end the session, but it is not recommended for remote SSH connections because it may leave processes running.

Common Mistakes

  • Pressing Enter after q – You do not need to press Enter. Just tapping q exits immediately; pressing Enter may send a newline that does nothing, but some users think they must confirm.
  • Using uppercase Q – The key is lowercase q. Uppercase Q (with Shift) may not work in all pagers, though in less it does.
  • Holding down the key – Press and release quickly. Holding q can cause auto-repeat, which might exit and then type extra characters at the shell prompt.
  • Confusing man with the shell – When you are inside man, you are not at the shell prompt. Typing exit or quit without pressing Enter does nothing; you must use the pager’s quit command.
  • Forgetting about the pager – man uses an external pager (usually less). Knowing less commands helps, because the same q works there.

Tips

  • Search within man pages – While reading, you can press / to search for a term, then n to jump to the next match. This is useful before you exit.
  • Use man -w to find the file path – If you want to read a man page without the pager, type man -w ls to see the file location, then use cat or less on that file.
  • Change the default pager – You can set the PAGER environment variable to something like cat if you prefer to see the whole page at once (though this is unusual). For example, export PAGER=cat.
  • Exit with a single keystroke – The q key is universal in less and more, so once you learn it, you can exit any pager quickly.
  • Use man with a specific section – If you want to read a particular manual section, type man 5 passwd (for file formats) and then exit the same way.

Troubleshooting

  • Pressing q does nothing – This can happen if the man page is not using less but a different pager like most or vim in some configurations. Try ZZ, or press Ctrl+C to break out. If that fails, press Ctrl+Z to suspend, then type kill %1.
  • The screen is frozen – Sometimes the terminal may appear stuck because the pager is waiting for input. Press q once, then press Enter if needed. If the terminal is truly unresponsive, open a new terminal and run pkill less or pkill man to kill the process.
  • You see a colon prompt – Some pagers (like vim) show a colon at the bottom. In that case, type q and press Enter, or q! to force quit without saving changes.
  • Exiting leaves the terminal in a weird state – If the terminal display is corrupted after exiting, type reset and press Enter to restore it. This is rare but can happen with certain terminal emulators.
  • Remote SSH connection drops – If you are on SSH and press Ctrl+Z, the man process is suspended. Use jobs to see it, then kill %1 to terminate it.

Frequently Asked Questions

Do I need to press Enter after q?

No. The q key works immediately without Enter. Pressing Enter afterward is harmless but unnecessary.

Why does man use less?

Most Linux distributions set the default pager to less because it allows scrolling both up and down. The q key is the standard quit command for less.

Can I exit man with the Esc key?

No, the Escape key does not exit man. You must use q or ZZ. Pressing Esc may beep or do nothing.

What is the difference between q and ZZ?

Both quit the pager. q is a single keypress, while ZZ is two uppercase Z’s. In less, both work identically.

What if I accidentally press Ctrl+S?

Ctrl+S freezes the terminal output. Press Ctrl+Q to unfreeze it, then use q to exit man.

Does the exit command work in man?

No, exit is a shell builtin, not a pager command. You must use the pager’s quit key, typically q.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.