freebsd-tips revision 93518
178266SnikThis fortune brought to you by:
278266Snik$FreeBSD: head/games/fortune/datfiles/freebsd-tips 93518 2002-04-01 08:53:21Z joe $
378266Snik%
488035SmikehHaving trouble using fetch through a firewall? Try setting the environment
588035Smikehvariable FTP_PASSIVE_MODE to yes, and see fetch(3) for more details.
678266Snik%
778266SnikBy pressing "Scroll Lock" you can use the arrow keys to scroll backward
878266Snikthrough the console output.  Press "Scroll Lock" again to turn it off.
978266Snik%
1078266SnikWant colour in your directory listings?  Use "ls -G".  "ls -F" is also useful,
1178266Snikand they can be combined as "ls -FG".
1278266Snik%
1378266SnikIf you need to ask a question on the FreeBSD-questions mailing list then
1478266Snik
1578266Snik	http://www.freebsd.org/doc/en_US.ISO8859-1/articles/\
1678266Snik		freebsd-questions/index.html
1778266Snik
1878266Snikcontains lots of useful advice to help you get the best results.
1978266Snik%
2078266SnikIf you'd like to keep track of applications in the FreeBSD ports tree, take a
2178266Sniklook at FreshPorts;
2278266Snik
2378266Snik	http://www.freshports.org/
2478266Snik%
2578266SnikTo search for files that match a particular name, use find(1); for example
2678266Snik
2778266Snik	find / -name "*GENERIC*" -ls
2878266Snik
2978266Snikwill search '/', and all subdirectories, for files with 'GENERIC' in the name.
3078266Snik      	--  Stephen Hilton <nospam@hiltonbsd.com>
3178266Snik%
3278266SnikIn tcsh, you can `set autolist' to have the shell automatically show
3378266Snikall the possible matches when doing filename/directory expansion.
3478266Snik%
3578266SnikYou can `set autologout = 30' to have tcsh log you off automatically
3684001Smurrayif you leave the shell idle for more than 30 minutes.
3778266Snik%
3878266SnikIf you `set filec' (file completion) in tcsh and write a part of the
3978266Snikfilename, pressing TAB will show you the available choices when there
4078266Snikis more than one, or complete the filename if there's only one match.
4178266Snik%
4278266SnikYou can press up-arrow or down-arrow to walk through a list of
4378266Snikprevious commands in tcsh.
4478266Snik%
4578266SnikYou can disable tcsh's terminal beep if you `set nobeep'.
4678266Snik%
4778266SnikIf you `set watch (0 any any)' in tcsh, you will be notified when
4878266Sniksomeone logs in or out of your system.
4978266Snik%
5078266SnikNice tcsh prompt: set prompt = '%m %# '
5178266Snik%
5278266SnikNice tcsh prompt: set prompt = '%n@%m%# '
5378266Snik%
5478266SnikNice tcsh prompt: set prompt = '%n@%m:%~%# '
5578266Snik%
5678266SnikNice tcsh prompt: set prompt = '%n@%m:%/%# '
5778266Snik%
5878266SnikNice tcsh prompt: set prompt = '[%B%m%b] %B%~%b%# '
5978266Snik%
6078266SnikSimple tcsh prompt: set prompt = '%# '
6178266Snik%
6278266SnikIf you want df(1) and other commands to display disk sizes in
6378266Snikkilobytes instead of 512-byte blocks, set BLOCKSIZE in your
6493516Sjoeenvironment to 'K'.  You can also use 'M' for Megabytes or 'G' for 
6593516SjoeGigabytes.  If you want df(1) to automatically select the best size
6693516Sjoethen use 'df -h'.
6778266Snik%
6878266SnikTo change an environment variable in tcsh you use: setenv NAME "value"
6978266Snikwhere NAME is the name of the variable and "value" its new value.
7078266Snik%
7178266SnikTo change an environment variable in /bin/sh use:
7278266Snik
7378266Snik	$ VARIABLE="value"
7478266Snik	$ export VARIABLE
7578266Snik%
7682604SalexYou can use /etc/make.conf to control the options used to compile software
7782604Salexon this system.  Example entries are in /usr/share/examples/etc/make.conf.
7878266Snik%
7978266SnikTo do a fast search for a file, try
8078266Snik
8178266Snik	 locate filename
8278266Snik
8379027Smpplocate uses a database that is updated every Saturday (assuming your computer
8478266Snikis running FreeBSD at the time) to quickly find files based on name only.
8578266Snik%
8678266SnikIn order to search for a string in some files, use 'grep' like this:
8778266Snik
8878266Snik	 grep "string" filename1 [filename2 filename3 ...]
8978266Snik
9078266SnikThis will print out the lines in the files that contain the string.  grep can
9178266Snikalso do a lot more advanced searches - type 'man grep' for details.
9278266Snik%
9378266SnikYou can use the 'fetch' command to retrieve files over ftp or http.
9478266Snik
9578266Snik	 fetch http://www.freebsd.org/index.html
9678266Snik
9778266Snikwill download the front page of the FreeBSD web site.
9878266Snik%
9978266SnikIn order to make fetch (the FreeBSD downloading tool) ask for
10078266Snikusername/password when it encounter a password-protected web page, you can set
10178266Snikthe environment variable HTTP_AUTH to 'basic:*'.
10278266Snik%
10378266SnikYou can permanently set environment variables for your shell by putting them
10478266Snikin a startup file for the shell.  The name of the startup file varies
10578772Sbriandepending on the shell - csh and tcsh uses .login, bash, sh, ksh and zsh use
10678772Sbrian.profile.  When using bash, sh, ksh or zsh, don't forget to export the
10778772Sbrianvariable.
10878266Snik%
10978266SnikIf you are running xterm, the default TERM variable will be 'xterm'.  If you
11078266Snikset this environment variable to 'xterm-color' instead, a lot of programs will
11178266Snikuse colors.  You can do this by
11278266Snik
11378266Snik	TERM=xterm-color; export TERM
11478266Snik
11578266Snikin Bourne-derived shells, and
11678266Snik
11778266Snik	setenv TERM xterm-color
11878266Snik
11978266Snikin csh-derived shells.
12078266Snik%
12178266SnikIf you do not want to get beeps in X11 (X Windows), you can turn them off with
12278266Snik
12378266Snik	xset b off
12478266Snik%
12578266SnikYou can look through a file in a nice text-based interface by typing
12678266Snik
12778266Snik	less filename
12878266Snik%
12978266SnikThe default editor in FreeBSD is vi, which is efficient to use when you have
13078266Sniklearned it, but somewhat user-unfriendly.  To use ee (an easier but less
13178266Snikpowerful editor) instead, set the environment variable EDITOR to /usr/bin/ee
13278266Snik%
13378266SnikIf you accidently end up inside vi, you can quit it by pressing Escape, colon
13478266Snik(:), q (q), bang (!) and pressing return.
13578266Snik%
13678266SnikYou can use aliases to decrease the amount of typing you need to do to get
13778266Snikcommands you commonly use.  Examples of fairly popular aliases include (in
13878266Snikbourne shell style, as in /bin/sh, bash, ksh, and zsh):
13978266Snik
14078266Snik	alias lf="ls -FA"
14178266Snik	alias ll="ls -lA"
14278266Snik	alias su="su -m"
14378266Snik
14478266SnikIn csh or tcsh, these would be
14578266Snik
14678266Snik	alias lf ls -FA
14778266Snik	alias ll ls -lA
14878266Snik	alias su su -m
14978266Snik
15078266SnikTo remove an alias, you can usually use 'unalias aliasname'.  To list all
15178266Snikaliases, you can usually type just 'alias'.
15278266Snik%
15378266SnikIn order to support national characters for european languages in tools like
15478266Snikless without creating other nationalisation aspects, set the environment
15578266Snikvariable LC_ALL to 'en_US.ISO8859-1'.
15678266Snik%
15778266SnikYou can search for documentation on a keyword by typing
15878266Snik
15978266Snik	apropos keyword
16078266Snik%
16178266SnikMan pages are divided into section depending on topic.  There are 9 different
16278266Sniksections numbered from 1 (General Commands) to 9 (Kernel Developer's Manual).
16378266SnikYou can get an introduction to each topic by typing
16478266Snik
16578266Snik	man <number> intro
16678266Snik
16778266SnikIn other words, to get the intro to general commands, type
16878266Snik
16978266Snik	man 1 intro
17078266Snik%
17178266SnikFreeBSD is started up by the program 'init'.  The first thing init does when
17278266Snikstarting multiuser mode (ie, starting the computer up for normal use) is to
17378266Snikrun the shell script /etc/rc.  By reading /etc/rc, you can learn a lot about
17478266Snikhow the system is put together, which again will make you more confident about
17578266Snikwhat happens when you do something with it.
17678266Snik%
17778266SnikIf you want to play CDs with FreeBSD, a utility for this is already included.
17878266SnikType 'cdcontrol' then 'help' to learn more.  (You may need to set the CDROM
17978266Snikenvironment variable in order to make cdcontrol want to start.)
18078266Snik%
18178266SnikIf you have a CD-ROM drive in your machine, you can make the CD-ROM that is
18278266Snikpresently inserted available by typing 'mount /cdrom' as root.   The CD-ROM
18378512Smphwill be available under /cdrom/.  Remember to do 'umount /cdrom' before
18478266Snikremoving the CD-ROM (it will usually not be possible to remove the CD-ROM
18578266Snikwithout doing this.)
18678266Snik
18778266SnikNote: This tip may not work in all configurations.
18878266Snik%
18978266SnikYou can install extra packages for FreeBSD by using the ports system.
19078266SnikIf you have installed it, you can download, compile, and install software by
19178266Snikjust typing
19278266Snik
19378266Snik	# cd /usr/ports/<category>/<portname>
19478266Snik	# make install && make clean
19578266Snik
19678266Snikas root.   The ports infrastructure will download the software, change it so
19778266Snikit works on FreeBSD, compile it, install it, register the installation so it
19878266Snikwill be possible to automatically uninstall it, and clean out the temporary
19978266Snikworking space it used.  You can remove an installed port you decide you do not
20078266Snikwant after all by typing
20178266Snik
20278266Snik	# cd /usr/ports/<category>/<portname>
20378266Snik	# make deinstall
20478266Snik
20578266Snikas root.
20678266Snik%
20778266SnikNice bash prompt: PS1='(\[$(tput md)\]\t <\w>\[$(tput me)\]) $(echo $?) \$ '
20878266Snik		-- Mathieu <mathieu@hal.interactionvirtuelle.com>
20978266Snik%
21078266SnikTo see the output from when your computer started, run dmesg(8).  If it has
21178266Snikbeen replaced with other messages, look at /var/run/dmesg.boot.
21278266Snik		-- Francisco Reyes <lists@natserv.com>
21378266Snik%
21478266SnikYou can use "whereis" to locate standard binary, manual page and source
21578266Snikdirectories for the specified programs. This can be particularly handy
21678266Snikwhen you are trying to find where in the ports tree an application is.
21778266Snik
21878266SnikTry "whereis netscape" and "whereis whereis".
21978266Snik		-- Konstantinos Konstantinidis <kkonstan@duth.gr>
22078266Snik%
22178266SnikYou can press Ctrl-D to quickly exit from a shell, or logout from a
22278266Sniklogin shell.
22378266Snik		-- Konstantinos Konstantinidis <kkonstan@duth.gr>
22478266Snik%
22578266SnikYou can use "pkg_info" to see a list of packages you have installed.
22678266Snik		-- Konstantinos Konstantinidis <kkonstan@duth.gr>
22778266Snik%
22878266SnikYou can change the video mode on all consoles by adding something like
22978266Snikthe following to /etc/rc.conf:
23078266Snik
23178266Snik	allscreens="80x30"
23278266Snik
23378266SnikYou can use "vidcontrol -i mode | grep T" for a list of supported text
23478266Snikmodes.
23578266Snik		-- Konstantinos Konstantinidis <kkonstan@duth.gr>
23678266Snik%
23778266SnikAny user that is a member of the wheel group can use "su -" to simulate
23878266Snika root login. You can add a user to the wheel group by editing /etc/group.
23978796Sdd		-- Konstantinos Konstantinidis <kkonstan@duth.gr>
24078271Snik%
24178271SnikOver quota?  "du -s * | sort -n " will give you a sorted list of your
24278271Snikdirectory sizes.
24378271Snik		-- David Scheidt <dscheidt@tumbolia.com>
24478271Snik%
24578271SnikHandy bash(1) prompt:   PS1="\u@\h \w \!$ "
24678271Snik		-- David Scheidt <dscheidt@tumbolia.com>
24778271Snik%
24878271SnikEver wonder what those numbers after command names were, as in cat(1)?  It's
24978271Snikthe section of the manual the man page is in.  "man man" will tell you more.
25078271Snik		-- David Scheidt <dscheidt@tumbolia.com>
25178271Snik%
25278271Snik"man hier" will explain the way FreeBSD filesystems are normally laid out.
25378271Snik		-- David Scheidt <dscheidt@tumbolia.com>
25478271Snik%
25578271Snik"man tuning" gives some tips how to tune performance of your FreeBSD system.
25678271Snik		-- David Scheidt <dscheidt@tumbolia.com>
25778271Snik%
25878271Snik"man firewall" will give advice for building a FreeBSD firewall
25978271Snik		-- David Scheidt <dscheidt@tumbolia.com>
26078283Seivind%
26178283SeivindYou can often get answers to your questions about FreeBSD by searching in the
26278283SeivindFreeBSD mailing list archives at
26378283Seivind
26478283Seivind	http://www.freebsd.org/search.html
26578283Seivind%
26678283SeivindYou can adjust the volume of various parts of the sound system in your
26778283Seivindcomputer by typing 'mixer <type> <volume>'.  To get a list of what you can
26878283Seivindadjust, just type 'mixer'.
26978283Seivind%
27078283SeivindYou can automatically download and install binary packages by doing
27178283Seivind
27278283Seivind	pkg_add -r <URL>
27378283Seivind
27478283Seivindwhere you replace <URL> with the URL to the package.  This will also
27578283Seivindautomatically install the packages the package you download is dependent on
27678283Seivind(ie, the packages it needs in order to work.)
27778283Seivind%
27878283SeivindYou can get a good standard workstation install by using the
27978283Seivindinstant-workstation port/package.  If you have ports installed, you can
28078283Seivindinstall it by doing
28178283Seivind
28278283Seivind	# cd /usr/ports/misc/instant-workstation
28378283Seivind	# make install && make clean
28478283Seivind
28578283Seivindas root.  This will install a collection of packages that is convenient to
28678283Seivindhave on a workstation.
28778283Seivind%
28878283SeivindYou can get a good generic server install by using the
28978283Seivindinstant-server port/package.  If you have ports installed, you can
29078283Seivindinstall it by doing
29178283Seivind
29278283Seivind	# cd /usr/ports/misc/instant-server
29378283Seivind	# make install && make clean
29478283Seivind
29578283Seivindas root.  This will install a collection of packages that is appropriate for
29678283Seivindrunning a "generic" server.
29781558Smharo%
29879027SmppYou can make a log of your terminal session with script(1). 
29981558Smharo%
30078352Snik"man ports" gives many useful hints about installing FreeBSD ports. 
30181558Smharo%
30293518Sjoe"man security" gives very good advice on how to tune the security of your
30393518SjoeFreeBSD system.
30493518Sjoe%
30593518SjoeWant to find a specific port, just type the following under /usr/ports,
30693518Sjoeor one its subdirectories:
30793518Sjoe
30893518Sjoe	"make search port=<port-name>"
30993518Sjoe    or
31093518Sjoe	"make search key="<keyword>"
31193518Sjoe%
31293518SjoeWant to see how much virtual memory you're using? Just type "swapinfo" to
31393518Sjoebe shown information about the usage of your swap partitions.
31493518Sjoe%
31578352Snikports/net/netcat port is useful not only for redirecting input/output 
31678352Snikto TCP or UDP connections, but also for proxying them. See inetd(8) for 
31778352Snikdetails. 
31881558Smharo%
31978352SnikIf other operating systems have damaged your Master Boot Record, you can 
32078352Snikreinstall it either with /stand/sysinstall or with boot0cfg(8). See 
32178352Snik"man boot0cfg" for details.
32281558Smharo%
32378355SnikNeed to see the calendar for this month? Simply type "cal".  To see the 
32493518Sjoewhole year, type "cal 2002". 
32578355Snik		-- Dru <genesis@istar.ca>
32681558Smharo%
32778355SnikNeed to quickly return to your home directory? Type "cd". 
32878355Snik		-- Dru <genesis@istar.ca>
32981558Smharo%
33078355SnikTo see the last time that you logged in, use lastlogin(8). 
33178355Snik		-- Dru <genesis@istar.ca>
33281558Smharo%
33378355SnikTo clear the screen, use "clear". To re-display your screen buffer, press 
33478355Snikthe scroll lock key and use your page up button. When you're finished, 
33578355Snikpress the scroll lock key again to get your prompt back. 
33678355Snik		-- Dru <genesis@istar.ca>
33781558Smharo%
33878355SnikTo save disk space in your home directory, can compress files you 
33978355Snikrarely use with "gzip filename". 
34078355Snik		-- Dru <genesis@istar.ca>
34181558Smharo%
34278355SnikTo read a compressed file without having to first uncompress it, use 
34378355Snik"zcat" or "zmore" to view it. 
34478355Snik		-- Dru <genesis@istar.ca>
34581558Smharo%
34678355SnikTo see how much disk space is left on your partitions, use 
34778355Snik
34878355Snik	df -h
34978355Snik		-- Dru <genesis@istar.ca>
35081558Smharo%
35178355SnikTo see the 10 largest files on a directory or partition, use 
35278355Snik
35378355Snik	du /partition_or_directory_name | sort -rn | head
35478355Snik		-- Dru <genesis@istar.ca>
35581558Smharo%
35678355SnikTo determine whether a file is a text file, executable, or some other type 
35778355Snikof file, use 
35878355Snik
35978355Snik	file filename
36078355Snik		-- Dru <genesis@istar.ca>
36181558Smharo%
36278355SnikTime to change your password? Type "passwd" and follow the prompts. 
36378355Snik		-- Dru <genesis@istar.ca>
36481558Smharo%
36578355SnikWant to know how many words, lines, or bytes are contained in a file? Type 
36678355Snik"wc filename". 
36778355Snik		-- Dru <genesis@istar.ca>
36881558Smharo%
36978355SnikNeed to print a manpage? Use 
37078355Snik
37178458Sdd	man name_of_manpage | col -bx | lpr
37278355Snik		-- Dru <genesis@istar.ca>
37381558Smharo%
37478355SnikNeed to remove all those ^M characters from a DOS file? Try 
37578355Snik
37678355Snik	col -bx < dosfile > newfile
37778355Snik		-- Dru <genesis@istar.ca>
37881558Smharo%
37978355SnikForget what directory you are in? Type "pwd". 
38078355Snik		-- Dru <genesis@istar.ca>
38181558Smharo%
38278355SnikIf you are in the C shell and have just installed a new program, you won't 
38378355Snikbe able to run it unless you first type "rehash". 
38478355Snik		-- Dru <genesis@istar.ca>
38581558Smharo%
38678355SnikNeed to leave your terminal for a few minutes and don't want to logout? 
38778355SnikUse "lock -p". When you return, use your password as the key to unlock the 
38878355Snikterminal. 
38978355Snik		-- Dru <genesis@istar.ca>
39081558Smharo%
39178471SnikNeed to find the location of a program? Use "locate program_name". 
39278355Snik		-- Dru <genesis@istar.ca>
39381558Smharo%
39478355SnikForget how to spell a word or a variation of a word? Use 
39578355Snik
39678355Snik	look portion_of_word_you_know
39778355Snik		-- Dru <genesis@istar.ca>
39881558Smharo%
39978355SnikTo see the last 10 lines of a long file, use "tail filename". To see the 
40078355Snikfirst 10 lines, use "head filename". 
40178355Snik		-- Dru <genesis@istar.ca>
40281558Smharo%
40378355SnikTo see how long it takes a command to run, type the word "time" before the 
40478355Snikcommand name. 
40578355Snik		-- Dru <genesis@istar.ca>
40681558Smharo%
40778355SnikTo quickly create an empty file, use "touch filename". 
40878355Snik		-- Dru <genesis@istar.ca>
40981558Smharo%
41078355SnikTo find out the hostname associated with an IP address, use 
41178355Snik
41278355Snik	dig -x IP_address
41378355Snik		-- Dru <genesis@istar.ca>
41481558Smharo%
41578355SnikIf you use the C shell, add the following line to the .cshrc file in your 
41678355Snikhome directory to prevent core files from being written to disk: 
41778355Snik
41878355Snik	limit coredumpsize 0
41978355Snik		-- Dru <genesis@istar.ca>
42081558Smharo%
42178355SnikIf you need a reminder to leave your terminal, type "leave hhmm" where 
42278355Snik"hhmm" represents in how many hours and minutes you need to leave. 
42378355Snik		-- Dru <genesis@istar.ca>
42481558Smharo%
42578355SnikNeed to do a search in a manpage or in a file you've sent to a pager? Use 
42678355Snik"/search_word". To repeat the same search, type "n" for next. 
42778355Snik		-- Dru <genesis@istar.ca>
42881558Smharo%
42978355SnikForget when Easter is? Try "ncal -e". If you need the date for Orthodox 
43078355SnikEaster, use "ncal -o" instead. 
43178355Snik		-- Dru <genesis@istar.ca>
43281558Smharo%
43378355SnikNeed to see your routing table? Type "netstat -rn". The entry with the G 
43478355Snikflag is your gateway. 
43578355Snik		-- Dru <genesis@istar.ca>
43681558Smharo%
43778355SnikNeed to see which daemons are listening for connection requests? Use 
43878471Snik"sockstat -4l" for IPv4, and "sockstat -l" for IPv4 and IPv6. 
43978355Snik		-- Dru <genesis@istar.ca>
44081558Smharo%
44178355SnikCan't remember is you've installed a certain port or not? Try "pkg_info | 
44278355Snikgrep port_name". 
44378355Snik		-- Dru <genesis@istar.ca>
44481558Smharo%
44578355SnikGot some time to kill? Try typing "hangman". 
44678355Snik		-- Dru <genesis@istar.ca>
44781558Smharo%
44893518SjoeTo erase a line you've written at the command prompt, use "Ctrl-U". 
44978355Snik		-- Dru <genesis@istar.ca>
45081558Smharo%
45178355SnikTo repeat the last command in the C shell, type "!!". 
45278355Snik		-- Dru <genesis@istar.ca>
45381558Smharo%
45478355SnikNeed to quickly empty a file? Use "echo > filename". 
45578355Snik		-- Dru <genesis@istar.ca>
45681558Smharo%
45778355SnikTo see all of the directories on your FreeBSD system, type 
45878355Snik
45978471Snik	ls -R / | more
46078355Snik		-- Dru <genesis@istar.ca>
46181558Smharo%
46278355SnikTo see the IP addresses currently set on your active interfaces, type 
46378355Snik"ifconfig -u". 
46478355Snik		-- Dru <genesis@istar.ca>
46581558Smharo%
46678355SnikTo see the MAC addresses of the NICs on your system, type 
46778355Snik
46878471Snik	ifconfig -a
46978355Snik		-- Dru <genesis@istar.ca>
47078471Snik%
47178471SnikYou can save your kernel startup configuration with kget(8).  The
47278471SnikConfiguration can be edited at boot time with 'boot -c' command in loader.
47378471SnikSee boot(8), loader(8) for details.
47478773Sbrian%
47578773SbrianYou can open up a new split-screen window in (n)vi with :N or :E and then
47678773Sbrianuse ^w to switch between the two.
47778774Sbrian%
47878774Sbriansh (the default bourne shell in FreeBSD) supports command-line editing.  Just
47978774Sbrian``set -o emacs'' or ``set -o vi'' to enable it.
48078777Sbrian%
48178777SbrianWhen you've made modifications to a file in vi(1) and then find that
48278777Sbrianyou can't write it, type ``<ESC>!rm -f %'' then ``:w!'' to force the
48378777Sbrianwrite
48478777Sbrian
48578777SbrianThis won't work if you don't have write permissions to the directory
48678777Sbrianand probably won't be suitable if you're editing through a symbolic link.
48790516Skeramida%
48890516SkeramidaIf you want to quickly check for duplicate package/port installations,
48990516Skeramidatry the following pkg_info command.
49090516Skeramida
49190516Skeramida	pkg_info | sort | sed -e 's/-[0-9].*$//' | \
49290516Skeramida	uniq -c | grep -v '^[[:space:]]*1'
493