FreeBSD: 102 Tips and Tricks

FreeBSD Tip: #61

To repeat the last command in the C shell, type "!!".
		-- Dru <genesis at>

FreeBSD Tip: #62

To save disk space in your home directory, compress files you rarely
use with "gzip filename".
		-- Dru <genesis at>

FreeBSD Tip: #63

To search for files that match a particular name, use find(1); for example

	find / -name "*GENERIC*" -ls

will search '/', and all subdirectories, for files with 'GENERIC' in the name.
      	--  Stephen Hilton <nospam at>

FreeBSD Tip: #64

To see all of the directories on your FreeBSD system, type

	find / -type d | less

All the files?

	find / -type f | less

FreeBSD Tip: #65

To see how long it takes a command to run, type the word "time" before the
command name.
		-- Dru <genesis at>

FreeBSD Tip: #66

To see how much disk space is left on your partitions, use

	df -h
		-- Dru <genesis at>

FreeBSD Tip: #67

To see the 10 largest files on a directory or partition, use

	du /partition_or_directory_name | sort -rn | head
		-- Dru <genesis at>

FreeBSD Tip: #68

To see the IP addresses currently set on your active interfaces, type
"ifconfig -u".
		-- Dru <genesis at>

FreeBSD Tip: #69

To see the last 10 lines of a long file, use "tail filename". To see the
first 10 lines, use "head filename".
		-- Dru <genesis at>

FreeBSD Tip: #70

To see the last time that you logged in, use lastlogin(8).
		-- Dru <genesis at>

FreeBSD Tip: #71

To see the MAC addresses of the NICs on your system, type

	ifconfig -a
		-- Dru <genesis at>

FreeBSD Tip: #72

To see the output from when your computer started, run dmesg(8).  If it has
been replaced with other messages, look at /var/run/dmesg.boot.
		-- Francisco Reyes <lists at>

FreeBSD Tip: #73

Want colour in your directory listings?  Use "ls -G".  "ls -F" is also useful,
and they can be combined as "ls -FG".

FreeBSD Tip: #74

Want to find a specific port, just type the following under /usr/ports
or one its subdirectories:

	make search name=<port-name>
	make search key=<keyword>

FreeBSD Tip: #75

Want to know how many words, lines, or bytes are contained in a file? Type
"wc filename".
		-- Dru <genesis at>

FreeBSD Tip: #76

Want to see how much virtual memory you're using? Just type "swapinfo" to
be shown information about the usage of your swap partitions.

FreeBSD Tip: #77

Want to strip UTF-8 BOM(Byte Order Mark) from given files?

	sed -e '1s/^xefxbbxbf//' < bomfile > newfile

FreeBSD Tip: #78

Want to use sed(1) to edit a file in place?  Well, to replace every 'e' with
an 'o', in a file named 'foo', you can do:

	sed -i.bak s/e/o/g foo

And you'll get a backup of the original in a file named 'foo.bak', but if you
want no backup:

	sed -i '' s/e/o/g foo

FreeBSD Tip: #79

When you've made modifications to a file in vi(1) and then find that
you can't write it, type ``<ESC>!rm -f %'' then ``:w!'' to force the

This won't work if you don't have write permissions to the directory
and probably won't be suitable if you're editing through a symbolic link.

FreeBSD Tip: #80

You can adjust the volume of various parts of the sound system in your
computer by typing 'mixer <type> <volume>'.  To get a list of what you can
adjust, just type 'mixer'.

FreeBSD Tip: #81

You can automatically download and install binary packages by doing

	pkg_add -r <URL>

where you replace <URL> with the URL to the package.  This will also
automatically install the packages the package you download is dependent on
(ie, the packages it needs in order to work.)

FreeBSD Tip: #82

You can change the video mode on all consoles by adding something like
the following to /etc/rc.conf:


You can use "vidcontrol -i mode | grep T" for a list of supported text
		-- Konstantinos Konstantinidis <kkonstan at>

FreeBSD Tip: #83

You can disable tcsh's terminal beep if you `set nobeep'.

FreeBSD Tip: #84

You can get a good generic server install by using the
instant-server port/package.  If you have ports installed, you can
install it by doing

	# cd /usr/ports/misc/instant-server
	# make install && make clean

as root.  This will install a collection of packages that is appropriate for
running a "generic" server.

FreeBSD Tip: #85

You can install extra packages for FreeBSD by using the ports system.
If you have installed it, you can download, compile, and install software by
just typing

	# cd /usr/ports/<category>/<portname>
	# make install && make clean

as root.  The ports infrastructure will download the software, change it so
it works on FreeBSD, compile it, install it, register the installation so it
will be possible to automatically uninstall it, and clean out the temporary
working space it used.  You can remove an installed port you decide you do not
want after all by typing

	# cd /usr/ports/<category>/<portname>
	# make deinstall

as root.

FreeBSD Tip: #86

You can look through a file in a nice text-based interface by typing

	less filename

FreeBSD Tip: #87

You can make a log of your terminal session with script(1).

FreeBSD Tip: #88

You can often get answers to your questions about FreeBSD by searching in the
FreeBSD mailing list archives at

FreeBSD Tip: #89

You can open up a new split-screen window in (n)vi with :N or :E and then
use ^w to switch between the two.

FreeBSD Tip: #90

You can permanently set environment variables for your shell by putting them
in a startup file for the shell.  The name of the startup file varies
depending on the shell - csh and tcsh uses .login, bash, sh, ksh and zsh use
.profile.  When using bash, sh, ksh or zsh, don't forget to export the

You may also like...