Commands and Utilities

Here are some very basic commands and utilities at your disposal in FreeBSD. If you don't understand some of the commands, try using them.

When talking about directories there are a few things to note:
  / is the root directory
  ~/ is your home directory
  ./ is this directory
  ../ is up one directory
  * is all files in the current directory.

This section will contain the following format:

command - What the command does.
Usage: How to use the command.
  -flag What the flag does.
ex: an example of using the command.

Note that single letter flags not requiring any extra parameters may be grouped together (ls -al for instance) but others may not (mount -t vfat: nothing can be grouped with the -t).

Commands
Utilities

Commands

pwd - Print the current (working) directory.

man - Read manual pages.
Usage: man target (target could be a command, or a file, that may or may not have a man page).
ex: man ls shows the man page for ls.

cd - Change to the specified directory.
Usage: cd /directory
ex: cd ~/.. changes your directory to home.

ls - List files in the specified directory.
Usage: ls /directory (if no directory is specified, it lists the current directory)
  -a List all files (ls as root lists all files by default)
  -l Show in list format
ex: ls -l /dev lists all files in /dev in a list format.

cp - Copy files to and from different directories.
Usage: cp source destination (multiple sources may be declared at a time, * would be all for example).
  -R if a directory is being copied, copy everything within it (copy recursively).
ex: You need to copy your report to an already mounted floppy: cp ~/report /floppy

mv - Move files to and from different directories.
Usage: mv source destination (multiple sources may be declared at a time, * would be all for example). A different name can be chosen for the source and target files (can use to rename files).
ex: You need to move and rename your report to an already mounted floppy: cp ~/report /floppy/englishreport

su - switch user identity.
Usage: su username (if no username is specified, root is assumed).

chmod - Change file permissions.
Usage:chmod zzz filename. Only a user with write priveledges may use chmod on a file. Therefore each z corresponds to either owner, group, everyone, in that respective order. Each z is an octal number, 0-7, which is representative of that user's permissions.
0 = ___ (no permissions)
1 = __x (can execute the file)
2 = _w_ (can write to the file)
3 = _wx (can write to and execute the file)
4 = r__ (can read the file)
5 = r_x (can read and execute the file)
6 = rw_ (can read and write to the file)
7 = rwx (full permissions)
If a user can read the file, it will appear when they use ls. If they can write to it they can make and save changes. If a user can execute the file, they can run it.
ex: You've just created a new script, but by default it is not executable. You want full priveledges, you want others in the same group as you to be able to read and execute the script, but not change it. You don't want anybody else to be able to view it. use "chmod 750 ~/script"

chown - Change the owner of a file.
Usage: chown owner file
ex: chown xaenn /mnt if you want xaenn to own /mnt.

chgrp - Change the group of a file.
Usage: chgrp group file
ex: chgrp operator /mnt if you want /mnt to belong to the group operator.

passwd - Change password.
Usage: passwd username (if no username is specified, it is for the current user. Only root may change other user's passwords).

df - Display free disk space.
Usage: df -h file (-h will make the file size human readable)

du - Display disk usage.
Usage: du -h file
ex: du -h ./* shows the disk usage of all files in the current directory.

Utilities

dmesg - Displays the system message buffer.
Usage: By viewing the output of dmesg, most importantly you can view what hardware was detected at startup. However, when other events occur they will also show up in the output of dmesg, such as attaching a removeable harddrive.

grep - Search for patterns in files or chunks of text.
Usage: Most commonly grep is used in conjunction with piping (at least for me) to quickly filter through something to see if a certain line is present. For instance, we want to see if our printer was detected upon startup. So we issue the command dmesg | grep ulpt0. Then only the lines containing ulpt0 are displayed. This is much faster for looking through long outputs. The | (pipe) says take the output of dmesg and pass it to grep. You can also try piping with text viewers like less.

cat - Displays the contents of files.
Usage: cat file or cat file1 > file2. The first command displays file to the terminal. The second saves the contents of file1 into file2.

echo - Displays argument to the terminal.
Usage: For me echo is used to view the contents of variables. Try echo $PATH. You should see a bunch of directories separated by colons. These are all paths which are tried if you run a command without stating its path. Running ls for example works because of the path, otherwise you would have to specify /bin/ls.

tar - Create and extract tar archives.
Usage: tar output target
  -f read or write to file (definately use unless you have a tape drive)
  -c create archive
  -z (c mode only) compress the resulting tar with gzip (recommended)
  -x extract archive (gzip is automatically extracted if relevant).
ex: to archive a file use tar -czf file.tgz file and to extract it use tar -xf file.tgz.

top - Displays top system processes.
Usage: top brings you into a subscreen which let's you view your current processes. q exits top. Typing kill (k and then it auto completes) allows you to choose the PID of a process you want to end. More choices will be available depending on the height of your terminal.

ntpdate - Update system clock.
I restored an openstep ghost image on this computer and it set my clock back to 1997 (this was written in Dec 2004)! Some programs would not work correctly, and my system logs would be useless. Type "date" to see what your current system clock says. If it is off you can type "ntpdate ntp.nasa.gov" so sync your system clock with nasa's atomic clock.