PLEASE: Read everything on this sheet to properly complete these exercises
Your instructor may indicate some updates or changes to these exercises. The initial exercises are to finalize our machine configurations for use later today, and throughout the week, as well as to highlight some areas that are different from Linux - particularly methods by which you can install software.
Some Differences from Linux
For Those who Want More Practice
rehash
at the root shell prompt. This is only necessary when running a C shell (e.g., like /bin/csh).
1.) Use pw to create a new userid that you will use instead of root [Top]
First login to your computer if you have not already done so. Login as userid "root" using the password given at the start of class and that you used while installing FreeBSD.
Now that you are root you can create a new user account on your machine. If more than one person is using your machine, then be sure that you create an account for each and every person.
To create or remove a user account you should use the "pw" command. To get a feel for the power and complexity of this command take a look at its man pages:
# man pw
So, first pick a username that you want to use. For example, use your first name, last name, a combination of both, or whatever you prefer. For purposes of this example we use username. So, to add a new user to your system type:
# pw useradd username -m -s /usr/local/bin/bash
This creates the user username. The "-m" says add a new home directory of /usr/home/username and copies files from /usr/share/skel to the new user's home directory. The default shell "bash" will be used. Note that at this point the bash shell has not been installed on your machine. We'll be doing this in the upcoming exercises.
Next you need to set the password for the new userid, otherwise you won't be able to use the account properly. To do this use the passwd
command like this:
# passwd username
You will be prompted to enter in a new password, then to enter it again to verify. You need to pick a secure password. Note, as root (OK, and by default on FreeBSD!) you are allowed to pick any password you want, but you need to pick a secure password for your new account. Here are some quick guidelines to picking a secure password:
So, finally, let's change your new user's password using the command:
# passwd username
Please complete these steps:
Create the userid admin. This account may be used later for ssh exercises, and to allow your instructor access to your machine during the week if necessary. The password for the admin should be written at the front of the room. If not, please ask your instructor for the admin password now. The pw useradd
command format will be a bit different. This will be explained in exercise 5.
# pw useradd admin -m -s /usr/local/bin/bash -G wheel
# passwd admin (password for admin account given in class)
2.) Use sysinstall and pkg_add to install lynx, bash, and joe [Top]
For this exercise you need to be logged in as root.
FreeBSD has a large collection of preconfigured binary packages for each release that can be installed in a number of ways, including:
sysinstall
(don't use this now).pkg_add pkg_delete pkg_infoYou can read about each of these package commands using the "man" command, i.e.:
Remember, the pkg utilities under FreeBSD are very powerful as they can resolve dependencies, let you test installation before actually installing software, and keep track of what is installed with utilities to query the package database and assocated files.# man pkg_delete
# man pkg_add
For our first package we are going to install a text-based web browser called lynx. We'll use the sysinstall program to install lynx from the first disc of the FreeBSD CD-ROM installation set.
First,you can see if lynx is already installed on your system. Use the pkg_info command to do this. To get an idea of what packages are installed and what the default pkg_info output looks like type:
# pkg_info | more
You'll notice a pause while your machine prepares to show
all the packages installed, in alphabetical order. Press space to
scroll down the list, or ctrl-c to stop the list.
Now to check for just the lynx package type:
# pkg_info | grep lynx
or
# pkg_info lynx\*
If you don't understand what "grep" is doing type "man
grep". In optional exercises we go in to detail about the use of "grep", and the pipe facility represented above by the "|" character.
If lynx is already installed, for purposes of this exercise, first remove the package from our system (it's good practice!). You can do this by typing:
# pkg_delete lynx-2.8.5_2
Now type again:
# pkg_info | grep lynx
And, assuming that lynx is now not installed you should just get your prompt back.
Now to install lynx using the FreeBSD install CD-ROM do the following:
Insert the FreeBSD Disc 1 Installation CD in your machine's CD-ROM drive.At this point you take the following steps in the sysinstall menu system to choose the lynx package and install it:
Be sure that you are logged in as the root user:Now start the "sysinstall" utility by typing:
# sysinstall
At this point you will be prompted for disc 2 of the FreeBSD installation set. Most of the FreeBSD packages have been moved to this disc. Go ahead and follow the on-screen instructions to swap cd-roms.
Filesystem 1K-blocks Used Avail Capacity Mounted on /dev/acd0 660384 660384 0 100% /cdromIf you don't see the "/cdrom" entry, then type:
# mount /cdrom
again to make sure your CD-ROM (FreeBSD disc 2) is correctly mounted.
Installation of bash
Now let's install the bash package using a single command. As your FreeBSD CD-ROM is mounted under /cdrom, and as your instructor knows where the bash package resides on your CD, you could install bash by typing:
# pkg_add /cdrom/packages/shells/bash-3.1.10_1.tbz
But, rather than doing this, let's do this a bit differently. First use the cd (Change Directory) command to change to the initial cd-rom directory. Then we'll change to the directory /cdrom/packages/All. The "All" directory contains a list of all packages available to be installed on the cd-rom. It has the advantage that if you use pkg_add installing from this directory that if there are dependent packages that are needed, then they will be found and installed as well. So, first do:
Now let's look for the bash package. We can use the ls command to do this with a wildcard. You'll be practicing and learning much more about these basic system commands in a few more exercises. OK, so do:# cd /cdrom
# cd packages/All
# ls bash*
You should see bash-3.1.10_1.tbz on your screen. This is how you know the exact name of the package you want to install. In addition, once you have installed and are using the bash package it will be easy to use command completion to figure out complicated filenames like these. You'll see more of this in exercise 7. So, now that you know you want to install the package called bash-3.1.10_1.tbz (we're going to use the newer version vs. the 2.05b version that's listed), and you are already in the directory where this file resides, then you can simply type:
# pkg_add bash-3.1.10_1.tbz
and the bash package will be installed. By the way, bash is an alternate shell environment that you can use which has more features than the default shell sh. Notice the file extension of "tbz" on the file bash-3.1.10_1.tbz, this means that the file is actually a group of files that have been compressed and saved as a single file.
Installation of joe
Some of you may practice the use of the "vi" editor in later, optional exercises. vi is not as friendly as the optional "joe" editor. There are reasons for this, which we'll explain. But, for later exercises let's install "joe" right now, but this time we'll install from our local workshop server, "noc".
Note: If the server name is different than what is shown below your workshop instructor will let you know.
To install the "joe" editor from the local workshop server you can simply type the following:
# pkg_add ftp://noc/pub/FreeBSD/packages/6.1/All/joe-3.3,1.tbz (Note the comma)
This will download and install the joe 3.3,1 package to your machine from the local workshop server. Note that this editor has been added by us. It no longer ships with the default FreeBSD installation.
Do a little bit of exploring about what you have just installed by entering the following commands:
# rehash
# man lynx
(we'll discuss man a bit later)
# man bash
# man joe
# pkg_info lynx-2.8.5_2
# lynx www.freebsd.org
'q' (to 'q'uit lynx)
# joe
ctrl-c (to abort, you can say "no" to saving data)
3.) Installing two more packages (gmake, unzip) [Top]
For this exercise you need to be logged in as root.
During the week we will need two additional packages to do our work. The two packages we need are:
If you want to learn more about these three packages you can type:# pkg_add ftp://noc/pub/FreeBSD/6.1/packages/All/gmake-3.80_2.tbz
# pkg_add ftp://noc/pub/FreeBSD/6.1/packages/All/unzip-5.52_2.tbz
# rehash
# man gmake
# man unzip
4.) Installation of software using ports [Top]
For this exercise you need to logged in as root.
The ports collection, which we installed during the FreeBSD install, is larger than the packages collection available on the first FreeBSD install cd-rom. As of June 2005 there were over 13,000 ports available! The FreeBSD Handbook has an excellent discussion of using Ports in section 4.5. In a nutshell these are the key points to remember about ports:
To do this you should edit the file (use joe or vi) /etc/make.conf and add the following two lines to the end of the file:
If "noc" is not correct replace this with the correct name in use for the workshop!
MASTER_SITE_BACKUP=ftp://noc/pub/FreeBSD/distfiles/${DIST_SUBDIR}/
MASTER_SITE_FREEBSD=yes
# cd /usr/ports
# make search name=lsof
This will output something like:
Port: lsof-4.76.2
Path: /usr/ports/sysutils/lsof
Info: Lists information about open files (similar to fstat(1))
Maint: obrien@FreeBSD.org
B-deps:
R-deps:
WWW: http://people.freebsd.org/~abe/
From this you can see that the lsof utility resides in /usr/ports/sysutils/lsof. So, to install lsof on your system you do the following:
# cd /usr/ports/sysutils/lsof
# make
# make install
Make will download the lsof source (hopefully from our local server!), and then compile the source. "Make install" will place the compiled binary files in the appropriate directories on your system and update the appropriate configuration files if necessary. You can issue the single command "make install
" instead.
You can now type:
For more information. Finally, if you want to deinstall a port once it is installed, for instance lsof, you would do the following (please don't do this):# rehash (to re-read items in your directory path)
# man lsof
# cd /usr/ports/sysutils/lsof
# make deinstall
And, if you decided that was a mistake, you can now do the following to reinstall a port (after it's been installed once):
# cd /usr/ports/sysutils/lsof
# make reinstall
Also, note that the lsof port has been built and installed and will now appear as a package. You can type:
# pkg_info lsof\*
You will see that the lsof port now appears as an installed package. Thus, you could manipulate this software with package commands (pkg_info
, pkg_delete
).
If you do a "make clean" then "make reinstall" will no longer work for that port. If you want to see lsof
in action you can type:
In addition, FreeBSD installs the utilities# rehash
# lsof -i
fstat
, and sockstat
that can display the similar information.
5.) Using sudo for privileged commands [Top]
When you created your own user account username you did not place it in the wheel group. This means that you cannot become the root user from your username using the command su. This is a useful thing to be able to do if you don't want to have to logout and log back in each time you need to be root. In addition, the change we are going to make to the "sudoers" file, which controls access to the sudo command is based on your username being in the wheel group. So, the first thing you need to do is be sure you are logged in as root:
$ exit
Login: root
Now we are going to use the pw command to make a change to your username account make it a member of the wheel group. The wheel group is a special group in Unix that allows members to become root. To do this type:
# pw usermod username -G wheel
The "-G" indicates "group list". If your user already belongs to other groups you must include all these groups in list format (e.g. "group1,group2,group3,etc.), otherwise your user will be removed from the other groups when you issue this command. To see what groups a user belongs to you can type:
# groups username
Once your user is a member of the wheel group you can use the su (Substitute User identity) command to become another user without having to login and logout of your session.
To practice this you need to login as your username account now:
Now you can practice using su.# exit
$ Login: username
$ su - root
If you skip the "-" option, then you won't execute the
root login scripts. In general you can type "su user", or "su - user",
and switch to any user's environment.
Now let's drop back to your standard user account and try to do something that requires privileges:
You should get the message,# exit
$ less /etc/master.passwd
"/etc/master.passwd: Permission denied"
- Now try running the same command like this:
$ sudo less /etc/master.passwd
You noticed that this did not work, right? First we need to add a package called "sudo" to your machine, then we need to configure the file /etc/sudoers to allow you to use this facility. Let's get the package installed first. We'll use pkg_add and we'll get it from our local server:
$ su - (you must be root to install this package)
# pkg_add ftp://noc/pub/FreeBSD/6.1/packages/All/sudo-1.6.8.12_1.tbz
Now we need to configure the file /usr/local/etc/sudoers so that you can use the sudo
command:
This is a special utility to edit the /etc/sudoers file using vi, but to lock the file so that no one else can edit it while you are using# rehash
# visudo
visudo
. So, remember your vi commands and scroll down the screen until you find the following lines in the file (if you need help with vi ask your instructor or one of the classroom helpers):
(Note/hint: there are other ways of finding this line in vi. You could search for something using "/".).# Uncomment to allow people in the group wheel to run all commands #%wheel ALL = (ALL) ALL
Now, once you are here, just make one, small change. Remove the "#" symbol (it's a comment symbol) from in front of "%wheel". Once you do this save and quit from the file. So, your file should now look like:
And, to save and quite it's:# Uncomment to allow people in the group wheel to run all commands %wheel ALL = (ALL) ALL
:wq
That's it. You are now ready to run "sudo" as a general user (or, at least a general user in the wheel group). Make sure you exit from the root shell you are in:
# exit
And, now as a general user, try issuing the command:
$ sudo less /etc/master.passwd
You will be prompted for a password, and the first time you use sudo you'll receive a warning. The password you should enter will be your user account's password. This is different from Linux.
Type this in, and you should be able to view the
/etc/master.passwd file even though you are running as a standard user.
Try doing this again ("less /etc/master.passwd") and you'll notice that
you are no longer prompted for the root password. You can issue any
privileged command (pretty much) without needing a password at this
point. Once you login and logout again, then you'll have to enter a
password the next time you use sudo.
sudo is very useful to allow you to do system administration tasks on your machine without needing to be logged in as root. This can help to protect you from making mistakes running as root, which can be costly.
For this exercise you will need to be logged in as root.
Before we begin there are a few items to understand to put this in perspective:
http://www.freebsd.org/gnome/You can read about KDE on FreeBSD here:
http://freebsd.kde.org/
During our initial installation of FreeBSD we installed Xorg, but we have not yet configured it to run on our hardware. First, let's install Gnome using the sysinstall
utility.
Start the sysinstall
utility (as root) by typing:
# sysinstall
At this point you take the following steps in the sysinstall menu system to choose the Gnome packages and install them:
You should have noticed that multiple Gnome packages are automatically chosen as dependencies (a "D" appears in the selection boxes vs. an "X") when you choose just gnome2-2.10.0.
At this point you will be prompted for disc 2 of the FreeBSD installation set. Most of the FreeBSD packages have been moved to this disc. Go ahead and follow the on-screen instructions to swap cd-roms.
If there are problems with this let your instructor know. There are many possible bits and pieces to this that can go wrong. An easy work-around is to download the entire gnome folder from noc/pub/FreeBSD/packages/All to your local drive and then use pkg_add in the Gnome directory to install everything at once.
To get them to work there are quite a few variations of what might happen and how you can do this. If Xorg is able to correctly identify your video and monitor hardware you can do the following to configure your XWindow server and Gnome:
You may notice that we skip a step (# Xorg -configure
# cp /root/xorg.conf.new /etc/X11/xorg.conf
# /usr/X11R6/sbin/gdm
X -config /root/xorg.conf.new
). This is on purpose. If additional configuration is needed your instructor will have done this and will help you in class as necessary.
Once you log in using Gnome (log in as the user "admin" or as your username, but not as root) you may need to manually set the screen resolution to be something more reasonable. You can usually do this by going to the Screen Resolution utility under the System menu, then the Preferences menu.
 
This is a rather complex topic. But, in a nutshell, under FreeBSD 6.1, when your machine boots processes (that is daemons or services) are configured and/or started like this:
/usr/local/etc/rc.d/script-name.sh start
at system boot time. They may, or may not look in /etc/rc.conf for configuration settings.
$ man rc
Then, you should probably read this again...
Now, if you want to start a process each time your machine boot you generally add an item to /etc/rc.conf to indicate this. For instance, if you wanted to enable the ssh daemon (server) each time your machine started then you would add the line:
to /etc/rc.conf. If you look at /etc/defaults/rc.conf you'll see that sshd is not enabled in this file by default. By enabling sshd in /etc/rc.conf this overrides the setting in /etc/defaults/rc.conf. In addition, if you look in /etc/rc.d/ you'll find an sshd script file that starts this service.sshd_enable="YES"
To see how sshd is enabled initially do this:
$ grep sshd /etc/defaults/rc.conf
You should see something like:
These are the lines in /etc/defaults/rc.conf that deal with the ssh daemon. When you specified to enable the ssh daemon during installation then in the file /etc/rc.conf the lines that read:sshd_enable="NO" # Enable sshd sshd_program="/usr/sbin/sshd" # path to sshd, if you want a different one. sshd_flags="" # Additional flags for sshd.
became active. So, if your ssh program was not "/usr/sbin/sshd" for some reason, then in /etc/rc.conf you could add:sshd_program="/usr/sbin/sshd" # path to sshd, if you want a different one. sshd_flags="" # Additional flags for sshd.
to override what's in /etc/defaults/rc.conf.sshd_program="/new/directory/sshd" # new path to sshd
You could just put everything in /etc/defaults/rc.conf, but you don't want to do this. If you upgrade your system it's almost certain that /etc/defaults/rc.conf could be overwritten. In addition, this file is large and it would be hard to see the changes you had made if you were to do them in /etc/defaults/rc.conf.
To start a service manually you can use it's startup script by hand. For instance, try typing:
What is returned on the screen? It should be something like:$ su - (you must be root to run these commands)
# /etc/rc.d/sshd
So, you could typeUsage: /etc/rc.d/sshd [fast|force|one](start stop restart rcvar keygen reload status poll)
# /etc/rc.d/sshd status
to see if ssh is running. If it is, then try:
# /etc/rc.d/sshd stop
to start the service. Now type:
# /etc/rc.d/sshd start
to restart the service. Note the startup script option "reload" - This would let you make changes to the ssh configuration file(s) and then reload the service without actually stopping it so that it reads the new configuration. Note that already connected clients would not see this new configuration change until the logoff and log back in again.
Finally, and this is not obvious, if a startup script in /etc/rc.d has not been enabled in /etc/defaults/rc.conf or /etc/rc.conf, then even if you manually invoke the script it will not run. You will not get any indication of this other than the service not starting (i.e. use "ps auxw| grep servicename" and you won't see it started).
At this point take a closer look at /etc/rc.d/
# ls /etc/rc.d
and use "man" to read about some of the services. If you want to try and start and stop some of these services feel free to do so now, but remember you'll need to add 'servicename_enable="YES"' in /etc/rc.conf for the service to start.
8.) Disk partitions: how to view your disk [Top]
First, make sure you are logged in as your user and not as root.
Now in a terminal lets look at the partitions. Type:
$ df
$ df -h
What difference did you see between "df" and "df -h". How
can you see what your swap contains (note it was not listed using
"df")? Use this:
$ swapinfo
If you want to see more detailed information about your disk slices you can use the "fdisk" command. As a general user you are not allowed to run this program, so you must use sudo. Try this by typing:
$ sudo fdisk
Be careful with fdisk as you can remove slices, partitions, etc.
If you are interested in how much space files are taking up in a directory or a group of directories you can use the "du" command. Try it out by typing:
As usual you can get more information by typing "man du".$ du
$ du -h
Now that you've seen these methods for viewing disk information, you should be able to understand the output of the disklabel command a little better. The disklabel command is really the proper way to view the status of partitions in your FreeBSD slice at it will show you all your FreeBSD slice information no matter if a partition is mounted or not. In some cases this is critical if you are trying to troubleshoot problems and not all partitions have mounted. So, if FreeBSD resides on the slice /dev/ad0s1 on your disk, then to see disk information you can type (as a normal user):
$ sudo disklabel /dev/ad0s1
(Note, we are assuming we are using IDE drives) If we are This shows you output along these lines (will be different for this workshop):
As you can see it includes the "c" partition and "b" or the "swap" partition as well as filetypes.# /dev/ad0s2: 8 partitions: # size offset fstype [fsize bsize bps/cpg] a: 409600 0 4.2BSD 2048 16384 25608 b: 1433600 409600 swap c: 8385930 0 unused 0 0 # "raw" part, don't edit d: 1843200 1843200 4.2BSD 2048 16384 28552 e: 3072000 3686400 4.2BSD 2048 16384 28552 f: 1627530 6758400 4.2BSD 2048 16384 28552
9.) Getting help using manpages, docs, and the FreeBSD Handbook [Top]
Now that you have FreeBSD up and running you probably want to have a way to figure out how to use it when there are no instructors around, or other FreeBSD-knowledgeable people. First and foremost, make it a habit to read the man pages (MANual pages) for the commands that you use. You might be surprised at some of the things these commands can do! In any case, as you have seen, when in doubt about what a command does, or how it works simply type:
$ man command
Optionally, you might find some additional information for some commands typing:
$ info command
And, to get information about both these commands type:
After this there is a large amount of documenation available to you in serveral ways. For instance, if you look in:$ man man
$ info info
/usr/share/doc
you will find multiple FreeBSD articles in various languages available to you. In addition, the FreeBSD Handbook is available here under /usr/share/doc/handblook. If you wanted to start reading the FreeBSD Handbook from your local har drive you could either point a web browser to the file /usr/share/doc/handbook/index.html, or you could type the command:
$ lynx /usr/share/doc/handbook/index.html
Go ahead and type this command now to get a feel for what
information is available to you in the FreeBSD Handbook. Now let's look
at the FreeBSD FAQ by typing:
$ lynx /usr/share/doc/faq/index.html
After this, have a look at some of the available articles by doing:
Finally, there are several papers available as well. Try:$ cd /usr/share/doc/en/articles
$ ls
$ ls /usr/share/doc/papers
If you have a network connection, then you can go to http://www.freebsd.org/docs.html
for even more information. Become accustomed to the idea of using man
to get specific information about commands, and then using these
additional resources to get an overview of entire sub-systems of the
FreeBSD operating system. If you want to read the FreeBSD Handbook online it is available here
http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/
. If you want to understand FreeBSD concepts in more depth,
then the FreeBSD Handbook is really where you should begin.
10.) Shutdown and reboot your system [Top]
For this exercise you need to be root. It is better to close open files and programs (for example Firefox, vi, etc.), but it is not necessary. Before continuing read the man pages for shutdown, init, halt, and reboot (you'll see they are all connected):
# man shutdown
# man init
# man reboot
# man halt
Now, in a terminal do the following (save data, etc. as this will immediately reboot your machine!):
# shutdown -r now
Now your machine is rebooting. The "-r" stand for "reboot" and the "now" meant to take this action "now". This takes a moment. To stop your machine entirely you can use the command:
# halt
Or, you can also change your run level to run level 0, which is the same as "halt". So, you would write:
# init 0
And, to reboot this is the same as init 6, or:
# init 6
If you are running something like gdm for a graphical
login prompt on your machine you can usually use provided menu choices
to reboot or shutdown. The thinking is that once you have this level of
access, then you can simply turn off the machine's power if you wish.
At the very least it is much more friendly to use a software interface
to shutdown or reboot than pulling the power as processes have a chance
to clean up, save data, etc.
Note, sometimes it is useful to bring your machine down to runlevel 1, or "single user mode". For instance, if you are running X Windows and want to shut it down quickly (you'd really only do this on a desktop machine, by the way!), then you can open a terminal window as root (or use "su"), and then type"
# init 1
This will shut down X Windows, networking, and quite a bit more. Now you are in "single user mode". To get back to "multi-user mode" you simply type:
# exit
This exits your single-user modem shell and tells the system to go back to multi-user mode. Notice that the "runlevel" concept under FreeBSD is different than under Linux. The major difference are:
exit
runlevel 1 (or you can reboot).init c
if you with to block further logins under FreeBSD. 
The first time you login on your system after installation you will be presented with a prompt that looks something like this:
FreeBSD/i386 (name.domain) (ttyv0)
login:
At this point you can enter in "root" and, when prompted, the password we gave you in class for the root account. Once you are logged in you can work with an additional 7 virtual terminals if you wish. Actually, you can login from any virtual terminal you want at any time. To do this simply press:
ALT-FN
With "FN" being anything from the F1 to the F8 key. By default you are in ttyv0 which corresponds to the ALT-F1 keyboard sequence. Go ahead and login and then press:
ALT-F2
and login again. Feel free to do this on F3, F4, F8, etc. as you wish. You can cycle through each terminal session easily. This is an extremely useful technique when you wish to do more than one thing at the same time, but you are not using a graphical interface. Since we are loading the mouse daemon (mouse support) you can, also, copy and paste text between your virtual terminals. To do this go back to your initial login terminal by pressing:
ALT-F1
Try typing in the command:
$ clear
and pressing ENTER. Note that your screen clears and goes to the top. Now, you can easily recover your last command by pressing the UP-ARROW key on your keyboard once. Get used to doing this as it can be very useful if you have entered in a long command and made a mistake. You can press UP-ARROW to get the command back, then you can use the LEFT-ARROW to move your cursor to where the mistake is and correct it, then simply press ENTER to reissue the command. Note, you do not need to go back to the end of the command line before pressing ENTER.
In any case, you've pressed UP-ARROW once and should have the command "clear" visible. Now take your mouse and highlight just the command using the left mouse button. Without doing anything else with your mouse now press:
ALT-F2
to get to one of your other terminal sessions. Now just press the middle mouse button once. What happened? The text "clear" should have pasted on to your command line. Now you can press ENTER to execute the command. You can use this same trick to copy and paste in to editor windows, long and complex commands, between applications in a graphical environment, etc.
One final useful tip when working in your terminal sessions. As you type each command it is being saved in to a file called your "history file". This has a very useful purpose. Go back to your original login terminal pressing:
ALT-F1
and type the command:
$ history
You should see a list of commands you have entered in earlier. This list is probably short and it will even include incorrect commands you may have typed in. To quickly and immediately recover and execute a prior command make note of the number in the left-hand column next to the command and then just type:
$ !N
Where N is the number. So, if "clear" had been the second command, and you typed in:
$ !2
Then clear would appear on the command line very quickly and immediately execute. During the week you are going to be typing in some long and complex commands. The use of history can save you considerable time. If you press the UP-ARROW key repeatedly you can scroll through the previous commands you have entered beginning with the last command. Give it a try.
One very useful trick when using XWindow. If you need to escape your graphical environment and go to a console for some reason you can use the same virtual terminals, except that you press the keyboard combination:
ALT-CTRL-F1 through F8
At this point you will exit your graphical environemnt (KDE, Gnome, etc.) and be presented with a text console login prompt. Your graphical environment is still running as you left it. To get back to your graphical environment press:
ALT-CTRL-F9
Why might you need to do this? Here's one scenario:
You've just installed your favorite MTA (email server/Mail Transport Agent) and you typed something like (don't do this now):
pw usermod username -G mail
to place your user in the "mail" group. What just happened if your user was also a member of the "wheel" group and this is how you are using su
and sudo
? You can no longer become root in your session. To fix this you could go to a virtual console window, log in as root, and reissue the command above, but this time correctly:
pw usermod username -G wheel,mail
To fix this problem.
Hervey Allen