One of the most common problems encountered by newcomers is how to find the Linux command path that was just installed on Linux using a package manager (e.g. the apt command). There are many developers from the Windows world. Many of them are first time Linux users. Some use Linux with WSL and some deal with cloud servers directly via ssh. Let’s look at some common commands to list or find the path to Linux commands.
What are Linux commands?
On Windows, the default user interface is the GUI. however, Linux on the server side is set to a text interface by default. So terms like Bash, shell, console, command prompt, terminal, and many other names are often used. They all refer to the text interface.
Similarly, in a terminal, you type commands called Linux commands. For example, you can start a Linux terminal by pressing Ctrl- Alt-T. You can then type a simple command, such as the date command, to see the date and time of today. After pressing Enter to run it.
date, pwd, hello and ping are all Linux commands.
The different types of Linux commands
There are different types of Linux commands that you type in the terminal.
- internal or built-in shell commands builtin
- an external command/executable file/file file
- a shell function function
- an alias alias
- a keyword keyword
How to find out the Linux command types
We need to use the type command to show the path of a Linux command. It will also determine whether the command is a built-in shell, alias, function or external command. The syntax is :
For example, let’s find out the pwd command type.
What is the variable $PATH?
The PATH variable contains a set of directories where executable programs (such as ping, date, vi, docker, etc.) are stored on Linux or Unix-like systems. To see the current PATH, use the echo command/printf command.
Here’s what I saw.
To view all executable files stored in the /bin/ directory, run the ls command, as follows.
How to display information about commands
Use the command command as follows to list the path to Linux commands.
If you want a shell script to check if a command exists, use command check.
How to locate Linux commands
We can also easily get the path of a Linux command using the which command. For example: To print all possible matching paths, pass them as follows.
Get the path to a Linux command or manual page
Use the whereis command to find binaries, source code, and manual pages on disk for a given program or command. The syntax is:
How do I search the manuals and information pages only?
Find and locate command
We can also find files by name. For example, to search for a file named ‘date’ type.
Output of the positioning command.
Show help about Linux commands
We can use the whatis command, the help command and the man command or the info command.
Each Linux command comes with a manual page (a help page describing usage and syntax). In addition, it contains a short description. For example, the whatis command searches for a man page name. It displays the manual page description for any matching name in a short form.
For all external commands, we use the following man command or info command for detailed manuals.
Example manual page on Linux
For all Bash keywords and built-in functions, we use the help command.
A little exercise
The main obstacle for new Linux users is locating commands. But with the help of this simple page, you can now find command paths and even use the manual page to get help about them. Suppose you have Docker installed on your Ubuntu server. you can then use the following commands to find the path and get help.
I hope new Linux users and developers will find these commands useful. Happy coding.