Enterprise Software

Build Your Skills: Command essentials for FreeBSD, part 1

Commands and syntax for FreeBSD operating system

You’ve successfully logged on to your brand-new FreeBSD box for the first time, and now you’re staring at the cursor wondering what to do next. With the dizzying array of choices, logging on the first time can be intimidating for someone who’s unfamiliar with UNIX.
This article will introduce some basic commands to help you become more familiar with your FreeBSD system. In part 2, we’ll delve deeper into the command nomenclature and offer tips on maneuvering within the system and handling basic administrator tasks.
Create a new user account
The first rule on a UNIX box is never log on as root. Instead, log on as a regular user. If you have to log on as root, do it only long enough to perform administrative tasks. Now, if you forgot to create a user account during the install process, you have to log on as root. But you can then use the following command to create a regular user account:

This command will return you to the setup utility. To complete the process, follow these steps:
  • Choose Configure from the Main Menu screen and select User Management.
  • Choose User to access the Add A New User screen.
  • Enter the new user's name in the Login ID section.
  • Tab over to the Password section and enter a password.
  • Tab over to the Login Shell section and change it to /bin/csh.
  • Tab over to OK and press [Enter]; you now have a new user.
  • Arrow over to Cancel and press [Enter] twice, then select Exit Install to return to your prompt.

You will now want to log off as root and log on as the new user. Type exit and press [Enter]. Your prompt should look like this:

Type in your username, and the prompt will change to this:

Enter your password, and you'll see the welcome screen, plus an interesting fortune if you installed everything when you initially loaded FreeBSD.

The home directory
When you created your new user, FreeBSD created a home directory to keep that user's files in. Below are some commands that will show you what’s in there. At the prompt, type

This command will show your present working directory as your home directory. Then, type

where username is the user you just created. Now let's see what's in your home directory:

Not much to view. However, your directory is not empty. To see what’s hidden, add this switch:
ls -a

You'll notice that all the default files begin with a period, which indicates they are hidden files.

Virtual terminals
One of the neatest things about UNIX is the concept of virtual terminals. FreeBSD 4.0 comes with eight of them, which brings new meaning to the word multitasking. Press [Alt][F2] and notice that you’re presented with another logon screen. Log on as the user you just created. Now try [Alt][F3], and you’ll be presented with a third terminal. To switch between terminals, use [Alt][Fx] where x represents the number of the terminal you want. I'm notorious for using all eight terminals simultaneously, and this functionality is what I miss most when I'm not sitting at a UNIX box.

If you have created multiple user accounts, you can have different users logged on to different terminals. If you ever forget who you are when you enter a terminal, type this at the command prompt:

Then, if you type

UNIX will remind you where you are in the directory structure.

Listing files systems with man hier
Now that you know who you are and where you are, let's see what all these files are and where to find the applications that came with FreeBSD. Begin by using the command
man hier

This command gives a sketch of the file system hierarchy and shows where to find everything. If you see something that looks interesting, switch to another virtual terminal and use the cd command to change directories. You can then type ls to list its contents. Please note that anything listed in man hier is probably something you should not be deleting when performing housecleaning on your FreeBSD box.

Getting more information with whatis
If you come across a term you’d like to know more about, use the whatis command. For example, at the bottom of the man hier page is the reference See Also finger(1). If you are wondering what fingers have to do with FreeBSD, type
whatis finger

You will get a reply back stating
finger(1) - user information lookup program.

Whatis is also helpful in demystifying the device names found in the /dev directory. For instance, try typing this:
cd /dev
whatis da

Depending on the device, you’ll receive a reply similar to this:
da(4) - SCSI Direct Access Device Driver

Finding applications with whereis
If you need to find an application, use the whereis command. This will be especially useful when you start building applications and want to find out where they went. For example, if you type
whereis telnet

you will receive back the following:
telnet: /usr/bin/telnet

Not surprisingly, it’s in a bin directory, since it’s an application.

Stay tuned
In part 2 of this series, we’ll share some handy commands to help you maneuver within the system and perform a few useful administrative tasks.
If you'd like to share your opinion, please post a comment below or send the editor an e-mail.

Editor's Picks

Free Newsletters, In your Inbox