Verified and Tested 08/28/15

Introduction

Nothing is more frustrating than wanting to do something and not knowing how to do it.  In this How-to, we will be going over the some of FreeBSD’s more popular commands so we could make our lives easier and work more effective.

Prerequisites

You need a FreeBSD server that is configured with a static IP address.

Hierarchy Manual in FreeBSD

In FreeBSD, sometimes it can be difficult to remember so many directories and what they contain. Similar to Linux systems there is a manual that you can bring up and refresh your memory and continue working on your task. This is the directory Hierarchy manual, and it can be view with the following command.

man hier

An example of the "man hier" command An example of the “man hier” command

Hard Drive and Memory Information in FreeBSD

To find out information about your hard drive and how much space you have available or are consuming, the following command can help you accomplish this task. It will display this information in a very simple way. Go for it!

df -h

This is the default output of the df -h command in FreeBSD This is the default output of the df -h command in FreeBSD

If you would like to see how much RAM is available or assigned to your FeeBSD server, grab the following command that will display the real memory (total amount) and the available memory (available amount).

grep memory /var/run/dmesg.boot

An example of the "grep memory /var/run/dmesg.boot" command This is the default output of the grep memory command in FreeBSD

Current OS Version in FreeBSD

If you are not sure of the exact version of FreeBSD that is on your system, this can be completed with the following command. It will display the running version of FreeBSD on your system.

uname -a

An example of the "uname -a" command An example of the “uname -a” command

Package Information in FreeBSD

Knowing what you currently have installed on your FreeBSD server is very important because it helps in keeping things in order.  To find out what Packages and version of those packages, copy the command below and paste it in your terminal.

pkg info

This is the default output of the pkg info command This is the default output of the pkg info command

Installing and Uninstalling Packages in FreeBSD

FreeBSD uses Packages as their program/software name convention. If you would like to install any package into your FreeBSD system, this could be accomplished with the command replacing the brackets and package with the one you want to be installed:

pkg install [package]

This is the default output of the pkg install command This is the default output of the pkg install command

You can also run the following command replacing the brackets and package with the one you want to be removed:

pkg remove [package]

This is the default output of the pkg remove command This is the default output of the pkg remove command

Listing Files, Changing Directories and Printing current Directory in FreeBSD

The ls(list) command is used to view files within specified directories. To view the files under your current directory run the following command.

ls

You can also change or navigate through different directories within FreeBSD with the following command:

cd

 

An example of using the '"cd" and "ls" commands An example of using the ‘”cd” and “ls” commands

Although the following command applies to many Linux Operating Systems, it can also be used in FreeBSD. It is beneficial because it prints the directory that is currently being used. This helps out if you are not sure in what directory you find yourself in. Give it a try!

pwd

This is the default output of the pwd command in FreeBSD This is the default output of the pwd command in FreeBSD

Creating and Removing Files in FreeBSD

Creating files can be a bit can be tricky if you are not familiar with FreeBSD or Linux. To create a file in FreeBSD, it is done using the touch command. Input the following command replacing the brackets and myfile with the file that you want to be created(note: then you use your vi Text editor to make changes in the file):

touch [myfile]

An example of using the "touch" command An example of using the “touch” command

You could also remove files with the rm command. Copy and paste the following command replacing the brackets and myfile with the file that you want to remove or deleted.

rm [myfile]

An example of using the "rm" command An example of using the “rm” command

Moving and Copying Files in FreeBSD

Furthermore, you could move files from one place to the other following the command below replacing the myfile with your files name and location with the path that you want to place that file.

mv myfile location

An example of using the "mv" command An example of using the “mv” command

To copy a file in FreeBSD, this can be accomplished by simply replacing the myfile with your files name and myfile2 with the name of the copied file.

cp myfile myfile2

An example of using the "cp" command An example of using the “cp” command

Making/Removing Directories in FreeBSD

If you would like to create/make new directories in FreeBSD, this could be accomplished with the following command replacing the brackets and mydir with the new directory that you want to be created.

mkdir [mydir]

An example of using the "mkdir" command An example of using the “mkdir” command

To remove a previous or newly created directory, this could be accomplished with the following command replacing the brackets and mydir with the specified directory that you want to be removed.

rmdir [mydir]

An example of using the "rmdir" command An example of using the “rmdir” command

What next?

Congratulations! This completes this tutorial on FreeBSD Popular Commands. I hope that you find this information useful just like it was to me. Thank you for following along and feel free to check back with us for further updates, or learn more about our reliable HIPAA-compliant cloud hosting solutions.