Home

Blog

Understanding what a command does in terminal

April 26, 2025

Intro

When learning to code (or even after years of experience) you will eventually get stuck while using something. Most people go online or ask an AI assistant for help with their work, but don’t really know what it is doing to their machine. That can be risky and concerning to blindly execute whatever is thrown at you. That is why today I am going to go over some common commands, and tips for finding out what almost any command claims to do.

Disclaimer

Commands can claim to do one thing but actually be lying. Run code at your own risk.

Guide

Using the which command

Before you run anything, do you know if you even have the command or tool installed? Do you know where it is? Which one it is? Luckily this was thought of and the which tool was made. Pick a command and run:

which your_command_here

You should see something like:

~:$ which cat
/bin/cat

If you get a message it means first of all, it exists, secondly where it exists.

I just learned that where is also a command by running which where. What?

Using the man command

Now that we know that we have the tool installed, we can use the man command to learn more about what it claims to do. Start with:

man your_command_here

Don’t panic! This new window is normal, it should look like:

Name
CAT(1)                      General Commands Manual                    CAT(1)

NAME
     cat – concatenate and print files

SYNOPSIS
     cat [-belnstuv] [file ...]

DESCRIPTION
     The cat utility reads files sequentially, writing them to the standard
     output.  The file operands are processed in command-line order.  If file
     is a single dash (‘-’) or absent, cat reads from the standard input.  If
     file is a UNIX domain socket, cat connects to it and then reads it until
     EOF.  This complements the UNIX domain binding capability available in
     inetd(8).

     The options are as follows:

     -b      Number the non-blank output lines, starting at 1.

     -e      Display non-printing characters (see the -v option), and display
             a dollar sign (‘$’) at the end of each line.

:

This is a vim or less (honestly I can’t tell the difference) style window. You can use arrow keys to scroll through the manual page and first tip type the / key to search. try: /cat this will highlight and jump to all instances of the word “cat” in the file. You can use n to jump from word to word or Shift + N to go backwards.

Press ESC and then q to leave

The man pages are the documentation that the developers provide for their utility, so if you ever get stuck or don’t quite trust the output of an AI you can use this as a backup. (Again, the writers can lie, so always run code at your own risk)

History

Finally, you might forget and want to run a command again. This was also considered. The history command is here for this exact scenario. if you run

history 10

it will give you 10 lines of your command history. You can increase or decrease this number to your liking, or just not specify one at all for all of your history!

Another trick is to use the grep utility, which is as far as I’m concerned ancient magic. You can run:

history | grep "keyword (spelled right)"

search through your history for all lines that match that word.

Outro

Hopefully this guide has helped you with your development. Maybe you were just reading this out of interest. If so, perhaps you would like some of the other articles that I have: