freebsd-tips revision 78777
178266SnikThis fortune brought to you by: 278266Snik$FreeBSD: head/games/fortune/datfiles/freebsd-tips 78777 2001-06-25 21:05:55Z brian $ 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 11778772Sbriandepending on the shell - csh and tcsh uses .login, bash, sh, ksh and zsh use 11878772Sbrian.profile. When using bash, sh, ksh or zsh, don't forget to export the 11978772Sbrianvariable. 12078266Snik% 12178266SnikIf you are running xterm, the default TERM variable will be 'xterm'. If you 12278266Snikset this environment variable to 'xterm-color' instead, a lot of programs will 12378266Snikuse colors. You can do this by 12478266Snik 12578266Snik TERM=xterm-color; export TERM 12678266Snik 12778266Snikin Bourne-derived shells, and 12878266Snik 12978266Snik setenv TERM xterm-color 13078266Snik 13178266Snikin csh-derived shells. 13278266Snik% 13378266SnikIf you accidently drop into /bin/sh (e.g, due to a computer failure where you 13478266Snikend up in single user mode), you can make the cursor keys work by typing 13578266Snik 13678266Snik set -E 13778266Snik 13878266SnikThe E represents the initial E in Emacs (for emacs keys). 13978266Snik% 14078266SnikIf you do not want to get beeps in X11 (X Windows), you can turn them off with 14178266Snik 14278266Snik xset b off 14378266Snik% 14478266SnikYou can look through a file in a nice text-based interface by typing 14578266Snik 14678266Snik less filename 14778266Snik% 14878266SnikThe default editor in FreeBSD is vi, which is efficient to use when you have 14978266Sniklearned it, but somewhat user-unfriendly. To use ee (an easier but less 15078266Snikpowerful editor) instead, set the environment variable EDITOR to /usr/bin/ee 15178266Snik% 15278266SnikIf you accidently end up inside vi, you can quit it by pressing Escape, colon 15378266Snik(:), q (q), bang (!) and pressing return. 15478266Snik% 15578266SnikYou can use aliases to decrease the amount of typing you need to do to get 15678266Snikcommands you commonly use. Examples of fairly popular aliases include (in 15778266Snikbourne shell style, as in /bin/sh, bash, ksh, and zsh): 15878266Snik 15978266Snik alias lf="ls -FA" 16078266Snik alias ll="ls -lA" 16178266Snik alias su="su -m" 16278266Snik 16378266SnikIn csh or tcsh, these would be 16478266Snik 16578266Snik alias lf ls -FA 16678266Snik alias ll ls -lA 16778266Snik alias su su -m 16878266Snik 16978266SnikTo remove an alias, you can usually use 'unalias aliasname'. To list all 17078266Snikaliases, you can usually type just 'alias'. 17178266Snik% 17278266SnikIn order to support national characters for european languages in tools like 17378266Snikless without creating other nationalisation aspects, set the environment 17478266Snikvariable LC_ALL to 'en_US.ISO8859-1'. 17578266Snik% 17678266SnikYou can search for documentation on a keyword by typing 17778266Snik 17878266Snik apropos keyword 17978266Snik% 18078266SnikMan pages are divided into section depending on topic. There are 9 different 18178266Sniksections numbered from 1 (General Commands) to 9 (Kernel Developer's Manual). 18278266SnikYou can get an introduction to each topic by typing 18378266Snik 18478266Snik man <number> intro 18578266Snik 18678266SnikIn other words, to get the intro to general commands, type 18778266Snik 18878266Snik man 1 intro 18978266Snik% 19078266SnikFreeBSD is started up by the program 'init'. The first thing init does when 19178266Snikstarting multiuser mode (ie, starting the computer up for normal use) is to 19278266Snikrun the shell script /etc/rc. By reading /etc/rc, you can learn a lot about 19378266Snikhow the system is put together, which again will make you more confident about 19478266Snikwhat happens when you do something with it. 19578266Snik% 19678266SnikIf you want to play CDs with FreeBSD, a utility for this is already included. 19778266SnikType 'cdcontrol' then 'help' to learn more. (You may need to set the CDROM 19878266Snikenvironment variable in order to make cdcontrol want to start.) 19978266Snik% 20078266SnikIf you have a CD-ROM drive in your machine, you can make the CD-ROM that is 20178266Snikpresently inserted available by typing 'mount /cdrom' as root. The CD-ROM 20278512Smphwill be available under /cdrom/. Remember to do 'umount /cdrom' before 20378266Snikremoving the CD-ROM (it will usually not be possible to remove the CD-ROM 20478266Snikwithout doing this.) 20578266Snik 20678266SnikNote: This tip may not work in all configurations. 20778266Snik% 20878266SnikYou can install extra packages for FreeBSD by using the ports system. 20978266SnikIf you have installed it, you can download, compile, and install software by 21078266Snikjust typing 21178266Snik 21278266Snik # cd /usr/ports/<category>/<portname> 21378266Snik # make install && make clean 21478266Snik 21578266Snikas root. The ports infrastructure will download the software, change it so 21678266Snikit works on FreeBSD, compile it, install it, register the installation so it 21778266Snikwill be possible to automatically uninstall it, and clean out the temporary 21878266Snikworking space it used. You can remove an installed port you decide you do not 21978266Snikwant after all by typing 22078266Snik 22178266Snik # cd /usr/ports/<category>/<portname> 22278266Snik # make deinstall 22378266Snik 22478266Snikas root. 22578266Snik% 22678266SnikNice bash prompt: PS1='(\[$(tput md)\]\t <\w>\[$(tput me)\]) $(echo $?) \$ ' 22778266Snik -- Mathieu <mathieu@hal.interactionvirtuelle.com> 22878266Snik% 22978266SnikTo see the output from when your computer started, run dmesg(8). If it has 23078266Snikbeen replaced with other messages, look at /var/run/dmesg.boot. 23178266Snik -- Francisco Reyes <lists@natserv.com> 23278266Snik% 23378266SnikYou can use "whereis" to locate standard binary, manual page and source 23478266Snikdirectories for the specified programs. This can be particularly handy 23578266Snikwhen you are trying to find where in the ports tree an application is. 23678266Snik 23778266SnikTry "whereis netscape" and "whereis whereis". 23878266Snik -- Konstantinos Konstantinidis <kkonstan@duth.gr> 23978266Snik% 24078266SnikYou can press Ctrl-D to quickly exit from a shell, or logout from a 24178266Sniklogin shell. 24278266Snik -- Konstantinos Konstantinidis <kkonstan@duth.gr> 24378266Snik% 24478266SnikYou can use "pkg_info" to see a list of packages you have installed. 24578266Snik -- Konstantinos Konstantinidis <kkonstan@duth.gr> 24678266Snik% 24778266SnikYou can change the video mode on all consoles by adding something like 24878266Snikthe following to /etc/rc.conf: 24978266Snik 25078266Snik allscreens="80x30" 25178266Snik 25278266SnikYou can use "vidcontrol -i mode | grep T" for a list of supported text 25378266Snikmodes. 25478266Snik -- Konstantinos Konstantinidis <kkonstan@duth.gr> 25578266Snik% 25678266SnikAny user that is a member of the wheel group can use "su -" to simulate 25778266Snika root login. You can add a user to the wheel group by editing /etc/group. 25878266Snik -- -- Konstantinos Konstantinidis <kkonstan@duth.gr> 25978271Snik% 26078271SnikOver quota? "du -s * | sort -n " will give you a sorted list of your 26178271Snikdirectory sizes. 26278271Snik -- David Scheidt <dscheidt@tumbolia.com> 26378271Snik% 26478271SnikHandy bash(1) prompt: PS1="\u@\h \w \!$ " 26578271Snik -- David Scheidt <dscheidt@tumbolia.com> 26678271Snik% 26778271Snikman -k "something" will give you a list of manpages that have "something" 26878271Snikin their description. 26978271Snik -- David Scheidt <dscheidt@tumbolia.com> 27078271Snik% 27178271SnikEver wonder what those numbers after command names were, as in cat(1)? It's 27278271Snikthe section of the manual the man page is in. "man man" will tell you more. 27378271Snik -- David Scheidt <dscheidt@tumbolia.com> 27478271Snik% 27578271Snik"man hier" will explain the way FreeBSD filesystems are normally laid out. 27678271Snik -- David Scheidt <dscheidt@tumbolia.com> 27778271Snik% 27878271Snik"man tuning" gives some tips how to tune performance of your FreeBSD system. 27978271Snik -- David Scheidt <dscheidt@tumbolia.com> 28078271Snik% 28178271Snik"man firewall" will give advice for building a FreeBSD firewall 28278271Snik -- David Scheidt <dscheidt@tumbolia.com> 28378283Seivind% 28478283SeivindYou can often get answers to your questions about FreeBSD by searching in the 28578283SeivindFreeBSD mailing list archives at 28678283Seivind 28778283Seivind http://www.freebsd.org/search.html 28878283Seivind% 28978283SeivindYou can adjust the volume of various parts of the sound system in your 29078283Seivindcomputer by typing 'mixer <type> <volume>'. To get a list of what you can 29178283Seivindadjust, just type 'mixer'. 29278283Seivind% 29378283SeivindYou can automatically download and install binary packages by doing 29478283Seivind 29578283Seivind pkg_add -r <URL> 29678283Seivind 29778283Seivindwhere you replace <URL> with the URL to the package. This will also 29878283Seivindautomatically install the packages the package you download is dependent on 29978283Seivind(ie, the packages it needs in order to work.) 30078283Seivind% 30178283SeivindYou can get a good standard workstation install by using the 30278283Seivindinstant-workstation port/package. If you have ports installed, you can 30378283Seivindinstall it by doing 30478283Seivind 30578283Seivind # cd /usr/ports/misc/instant-workstation 30678283Seivind # make install && make clean 30778283Seivind 30878283Seivindas root. This will install a collection of packages that is convenient to 30978283Seivindhave on a workstation. 31078283Seivind% 31178283SeivindYou can get a good generic server install by using the 31278283Seivindinstant-server port/package. If you have ports installed, you can 31378283Seivindinstall it by doing 31478283Seivind 31578283Seivind # cd /usr/ports/misc/instant-server 31678283Seivind # make install && make clean 31778283Seivind 31878283Seivindas root. This will install a collection of packages that is appropriate for 31978283Seivindrunning a "generic" server. 32078352Snik% 32178352SnikYou can make a log of you terminal session with script(1). 32278352Snik% 32378352Snik"man ports" gives many useful hints about installing FreeBSD ports. 32478352Snik% 32578352Snikports/net/netcat port is useful not only for redirecting input/output 32678352Snikto TCP or UDP connections, but also for proxying them. See inetd(8) for 32778352Snikdetails. 32878352Snik% 32978352SnikIf other operating systems have damaged your Master Boot Record, you can 33078352Snikreinstall it either with /stand/sysinstall or with boot0cfg(8). See 33178352Snik"man boot0cfg" for details. 33278355Snik% 33378355SnikNeed to see the calendar for this month? Simply type "cal". To see the 33478355Snikwhole year, type "cal 2001". 33578355Snik -- Dru <genesis@istar.ca> 33678355Snik% 33778355SnikNeed to quickly return to your home directory? Type "cd". 33878355Snik -- Dru <genesis@istar.ca> 33978355Snik% 34078355SnikTo see the last time that you logged in, use lastlogin(8). 34178355Snik -- Dru <genesis@istar.ca> 34278355Snik% 34378355SnikTo clear the screen, use "clear". To re-display your screen buffer, press 34478355Snikthe scroll lock key and use your page up button. When you're finished, 34578355Snikpress the scroll lock key again to get your prompt back. 34678355Snik -- Dru <genesis@istar.ca> 34778355Snik% 34878355SnikTo save disk space in your home directory, can compress files you 34978355Snikrarely use with "gzip filename". 35078355Snik -- Dru <genesis@istar.ca> 35178355Snik% 35278355SnikTo read a compressed file without having to first uncompress it, use 35378355Snik"zcat" or "zmore" to view it. 35478355Snik -- Dru <genesis@istar.ca> 35578355Snik% 35678355SnikTo see how much disk space is left on your partitions, use 35778355Snik 35878355Snik df -h 35978355Snik -- Dru <genesis@istar.ca> 36078355Snik% 36178355SnikTo see the 10 largest files on a directory or partition, use 36278355Snik 36378355Snik du /partition_or_directory_name | sort -rn | head 36478355Snik -- Dru <genesis@istar.ca> 36578355Snik% 36678355SnikTo determine whether a file is a text file, executable, or some other type 36778355Snikof file, use 36878355Snik 36978355Snik file filename 37078355Snik -- Dru <genesis@istar.ca> 37178355Snik% 37278355SnikTime to change your password? Type "passwd" and follow the prompts. 37378355Snik -- Dru <genesis@istar.ca> 37478355Snik% 37578355SnikWant to know how many words, lines, or bytes are contained in a file? Type 37678355Snik"wc filename". 37778355Snik -- Dru <genesis@istar.ca> 37878355Snik% 37978355SnikNeed to print a manpage? Use 38078355Snik 38178458Sdd man name_of_manpage | col -bx | lpr 38278355Snik -- Dru <genesis@istar.ca> 38378355Snik% 38478355SnikNeed to remove all those ^M characters from a DOS file? Try 38578355Snik 38678355Snik col -bx < dosfile > newfile 38778355Snik -- Dru <genesis@istar.ca> 38878355Snik% 38978355SnikForget what directory you are in? Type "pwd". 39078355Snik -- Dru <genesis@istar.ca> 39178355Snik% 39278355SnikIf you are in the C shell and have just installed a new program, you won't 39378355Snikbe able to run it unless you first type "rehash". 39478355Snik -- Dru <genesis@istar.ca> 39578355Snik% 39678355SnikNeed to leave your terminal for a few minutes and don't want to logout? 39778355SnikUse "lock -p". When you return, use your password as the key to unlock the 39878355Snikterminal. 39978355Snik -- Dru <genesis@istar.ca> 40078355Snik% 40178471SnikNeed to find the location of a program? Use "locate program_name". 40278355Snik -- Dru <genesis@istar.ca> 40378355Snik% 40478355SnikForget how to spell a word or a variation of a word? Use 40578355Snik 40678355Snik look portion_of_word_you_know 40778355Snik -- Dru <genesis@istar.ca> 40878355Snik% 40978355SnikTo see the last 10 lines of a long file, use "tail filename". To see the 41078355Snikfirst 10 lines, use "head filename". 41178355Snik -- Dru <genesis@istar.ca> 41278355Snik% 41378355SnikTo see how long it takes a command to run, type the word "time" before the 41478355Snikcommand name. 41578355Snik -- Dru <genesis@istar.ca> 41678355Snik% 41778355SnikTo quickly create an empty file, use "touch filename". 41878355Snik -- Dru <genesis@istar.ca> 41978355Snik% 42078355SnikTo find out the hostname associated with an IP address, use 42178355Snik 42278355Snik dig -x IP_address 42378355Snik -- Dru <genesis@istar.ca> 42478355Snik% 42578355SnikIf you use the C shell, add the following line to the .cshrc file in your 42678355Snikhome directory to prevent core files from being written to disk: 42778355Snik 42878355Snik limit coredumpsize 0 42978355Snik -- Dru <genesis@istar.ca> 43078355Snik% 43178355SnikIf you need a reminder to leave your terminal, type "leave hhmm" where 43278355Snik"hhmm" represents in how many hours and minutes you need to leave. 43378355Snik -- Dru <genesis@istar.ca> 43478355Snik% 43578355SnikNeed to do a search in a manpage or in a file you've sent to a pager? Use 43678355Snik"/search_word". To repeat the same search, type "n" for next. 43778355Snik -- Dru <genesis@istar.ca> 43878355Snik% 43978355SnikForget when Easter is? Try "ncal -e". If you need the date for Orthodox 44078355SnikEaster, use "ncal -o" instead. 44178355Snik -- Dru <genesis@istar.ca> 44278355Snik% 44378355SnikNeed to see your routing table? Type "netstat -rn". The entry with the G 44478355Snikflag is your gateway. 44578355Snik -- Dru <genesis@istar.ca> 44678355Snik% 44778355SnikNeed to see which daemons are listening for connection requests? Use 44878471Snik"sockstat -4l" for IPv4, and "sockstat -l" for IPv4 and IPv6. 44978355Snik -- Dru <genesis@istar.ca> 45078355Snik% 45178355SnikCan't remember is you've installed a certain port or not? Try "pkg_info | 45278355Snikgrep port_name". 45378355Snik -- Dru <genesis@istar.ca> 45478355Snik% 45578355SnikGot some time to kill? Try typing "hangman". 45678355Snik -- Dru <genesis@istar.ca> 45778355Snik% 45878355SnikTo erase a line you've written at the command prompt, use "Ctrl u". 45978355Snik -- Dru <genesis@istar.ca> 46078355Snik% 46178355SnikTo repeat the last command in the C shell, type "!!". 46278355Snik -- Dru <genesis@istar.ca> 46378355Snik% 46478355SnikNeed to quickly empty a file? Use "echo > filename". 46578355Snik -- Dru <genesis@istar.ca> 46678355Snik% 46778355SnikTo see all of the directories on your FreeBSD system, type 46878355Snik 46978471Snik ls -R / | more 47078355Snik -- Dru <genesis@istar.ca> 47178355Snik% 47278355SnikTo see the IP addresses currently set on your active interfaces, type 47378355Snik"ifconfig -u". 47478355Snik -- Dru <genesis@istar.ca> 47578355Snik% 47678355SnikTo see the MAC addresses of the NICs on your system, type 47778355Snik 47878471Snik ifconfig -a 47978355Snik -- Dru <genesis@istar.ca> 48078471Snik% 48178471SnikYou can save your kernel startup configuration with kget(8). The 48278471SnikConfiguration can be edited at boot time with 'boot -c' command in loader. 48378471SnikSee boot(8), loader(8) for details. 48478773Sbrian% 48578773SbrianYou can open up a new split-screen window in (n)vi with :N or :E and then 48678773Sbrianuse ^w to switch between the two. 48778774Sbrian% 48878774Sbriansh (the default bourne shell in FreeBSD) supports command-line editing. Just 48978774Sbrian``set -o emacs'' or ``set -o vi'' to enable it. 49078777Sbrian% 49178777SbrianWhen you've made modifications to a file in vi(1) and then find that 49278777Sbrianyou can't write it, type ``<ESC>!rm -f %'' then ``:w!'' to force the 49378777Sbrianwrite 49478777Sbrian 49578777SbrianThis won't work if you don't have write permissions to the directory 49678777Sbrianand probably won't be suitable if you're editing through a symbolic link. 497