BSD DevCenter
oreilly.comSafari Books Online.Conferences.

advertisement


FreeBSD Basics

Useful Commands

08/09/2000

FreeBSD comes with a lot of simple yet powerful commands designed to make your computing work easier. No matter how long you've used any type of Unix system, you'll still discover new shortcuts and new ways of doing things more efficiently. As my grandmother used to say, there's more than one way to skin a cat.

In this article, we'll discuss commands that help you remember who you are, where you are, how to find things, and how to start thinking like a Unix geek when it comes to accomplishing tasks.

I love the concept of virtual terminals and usually run all 8 along with an XWindows session. At a typical moment, I'll have a PPP session running, another terminal with an e-mail client open, a couple of terminals with different man pages open, another terminal where I'm trying out commands as root, another terminal where I'm trying out commands as a regular user -- you get the idea. With this increased functionality comes increased confusion. I use several commands to help me navigate this mess.

If I forget which terminal I left a man page at, the PrintScrn key will scroll through all virtual terminals in increasing order. If I'm not running an X Window session, I can continue to rotate through terminals 1 to 8 forever. If I am running an X Window session, it will stop at terminal 9, the X Server.

If I enter a terminal and wish to know which one it is, I use the tty command:

tty
/dev/ttyv4

Note that this is actually virtual terminal 5 as they are numbered starting from 0. If I leave this terminal, Alt-F5 will get me back there.

If I want to know who I am in this terminal, I can use whoami:

whoami
root
If I want to know who is logged into any terminal, I can use who:
who
genisis          ttyv0   Jun  3 15:45
genisis          ttyv1   Jun  3 15:46
genisis          ttyv2   Jun  3 21:09
genisis          ttyv3   Jun  3 21:10
genisis          ttyv4   Jun  3 21:27
genisis          ttyv5   Jun  4 09:40
genisis          ttyv6   Jun  4 09:43
genisis          ttyv7   Jun  4 10:46

Note the difference between who and whoami. On ttyv4, I originally logged in as genisis, then became superuser. The who command will tell you who has the login shell but does not return information on non-login shells. Also, because my X Window session is not a login shell, ttyv8 does not display in this output.

If I forget where I am in the directory structure, I use pwd:

pwd

which will show my present working directory:

/usr/home/genisis

Good rule of thumb: Never make or delete files or directories without first using pwd to double-check that you really are where you want to be.

Now, if I've lost all track of time:

date
Sun Jun  4 11:15:46 EDT 2000

or worse, can't remember what day it is:

cal
     June 2000
Su Mo Tu We Th Fr Sa
             1  2  3
 4  5  6  7  8  9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30

or need to know what day Christmas falls on in the year 2020:

cal 12 2020

   December 2020
Su Mo Tu We Th Fr Sa
       1  2  3  4  5
 6  7  8  9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31

or what day of the week the Declaration of Independence was signed:

cal 07 1776

     July 1776
Su Mo Tu We Th Fr Sa
    1  2  3  4  5  6
 7  8  9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31

For two last geek trivia bits on cal to amaze your friends and confound your enemies; try:

cal 9 1752

   September 1752
Su Mo Tu We Th Fr Sa
       1  2 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

The missing dates are due to the switch from the Julian to the Gregorian calendars. And:

ncal -e
April 23 2000

will show which date Easter falls on; use -o if you want to know the date for Orthodox Easter.

By now, you're probably convinced that I'm a wonderful typist who has so carefully typed into this article the calendars you are viewing. Let's take a look at my history list:

h

   110	date > /usr/home/genisis/cal
   111  cal > /usr/home/genisis/cal
   112	cal 12 2020 > /usr/home/genisis/cal
   113	cal 07 1776 > /usr/home/genisis/cal
   117	cal 9 1752 > /usr/home/genisis/cal
   122	ncal -e > /usr/home/genisis/cal
   134	h > /usr/home/genisis/cal

I hate to type and use the > redirector a lot. This redirector is used if you want to save the results of a command to a file; the syntax is always the same:

command > filename

I wanted you to see the output for each of the commands in the above history list, so I redirected them to a file, then pasted that file into my document. Note that I overwrote the same file seven times; this happened because I only used one > redirector.

Pages: 1, 2

Next Pagearrow





Sponsored by: