freebsd-tips revision 78355
178266SnikThis fortune brought to you by: 278266Snik$FreeBSD: head/games/fortune/datfiles/freebsd-tips 78355 2001-06-16 16:45:52Z nik $ 378266Snik% 478266SnikHaving trouble using FTP through a firewall? Try setting the environment 578266Snikvariable FTP_PASSIVE_MODE to yes, and see ftp(1) 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 -- Giorgos Keramidas <keramida@ceid.upatras.gr> 3578266Snik% 3678266SnikYou can `set autologout = 30' to have tcsh log you off automatically 3778266Snikif you leave the shell idle for more than 30 seconds. 3878266Snik -- Giorgos Keramidas <keramida@ceid.upatras.gr> 3978266Snik% 4078266SnikIf you `set filec' (file completion) in tcsh and write a part of the 4178266Snikfilename, pressing TAB will show you the available choices when there 4278266Snikis more than one, or complete the filename if there's only one match. 4378266Snik -- Giorgos Keramidas <keramida@ceid.upatras.gr> 4478266Snik% 4578266SnikYou can press up-arrow or down-arrow to walk through a list of 4678266Snikprevious commands in tcsh. 4778266Snik -- Giorgos Keramidas <keramida@ceid.upatras.gr> 4878266Snik% 4978266SnikYou can disable tcsh's terminal beep if you `set nobeep'. 5078266Snik -- Giorgos Keramidas <keramida@ceid.upatras.gr> 5178266Snik% 5278266SnikIf you `set watch (0 any any)' in tcsh, you will be notified when 5378266Sniksomeone logs in or out of your system. 5478266Snik -- Giorgos Keramidas <keramida@ceid.upatras.gr> 5578266Snik% 5678266SnikNice tcsh prompt: set prompt = '%m %# ' 5778266Snik -- Giorgos Keramidas <keramida@ceid.upatras.gr> 5878266Snik% 5978266SnikNice tcsh prompt: set prompt = '%n@%m%# ' 6078266Snik -- Giorgos Keramidas <keramida@ceid.upatras.gr> 6178266Snik% 6278266SnikNice tcsh prompt: set prompt = '%n@%m:%~%# ' 6378266Snik -- Giorgos Keramidas <keramida@ceid.upatras.gr> 6478266Snik% 6578266SnikNice tcsh prompt: set prompt = '%n@%m:%/%# ' 6678266Snik -- Giorgos Keramidas <keramida@ceid.upatras.gr> 6778266Snik% 6878266SnikNice tcsh prompt: set prompt = '[%B%m%b] %B%~%b%# ' 6978266Snik% 7078266SnikSimple tcsh prompt: set prompt = '%# ' 7178266Snik -- Giorgos Keramidas <keramida@ceid.upatras.gr> 7278266Snik% 7378266SnikIf you want df(1) and other commands to display disk sizes in 7478266Snikkilobytes instead of 512-byte blocks, set BLOCKSIZE in your 7578266Snikenvironment to 'K'. 7678266Snik -- Giorgos Keramidas <keramida@ceid.upatras.gr> 7778266Snik% 7878266SnikTo change an environment variable in tcsh you use: setenv NAME "value" 7978266Snikwhere NAME is the name of the variable and "value" its new value. 8078266Snik -- Giorgos Keramidas <keramida@ceid.upatras.gr> 8178266Snik% 8278266SnikTo change an environment variable in /bin/sh use: 8378266Snik 8478266Snik $ VARIABLE="value" 8578266Snik $ export VARIABLE 8678266Snik -- Giorgos Keramidas <keramida@ceid.upatras.gr> 8778266Snik% 8878266Snik/etc/make.conf contains overrides to /etc/defaults/make.conf, which 8978266Snikcontrols the options used to compile software on this system. 9078266Snik% 9178266SnikTo do a fast search for a file, try 9278266Snik 9378266Snik locate filename 9478266Snik 9578266Sniklocate uses a database that is updated every saturday (assuming your computer 9678266Snikis running FreeBSD at the time) to quickly find files based on name only. 9778266Snik% 9878266SnikIn order to search for a string in some files, use 'grep' like this: 9978266Snik 10078266Snik grep "string" filename1 [filename2 filename3 ...] 10178266Snik 10278266SnikThis will print out the lines in the files that contain the string. grep can 10378266Snikalso do a lot more advanced searches - type 'man grep' for details. 10478266Snik% 10578266SnikYou can use the 'fetch' command to retrieve files over ftp or http. 10678266Snik 10778266Snik fetch http://www.freebsd.org/index.html 10878266Snik 10978266Snikwill download the front page of the FreeBSD web site. 11078266Snik% 11178266SnikIn order to make fetch (the FreeBSD downloading tool) ask for 11278266Snikusername/password when it encounter a password-protected web page, you can set 11378266Snikthe environment variable HTTP_AUTH to 'basic:*'. 11478266Snik% 11578266SnikYou can permanently set environment variables for your shell by putting them 11678266Snikin a startup file for the shell. The name of the startup file varies 11778266Snikdepending on the shell - csh and tcsh uses .cshrc, bash uses .bashrc, zsh uses 11878266Snik.zshrc, ksh uses .kshrc, and the Bourne shell (/bin/sh) uses .profile (and 11978266Snikthrough a little bit of trickery in .profile also .shrc) 12078266SnikOther shells will often also read .profile 12178266Snik% 12278266SnikIf you are running xterm, the default TERM variable will be 'xterm'. If you 12378266Snikset this environment variable to 'xterm-color' instead, a lot of programs will 12478266Snikuse colors. You can do this by 12578266Snik 12678266Snik TERM=xterm-color; export TERM 12778266Snik 12878266Snikin Bourne-derived shells, and 12978266Snik 13078266Snik setenv TERM xterm-color 13178266Snik 13278266Snikin csh-derived shells. 13378266Snik% 13478266SnikIf you accidently drop into /bin/sh (e.g, due to a computer failure where you 13578266Snikend up in single user mode), you can make the cursor keys work by typing 13678266Snik 13778266Snik set -E 13878266Snik 13978266SnikThe E represents the initial E in Emacs (for emacs keys). 14078266Snik% 14178266SnikIf you do not want to get beeps in X11 (X Windows), you can turn them off with 14278266Snik 14378266Snik xset b off 14478266Snik% 14578266SnikYou can look through a file in a nice text-based interface by typing 14678266Snik 14778266Snik less filename 14878266Snik% 14978266SnikThe default editor in FreeBSD is vi, which is efficient to use when you have 15078266Sniklearned it, but somewhat user-unfriendly. To use ee (an easier but less 15178266Snikpowerful editor) instead, set the environment variable EDITOR to /usr/bin/ee 15278266Snik% 15378266SnikIf you accidently end up inside vi, you can quit it by pressing Escape, colon 15478266Snik(:), q (q), bang (!) and pressing return. 15578266Snik% 15678266SnikYou can use aliases to decrease the amount of typing you need to do to get 15778266Snikcommands you commonly use. Examples of fairly popular aliases include (in 15878266Snikbourne shell style, as in /bin/sh, bash, ksh, and zsh): 15978266Snik 16078266Snik alias lf="ls -FA" 16178266Snik alias ll="ls -lA" 16278266Snik alias su="su -m" 16378266Snik 16478266SnikIn csh or tcsh, these would be 16578266Snik 16678266Snik alias lf ls -FA 16778266Snik alias ll ls -lA 16878266Snik alias su su -m 16978266Snik 17078266SnikTo remove an alias, you can usually use 'unalias aliasname'. To list all 17178266Snikaliases, you can usually type just 'alias'. 17278266Snik% 17378266SnikIn order to support national characters for european languages in tools like 17478266Snikless without creating other nationalisation aspects, set the environment 17578266Snikvariable LC_ALL to 'en_US.ISO8859-1'. 17678266Snik% 17778266SnikYou can search for documentation on a keyword by typing 17878266Snik 17978266Snik apropos keyword 18078266Snik% 18178266SnikMan pages are divided into section depending on topic. There are 9 different 18278266Sniksections numbered from 1 (General Commands) to 9 (Kernel Developer's Manual). 18378266SnikYou can get an introduction to each topic by typing 18478266Snik 18578266Snik man <number> intro 18678266Snik 18778266SnikIn other words, to get the intro to general commands, type 18878266Snik 18978266Snik man 1 intro 19078266Snik% 19178266SnikFreeBSD is started up by the program 'init'. The first thing init does when 19278266Snikstarting multiuser mode (ie, starting the computer up for normal use) is to 19378266Snikrun the shell script /etc/rc. By reading /etc/rc, you can learn a lot about 19478266Snikhow the system is put together, which again will make you more confident about 19578266Snikwhat happens when you do something with it. 19678266Snik% 19778266SnikIf you want to play CDs with FreeBSD, a utility for this is already included. 19878266SnikType 'cdcontrol' then 'help' to learn more. (You may need to set the CDROM 19978266Snikenvironment variable in order to make cdcontrol want to start.) 20078266Snik% 20178266SnikIf you have a CD-ROM drive in your machine, you can make the CD-ROM that is 20278266Snikpresently inserted available by typing 'mount /cdrom' as root. The CD-ROM 20378266Snikwill be available under /cdrom/. Remember to do 'unmount /cdrom' before 20478266Snikremoving the CD-ROM (it will usually not be possible to remove the CD-ROM 20578266Snikwithout doing this.) 20678266Snik 20778266SnikNote: This tip may not work in all configurations. 20878266Snik% 20978266SnikYou can install extra packages for FreeBSD by using the ports system. 21078266SnikIf you have installed it, you can download, compile, and install software by 21178266Snikjust typing 21278266Snik 21378266Snik # cd /usr/ports/<category>/<portname> 21478266Snik # make install && make clean 21578266Snik 21678266Snikas root. The ports infrastructure will download the software, change it so 21778266Snikit works on FreeBSD, compile it, install it, register the installation so it 21878266Snikwill be possible to automatically uninstall it, and clean out the temporary 21978266Snikworking space it used. You can remove an installed port you decide you do not 22078266Snikwant after all by typing 22178266Snik 22278266Snik # cd /usr/ports/<category>/<portname> 22378266Snik # make deinstall 22478266Snik 22578266Snikas root. 22678266Snik% 22778266SnikNice bash prompt: PS1='(\[$(tput md)\]\t <\w>\[$(tput me)\]) $(echo $?) \$ ' 22878266Snik -- Mathieu <mathieu@hal.interactionvirtuelle.com> 22978266Snik% 23078266SnikTo see the output from when your computer started, run dmesg(8). If it has 23178266Snikbeen replaced with other messages, look at /var/run/dmesg.boot. 23278266Snik -- Francisco Reyes <lists@natserv.com> 23378266Snik% 23478266SnikYou can use "whereis" to locate standard binary, manual page and source 23578266Snikdirectories for the specified programs. This can be particularly handy 23678266Snikwhen you are trying to find where in the ports tree an application is. 23778266Snik 23878266SnikTry "whereis netscape" and "whereis whereis". 23978266Snik -- Konstantinos Konstantinidis <kkonstan@duth.gr> 24078266Snik% 24178266SnikYou can press Ctrl-D to quickly exit from a shell, or logout from a 24278266Sniklogin shell. 24378266Snik -- Konstantinos Konstantinidis <kkonstan@duth.gr> 24478266Snik% 24578266SnikYou can use "pkg_info" to see a list of packages you have installed. 24678266Snik -- Konstantinos Konstantinidis <kkonstan@duth.gr> 24778266Snik% 24878266SnikYou can change the video mode on all consoles by adding something like 24978266Snikthe following to /etc/rc.conf: 25078266Snik 25178266Snik allscreens="80x30" 25278266Snik 25378266SnikYou can use "vidcontrol -i mode | grep T" for a list of supported text 25478266Snikmodes. 25578266Snik -- Konstantinos Konstantinidis <kkonstan@duth.gr> 25678266Snik% 25778266SnikAny user that is a member of the wheel group can use "su -" to simulate 25878266Snika root login. You can add a user to the wheel group by editing /etc/group. 25978266Snik -- -- Konstantinos Konstantinidis <kkonstan@duth.gr> 26078271Snik% 26178271SnikOver quota? "du -s * | sort -n " will give you a sorted list of your 26278271Snikdirectory sizes. 26378271Snik -- David Scheidt <dscheidt@tumbolia.com> 26478271Snik% 26578271SnikHandy bash(1) prompt: PS1="\u@\h \w \!$ " 26678271Snik -- David Scheidt <dscheidt@tumbolia.com> 26778271Snik% 26878271Snikman -k "something" will give you a list of manpages that have "something" 26978271Snikin their description. 27078271Snik -- David Scheidt <dscheidt@tumbolia.com> 27178271Snik% 27278271SnikEver wonder what those numbers after command names were, as in cat(1)? It's 27378271Snikthe section of the manual the man page is in. "man man" will tell you more. 27478271Snik -- David Scheidt <dscheidt@tumbolia.com> 27578271Snik% 27678271Snik"man hier" will explain the way FreeBSD filesystems are normally laid out. 27778271Snik -- David Scheidt <dscheidt@tumbolia.com> 27878271Snik% 27978271Snik"man tuning" gives some tips how to tune performance of your FreeBSD system. 28078271Snik -- David Scheidt <dscheidt@tumbolia.com> 28178271Snik% 28278271Snik"man firewall" will give advice for building a FreeBSD firewall 28378271Snik -- David Scheidt <dscheidt@tumbolia.com> 28478283Seivind% 28578283SeivindYou can often get answers to your questions about FreeBSD by searching in the 28678283SeivindFreeBSD mailing list archives at 28778283Seivind 28878283Seivind http://www.freebsd.org/search.html 28978283Seivind% 29078283SeivindYou can adjust the volume of various parts of the sound system in your 29178283Seivindcomputer by typing 'mixer <type> <volume>'. To get a list of what you can 29278283Seivindadjust, just type 'mixer'. 29378283Seivind% 29478283SeivindYou can automatically download and install binary packages by doing 29578283Seivind 29678283Seivind pkg_add -r <URL> 29778283Seivind 29878283Seivindwhere you replace <URL> with the URL to the package. This will also 29978283Seivindautomatically install the packages the package you download is dependent on 30078283Seivind(ie, the packages it needs in order to work.) 30178283Seivind% 30278283SeivindYou can get a good standard workstation install by using the 30378283Seivindinstant-workstation port/package. If you have ports installed, you can 30478283Seivindinstall it by doing 30578283Seivind 30678283Seivind # cd /usr/ports/misc/instant-workstation 30778283Seivind # make install && make clean 30878283Seivind 30978283Seivindas root. This will install a collection of packages that is convenient to 31078283Seivindhave on a workstation. 31178283Seivind% 31278283SeivindYou can get a good generic server install by using the 31378283Seivindinstant-server port/package. If you have ports installed, you can 31478283Seivindinstall it by doing 31578283Seivind 31678283Seivind # cd /usr/ports/misc/instant-server 31778283Seivind # make install && make clean 31878283Seivind 31978283Seivindas root. This will install a collection of packages that is appropriate for 32078283Seivindrunning a "generic" server. 32178352Snik% 32278352SnikYou can make a log of you terminal session with script(1). 32378352Snik% 32478352Snik"man ports" gives many useful hints about installing FreeBSD ports. 32578352Snik% 32678352Snikports/net/netcat port is useful not only for redirecting input/output 32778352Snikto TCP or UDP connections, but also for proxying them. See inetd(8) for 32878352Snikdetails. 32978352Snik% 33078352SnikIf other operating systems have damaged your Master Boot Record, you can 33178352Snikreinstall it either with /stand/sysinstall or with boot0cfg(8). See 33278352Snik"man boot0cfg" for details. 33378355Snik% 33478355SnikNeed to see the calendar for this month? Simply type "cal". To see the 33578355Snikwhole year, type "cal 2001". 33678355Snik -- Dru <genesis@istar.ca> 33778355Snik% 33878355SnikNeed to quickly return to your home directory? Type "cd". 33978355Snik -- Dru <genesis@istar.ca> 34078355Snik% 34178355SnikTo see the last time that you logged in, use lastlogin(8). 34278355Snik -- Dru <genesis@istar.ca> 34378355Snik% 34478355SnikTo clear the screen, use "clear". To re-display your screen buffer, press 34578355Snikthe scroll lock key and use your page up button. When you're finished, 34678355Snikpress the scroll lock key again to get your prompt back. 34778355Snik -- Dru <genesis@istar.ca> 34878355Snik% 34978355SnikTo save disk space in your home directory, can compress files you 35078355Snikrarely use with "gzip filename". 35178355Snik -- Dru <genesis@istar.ca> 35278355Snik% 35378355SnikTo read a compressed file without having to first uncompress it, use 35478355Snik"zcat" or "zmore" to view it. 35578355Snik -- Dru <genesis@istar.ca> 35678355Snik% 35778355SnikTo see how much disk space is left on your partitions, use 35878355Snik 35978355Snik df -h 36078355Snik -- Dru <genesis@istar.ca> 36178355Snik% 36278355SnikTo see the 10 largest files on a directory or partition, use 36378355Snik 36478355Snik du /partition_or_directory_name | sort -rn | head 36578355Snik -- Dru <genesis@istar.ca> 36678355Snik% 36778355SnikTo determine whether a file is a text file, executable, or some other type 36878355Snikof file, use 36978355Snik 37078355Snik file filename 37178355Snik -- Dru <genesis@istar.ca> 37278355Snik% 37378355SnikNeed to find the information that was displayed on your screen at boot 37478355Sniktime? Try 37578355Snik 37678355Snik more /var/run/dmesg.boot 37778355Snik -- Dru <genesis@istar.ca> 37878355Snik% 37978355SnikTime to change your password? Type "passwd" and follow the prompts. 38078355Snik -- Dru <genesis@istar.ca> 38178355Snik% 38278355SnikWant to know how many words, lines, or bytes are contained in a file? Type 38378355Snik"wc filename". 38478355Snik -- Dru <genesis@istar.ca> 38578355Snik% 38678355SnikNeed to print a manpage? Use 38778355Snik 38878355Snik man name_of_manpage | col -bx > lpr 38978355Snik -- Dru <genesis@istar.ca> 39078355Snik% 39178355SnikNeed to remove all those ^M characters from a DOS file? Try 39278355Snik 39378355Snik col -bx < dosfile > newfile 39478355Snik -- Dru <genesis@istar.ca> 39578355Snik% 39678355SnikForget what directory you are in? Type "pwd". 39778355Snik -- Dru <genesis@istar.ca> 39878355Snik% 39978355SnikIf you are in the C shell and have just installed a new program, you won't 40078355Snikbe able to run it unless you first type "rehash". 40178355Snik -- Dru <genesis@istar.ca> 40278355Snik% 40378355SnikNeed to leave your terminal for a few minutes and don't want to logout? 40478355SnikUse "lock -p". When you return, use your password as the key to unlock the 40578355Snikterminal. 40678355Snik -- Dru <genesis@istar.ca> 40778355Snik% 40878355SnikWant to save your login session to a file? Type "script filename" to 40978355Snikrecord your session. When you are finished, hold down the control key and 41078355Snikpress d. 41178355Snik -- Dru <genesis@istar.ca> 41278355Snik% 41378355SnikNeed to find the location of a program? Use "locate -b program_name". 41478355Snik -- Dru <genesis@istar.ca> 41578355Snik% 41678355SnikForget how to spell a word or a variation of a word? Use 41778355Snik 41878355Snik look portion_of_word_you_know 41978355Snik -- Dru <genesis@istar.ca> 42078355Snik% 42178355SnikTo see the last 10 lines of a long file, use "tail filename". To see the 42278355Snikfirst 10 lines, use "head filename". 42378355Snik -- Dru <genesis@istar.ca> 42478355Snik% 42578355SnikTo see how long it takes a command to run, type the word "time" before the 42678355Snikcommand name. 42778355Snik -- Dru <genesis@istar.ca> 42878355Snik% 42978355SnikTo quickly create an empty file, use "touch filename". 43078355Snik -- Dru <genesis@istar.ca> 43178355Snik% 43278355SnikTo find out the hostname associated with an IP address, use 43378355Snik 43478355Snik dig -x IP_address 43578355Snik -- Dru <genesis@istar.ca> 43678355Snik% 43778355SnikIf you use the C shell, add the following line to the .cshrc file in your 43878355Snikhome directory to prevent core files from being written to disk: 43978355Snik 44078355Snik limit coredumpsize 0 44178355Snik -- Dru <genesis@istar.ca> 44278355Snik% 44378355SnikIf you need a reminder to leave your terminal, type "leave hhmm" where 44478355Snik"hhmm" represents in how many hours and minutes you need to leave. 44578355Snik -- Dru <genesis@istar.ca> 44678355Snik% 44778355SnikNeed to do a search in a manpage or in a file you've sent to a pager? Use 44878355Snik"/search_word". To repeat the same search, type "n" for next. 44978355Snik -- Dru <genesis@istar.ca> 45078355Snik% 45178355SnikForget when Easter is? Try "ncal -e". If you need the date for Orthodox 45278355SnikEaster, use "ncal -o" instead. 45378355Snik -- Dru <genesis@istar.ca> 45478355Snik% 45578355SnikNeed to see your routing table? Type "netstat -rn". The entry with the G 45678355Snikflag is your gateway. 45778355Snik -- Dru <genesis@istar.ca> 45878355Snik% 45978355SnikNeed to see which daemons are listening for connection requests? Use 46078355Snik"sockstat -4". 46178355Snik -- Dru <genesis@istar.ca> 46278355Snik% 46378355SnikCan't remember is you've installed a certain port or not? Try "pkg_info | 46478355Snikgrep port_name". 46578355Snik -- Dru <genesis@istar.ca> 46678355Snik% 46778355SnikGot some time to kill? Try typing "hangman". 46878355Snik -- Dru <genesis@istar.ca> 46978355Snik% 47078355SnikTo erase a line you've written at the command prompt, use "Ctrl u". 47178355Snik -- Dru <genesis@istar.ca> 47278355Snik% 47378355SnikTo repeat the last command in the C shell, type "!!". 47478355Snik -- Dru <genesis@istar.ca> 47578355Snik% 47678355SnikNeed to quickly empty a file? Use "echo > filename". 47778355Snik -- Dru <genesis@istar.ca> 47878355Snik% 47978355SnikTo see all of the directories on your FreeBSD system, type 48078355Snik 48178355Snik ls -RC / |more 48278355Snik -- Dru <genesis@istar.ca> 48378355Snik% 48478355SnikTo see the IP addresses currently set on your active interfaces, type 48578355Snik"ifconfig -u". 48678355Snik -- Dru <genesis@istar.ca> 48778355Snik% 48878355SnikTo see the MAC addresses of the NICs on your system, type 48978355Snik 49078355Snik grep address /var/run/dmesg.boot 49178355Snik -- Dru <genesis@istar.ca> 492