The Linux Command Line Part 3

Published on January 21, 2023 at 7:18 am by LEW

Introduction

In this post we will examine a few more commands, and there uses. Noting to complex at this point, as we are still learning to crawl. Specifically we will be looking at man (manual pages), whoami, and pwd (print working directory). Additionally we will take a look at where the command binaries (files) reside on your drive. This means we will touch, just a tinny bit, on the Linux File Structure.

We want to touch on man pages because that should be your first resource when you have questions. While there are some variations on then concept out there (like info pages), man will be your first go to on system reference, and is installed by default in many distributions.

In addition, it is a good place and time to start learning a little bit about the Linux file system layout. What we will cover will be very simple. However if you are so inclined, the Linux File System Hierarchy can provide much more information.

Man (Manual) pages

The first thing we need to do is determine if the man command is installed on our system. To do this simply type;

$ man

If man is not present, then bash will generally respond with;

-bash: man: command not found

If man is present then the typical response will look like this;

What manual page do you want?
For example, try ‘man man’

If the man command returns command not found, you will need to install the man-db package for your distribution. Most Debian based distributions (like Ubuntu or Mint) normally add this during initial install. However Arch does not. I am not sure about Gentoo, as I don’t use it much.

Depending on your situation, you can request your system administrator add the command, or ask whoever did the install for you. If you struggled though the install on your own, then for Arch the install command for a normal user would be;

$ sudo pacman -S man-db

The man page Database Sections

The manual pages are divided into sections. It is important to understand this, as it has a direct effect on what results you will get, as an argument can appear in multiple sections. In general (there are some exceptions) the sections are numbered 1 to 8. The sections are commands, system calls, library functions, special files, file formats, games, miscellaneous, and system administration.

The man page Layout

Generally man pages have a around a five section page layout (depending on the entry, there are exceptions). The minimum page layout usually consists of name, synopsis, description, examples, and see also. Other possible sections that can be any of the following; options, exit codes, environment, history, bugs, author, etc.

A man page Example

We used the echo command in our last post. Lets take a look at the man page for echo.

$ man echo

At then top of the page we find ECHO(1), which tells us w are in the command section of the man data base.

The Name section tells us the command name and what it does (prints a line of text). The Synopsis shows us how then command should be formatted and used. The Description lists options and escape sequences for the command. After that we deviate with an Author, Copyright, and Reporting Bugs sections. In the See Also section at the end we find information about ho to access additional documentation.

The whoami Command

Now lets learn another easy command, whoami. The first thing we want to do is pull up the man page for the command.

$ man whoami

From the man page we know the command is in section 1. We also learn that it prints the effective user name. It also only has a couple of options (–version and –help). Next step is to try the command with the –help option.

$ whomami --help

This prints a very short abbreviated version of the man page to the screen, giving us the basics of using the command. Using the –version option tells us not only the version of the command, but the author and copy write information.

Running the command by itself simply returns the current user.

$ whoami
rt

This might not seem to useful, especially on a home computer. But remember Linux is a multi user environment, and the command can be useful to the system administrator in such an environment. We use it here because it is a simple command that helps us get our feet wet.

The pwd Command

Taking a quick look at the man page for pwd, we can see it has a few more options than the last command. We can see it is a command (section 1), and that its function is to print the name of the current/working directory.

This command is a little more useful to us, depending on how ones PS1 prompt is setup. The PS1 prompt may give you the full path, or it may just show the current directory with no path. In the later case, pwd will give us the path.

Remember how our home directory is abbreviated as “~”. when we issue the pwd command, we get the actual path as the returned text.

$ pwd
/home/rt

The same applies to links (we have not covered yet, but will), pwd provides the actual path.

Command Binaries and the PATH variable

Most of the commands we will use from the command line are located in a couple of places. Remember our home directory path was /home/rt. There are two additional folders that are at the same level as the /home dierectory. They are the /bin and the /sbin directories.

The /bin directory is short for binaries, and the /sbin directory is short for system binaries.  Most of the commands we will be using are in one of these two directires.

I bring this up now, because in the next post we will explore the CD command and go more in depth into the file system.

Conclusion

In this post we talked about man pages, and used it to view information about diff rent commands.

It may seem we are moving a little slow, but we are building a proper foundation.

Next time around we will explore the cd and ls commands, as well as look at relative paths, absolute paths, and links.

The Linux Command Line Part 1; An Introduction

The Linux Command Line Part 2; The Prompts, some basics

The Linux Command Line Part 3; echo, whoami, pwd

The Linux Command Line Part 4; cd and ls

The Linux Command Line Part 5: ln, cat, more, less

Add New Comment

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