freebsd-tips revision 90516
178266SnikThis fortune brought to you by: 278266Snik$FreeBSD: head/games/fortune/datfiles/freebsd-tips 90516 2002-02-11 03:45:29Z keramida $ 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 6478266Snikenvironment to 'K'. 6578266Snik% 6678266SnikTo change an environment variable in tcsh you use: setenv NAME "value" 6778266Snikwhere NAME is the name of the variable and "value" its new value. 6878266Snik% 6978266SnikTo change an environment variable in /bin/sh use: 7078266Snik 7178266Snik $ VARIABLE="value" 7278266Snik $ export VARIABLE 7378266Snik% 7482604SalexYou can use /etc/make.conf to control the options used to compile software 7582604Salexon this system. Example entries are in /usr/share/examples/etc/make.conf. 7678266Snik% 7778266SnikTo do a fast search for a file, try 7878266Snik 7978266Snik locate filename 8078266Snik 8179027Smpplocate uses a database that is updated every Saturday (assuming your computer 8278266Snikis running FreeBSD at the time) to quickly find files based on name only. 8378266Snik% 8478266SnikIn order to search for a string in some files, use 'grep' like this: 8578266Snik 8678266Snik grep "string" filename1 [filename2 filename3 ...] 8778266Snik 8878266SnikThis will print out the lines in the files that contain the string. grep can 8978266Snikalso do a lot more advanced searches - type 'man grep' for details. 9078266Snik% 9178266SnikYou can use the 'fetch' command to retrieve files over ftp or http. 9278266Snik 9378266Snik fetch http://www.freebsd.org/index.html 9478266Snik 9578266Snikwill download the front page of the FreeBSD web site. 9678266Snik% 9778266SnikIn order to make fetch (the FreeBSD downloading tool) ask for 9878266Snikusername/password when it encounter a password-protected web page, you can set 9978266Snikthe environment variable HTTP_AUTH to 'basic:*'. 10078266Snik% 10178266SnikYou can permanently set environment variables for your shell by putting them 10278266Snikin a startup file for the shell. The name of the startup file varies 10378772Sbriandepending on the shell - csh and tcsh uses .login, bash, sh, ksh and zsh use 10478772Sbrian.profile. When using bash, sh, ksh or zsh, don't forget to export the 10578772Sbrianvariable. 10678266Snik% 10778266SnikIf you are running xterm, the default TERM variable will be 'xterm'. If you 10878266Snikset this environment variable to 'xterm-color' instead, a lot of programs will 10978266Snikuse colors. You can do this by 11078266Snik 11178266Snik TERM=xterm-color; export TERM 11278266Snik 11378266Snikin Bourne-derived shells, and 11478266Snik 11578266Snik setenv TERM xterm-color 11678266Snik 11778266Snikin csh-derived shells. 11878266Snik% 11978266SnikIf you do not want to get beeps in X11 (X Windows), you can turn them off with 12078266Snik 12178266Snik xset b off 12278266Snik% 12378266SnikYou can look through a file in a nice text-based interface by typing 12478266Snik 12578266Snik less filename 12678266Snik% 12778266SnikThe default editor in FreeBSD is vi, which is efficient to use when you have 12878266Sniklearned it, but somewhat user-unfriendly. To use ee (an easier but less 12978266Snikpowerful editor) instead, set the environment variable EDITOR to /usr/bin/ee 13078266Snik% 13178266SnikIf you accidently end up inside vi, you can quit it by pressing Escape, colon 13278266Snik(:), q (q), bang (!) and pressing return. 13378266Snik% 13478266SnikYou can use aliases to decrease the amount of typing you need to do to get 13578266Snikcommands you commonly use. Examples of fairly popular aliases include (in 13678266Snikbourne shell style, as in /bin/sh, bash, ksh, and zsh): 13778266Snik 13878266Snik alias lf="ls -FA" 13978266Snik alias ll="ls -lA" 14078266Snik alias su="su -m" 14178266Snik 14278266SnikIn csh or tcsh, these would be 14378266Snik 14478266Snik alias lf ls -FA 14578266Snik alias ll ls -lA 14678266Snik alias su su -m 14778266Snik 14878266SnikTo remove an alias, you can usually use 'unalias aliasname'. To list all 14978266Snikaliases, you can usually type just 'alias'. 15078266Snik% 15178266SnikIn order to support national characters for european languages in tools like 15278266Snikless without creating other nationalisation aspects, set the environment 15378266Snikvariable LC_ALL to 'en_US.ISO8859-1'. 15478266Snik% 15578266SnikYou can search for documentation on a keyword by typing 15678266Snik 15778266Snik apropos keyword 15878266Snik% 15978266SnikMan pages are divided into section depending on topic. There are 9 different 16078266Sniksections numbered from 1 (General Commands) to 9 (Kernel Developer's Manual). 16178266SnikYou can get an introduction to each topic by typing 16278266Snik 16378266Snik man <number> intro 16478266Snik 16578266SnikIn other words, to get the intro to general commands, type 16678266Snik 16778266Snik man 1 intro 16878266Snik% 16978266SnikFreeBSD is started up by the program 'init'. The first thing init does when 17078266Snikstarting multiuser mode (ie, starting the computer up for normal use) is to 17178266Snikrun the shell script /etc/rc. By reading /etc/rc, you can learn a lot about 17278266Snikhow the system is put together, which again will make you more confident about 17378266Snikwhat happens when you do something with it. 17478266Snik% 17578266SnikIf you want to play CDs with FreeBSD, a utility for this is already included. 17678266SnikType 'cdcontrol' then 'help' to learn more. (You may need to set the CDROM 17778266Snikenvironment variable in order to make cdcontrol want to start.) 17878266Snik% 17978266SnikIf you have a CD-ROM drive in your machine, you can make the CD-ROM that is 18078266Snikpresently inserted available by typing 'mount /cdrom' as root. The CD-ROM 18178512Smphwill be available under /cdrom/. Remember to do 'umount /cdrom' before 18278266Snikremoving the CD-ROM (it will usually not be possible to remove the CD-ROM 18378266Snikwithout doing this.) 18478266Snik 18578266SnikNote: This tip may not work in all configurations. 18678266Snik% 18778266SnikYou can install extra packages for FreeBSD by using the ports system. 18878266SnikIf you have installed it, you can download, compile, and install software by 18978266Snikjust typing 19078266Snik 19178266Snik # cd /usr/ports/<category>/<portname> 19278266Snik # make install && make clean 19378266Snik 19478266Snikas root. The ports infrastructure will download the software, change it so 19578266Snikit works on FreeBSD, compile it, install it, register the installation so it 19678266Snikwill be possible to automatically uninstall it, and clean out the temporary 19778266Snikworking space it used. You can remove an installed port you decide you do not 19878266Snikwant after all by typing 19978266Snik 20078266Snik # cd /usr/ports/<category>/<portname> 20178266Snik # make deinstall 20278266Snik 20378266Snikas root. 20478266Snik% 20578266SnikNice bash prompt: PS1='(\[$(tput md)\]\t <\w>\[$(tput me)\]) $(echo $?) \$ ' 20678266Snik -- Mathieu <mathieu@hal.interactionvirtuelle.com> 20778266Snik% 20878266SnikTo see the output from when your computer started, run dmesg(8). If it has 20978266Snikbeen replaced with other messages, look at /var/run/dmesg.boot. 21078266Snik -- Francisco Reyes <lists@natserv.com> 21178266Snik% 21278266SnikYou can use "whereis" to locate standard binary, manual page and source 21378266Snikdirectories for the specified programs. This can be particularly handy 21478266Snikwhen you are trying to find where in the ports tree an application is. 21578266Snik 21678266SnikTry "whereis netscape" and "whereis whereis". 21778266Snik -- Konstantinos Konstantinidis <kkonstan@duth.gr> 21878266Snik% 21978266SnikYou can press Ctrl-D to quickly exit from a shell, or logout from a 22078266Sniklogin shell. 22178266Snik -- Konstantinos Konstantinidis <kkonstan@duth.gr> 22278266Snik% 22378266SnikYou can use "pkg_info" to see a list of packages you have installed. 22478266Snik -- Konstantinos Konstantinidis <kkonstan@duth.gr> 22578266Snik% 22678266SnikYou can change the video mode on all consoles by adding something like 22778266Snikthe following to /etc/rc.conf: 22878266Snik 22978266Snik allscreens="80x30" 23078266Snik 23178266SnikYou can use "vidcontrol -i mode | grep T" for a list of supported text 23278266Snikmodes. 23378266Snik -- Konstantinos Konstantinidis <kkonstan@duth.gr> 23478266Snik% 23578266SnikAny user that is a member of the wheel group can use "su -" to simulate 23678266Snika root login. You can add a user to the wheel group by editing /etc/group. 23778796Sdd -- Konstantinos Konstantinidis <kkonstan@duth.gr> 23878271Snik% 23978271SnikOver quota? "du -s * | sort -n " will give you a sorted list of your 24078271Snikdirectory sizes. 24178271Snik -- David Scheidt <dscheidt@tumbolia.com> 24278271Snik% 24378271SnikHandy bash(1) prompt: PS1="\u@\h \w \!$ " 24478271Snik -- David Scheidt <dscheidt@tumbolia.com> 24578271Snik% 24678271SnikEver wonder what those numbers after command names were, as in cat(1)? It's 24778271Snikthe section of the manual the man page is in. "man man" will tell you more. 24878271Snik -- David Scheidt <dscheidt@tumbolia.com> 24978271Snik% 25078271Snik"man hier" will explain the way FreeBSD filesystems are normally laid out. 25178271Snik -- David Scheidt <dscheidt@tumbolia.com> 25278271Snik% 25378271Snik"man tuning" gives some tips how to tune performance of your FreeBSD system. 25478271Snik -- David Scheidt <dscheidt@tumbolia.com> 25578271Snik% 25678271Snik"man firewall" will give advice for building a FreeBSD firewall 25778271Snik -- David Scheidt <dscheidt@tumbolia.com> 25878283Seivind% 25978283SeivindYou can often get answers to your questions about FreeBSD by searching in the 26078283SeivindFreeBSD mailing list archives at 26178283Seivind 26278283Seivind http://www.freebsd.org/search.html 26378283Seivind% 26478283SeivindYou can adjust the volume of various parts of the sound system in your 26578283Seivindcomputer by typing 'mixer <type> <volume>'. To get a list of what you can 26678283Seivindadjust, just type 'mixer'. 26778283Seivind% 26878283SeivindYou can automatically download and install binary packages by doing 26978283Seivind 27078283Seivind pkg_add -r <URL> 27178283Seivind 27278283Seivindwhere you replace <URL> with the URL to the package. This will also 27378283Seivindautomatically install the packages the package you download is dependent on 27478283Seivind(ie, the packages it needs in order to work.) 27578283Seivind% 27678283SeivindYou can get a good standard workstation install by using the 27778283Seivindinstant-workstation port/package. If you have ports installed, you can 27878283Seivindinstall it by doing 27978283Seivind 28078283Seivind # cd /usr/ports/misc/instant-workstation 28178283Seivind # make install && make clean 28278283Seivind 28378283Seivindas root. This will install a collection of packages that is convenient to 28478283Seivindhave on a workstation. 28578283Seivind% 28678283SeivindYou can get a good generic server install by using the 28778283Seivindinstant-server port/package. If you have ports installed, you can 28878283Seivindinstall it by doing 28978283Seivind 29078283Seivind # cd /usr/ports/misc/instant-server 29178283Seivind # make install && make clean 29278283Seivind 29378283Seivindas root. This will install a collection of packages that is appropriate for 29478283Seivindrunning a "generic" server. 29581558Smharo% 29679027SmppYou can make a log of your terminal session with script(1). 29781558Smharo% 29878352Snik"man ports" gives many useful hints about installing FreeBSD ports. 29981558Smharo% 30078352Snikports/net/netcat port is useful not only for redirecting input/output 30178352Snikto TCP or UDP connections, but also for proxying them. See inetd(8) for 30278352Snikdetails. 30381558Smharo% 30478352SnikIf other operating systems have damaged your Master Boot Record, you can 30578352Snikreinstall it either with /stand/sysinstall or with boot0cfg(8). See 30678352Snik"man boot0cfg" for details. 30781558Smharo% 30878355SnikNeed to see the calendar for this month? Simply type "cal". To see the 30978355Snikwhole year, type "cal 2001". 31078355Snik -- Dru <genesis@istar.ca> 31181558Smharo% 31278355SnikNeed to quickly return to your home directory? Type "cd". 31378355Snik -- Dru <genesis@istar.ca> 31481558Smharo% 31578355SnikTo see the last time that you logged in, use lastlogin(8). 31678355Snik -- Dru <genesis@istar.ca> 31781558Smharo% 31878355SnikTo clear the screen, use "clear". To re-display your screen buffer, press 31978355Snikthe scroll lock key and use your page up button. When you're finished, 32078355Snikpress the scroll lock key again to get your prompt back. 32178355Snik -- Dru <genesis@istar.ca> 32281558Smharo% 32378355SnikTo save disk space in your home directory, can compress files you 32478355Snikrarely use with "gzip filename". 32578355Snik -- Dru <genesis@istar.ca> 32681558Smharo% 32778355SnikTo read a compressed file without having to first uncompress it, use 32878355Snik"zcat" or "zmore" to view it. 32978355Snik -- Dru <genesis@istar.ca> 33081558Smharo% 33178355SnikTo see how much disk space is left on your partitions, use 33278355Snik 33378355Snik df -h 33478355Snik -- Dru <genesis@istar.ca> 33581558Smharo% 33678355SnikTo see the 10 largest files on a directory or partition, use 33778355Snik 33878355Snik du /partition_or_directory_name | sort -rn | head 33978355Snik -- Dru <genesis@istar.ca> 34081558Smharo% 34178355SnikTo determine whether a file is a text file, executable, or some other type 34278355Snikof file, use 34378355Snik 34478355Snik file filename 34578355Snik -- Dru <genesis@istar.ca> 34681558Smharo% 34778355SnikTime to change your password? Type "passwd" and follow the prompts. 34878355Snik -- Dru <genesis@istar.ca> 34981558Smharo% 35078355SnikWant to know how many words, lines, or bytes are contained in a file? Type 35178355Snik"wc filename". 35278355Snik -- Dru <genesis@istar.ca> 35381558Smharo% 35478355SnikNeed to print a manpage? Use 35578355Snik 35678458Sdd man name_of_manpage | col -bx | lpr 35778355Snik -- Dru <genesis@istar.ca> 35881558Smharo% 35978355SnikNeed to remove all those ^M characters from a DOS file? Try 36078355Snik 36178355Snik col -bx < dosfile > newfile 36278355Snik -- Dru <genesis@istar.ca> 36381558Smharo% 36478355SnikForget what directory you are in? Type "pwd". 36578355Snik -- Dru <genesis@istar.ca> 36681558Smharo% 36778355SnikIf you are in the C shell and have just installed a new program, you won't 36878355Snikbe able to run it unless you first type "rehash". 36978355Snik -- Dru <genesis@istar.ca> 37081558Smharo% 37178355SnikNeed to leave your terminal for a few minutes and don't want to logout? 37278355SnikUse "lock -p". When you return, use your password as the key to unlock the 37378355Snikterminal. 37478355Snik -- Dru <genesis@istar.ca> 37581558Smharo% 37678471SnikNeed to find the location of a program? Use "locate program_name". 37778355Snik -- Dru <genesis@istar.ca> 37881558Smharo% 37978355SnikForget how to spell a word or a variation of a word? Use 38078355Snik 38178355Snik look portion_of_word_you_know 38278355Snik -- Dru <genesis@istar.ca> 38381558Smharo% 38478355SnikTo see the last 10 lines of a long file, use "tail filename". To see the 38578355Snikfirst 10 lines, use "head filename". 38678355Snik -- Dru <genesis@istar.ca> 38781558Smharo% 38878355SnikTo see how long it takes a command to run, type the word "time" before the 38978355Snikcommand name. 39078355Snik -- Dru <genesis@istar.ca> 39181558Smharo% 39278355SnikTo quickly create an empty file, use "touch filename". 39378355Snik -- Dru <genesis@istar.ca> 39481558Smharo% 39578355SnikTo find out the hostname associated with an IP address, use 39678355Snik 39778355Snik dig -x IP_address 39878355Snik -- Dru <genesis@istar.ca> 39981558Smharo% 40078355SnikIf you use the C shell, add the following line to the .cshrc file in your 40178355Snikhome directory to prevent core files from being written to disk: 40278355Snik 40378355Snik limit coredumpsize 0 40478355Snik -- Dru <genesis@istar.ca> 40581558Smharo% 40678355SnikIf you need a reminder to leave your terminal, type "leave hhmm" where 40778355Snik"hhmm" represents in how many hours and minutes you need to leave. 40878355Snik -- Dru <genesis@istar.ca> 40981558Smharo% 41078355SnikNeed to do a search in a manpage or in a file you've sent to a pager? Use 41178355Snik"/search_word". To repeat the same search, type "n" for next. 41278355Snik -- Dru <genesis@istar.ca> 41381558Smharo% 41478355SnikForget when Easter is? Try "ncal -e". If you need the date for Orthodox 41578355SnikEaster, use "ncal -o" instead. 41678355Snik -- Dru <genesis@istar.ca> 41781558Smharo% 41878355SnikNeed to see your routing table? Type "netstat -rn". The entry with the G 41978355Snikflag is your gateway. 42078355Snik -- Dru <genesis@istar.ca> 42181558Smharo% 42278355SnikNeed to see which daemons are listening for connection requests? Use 42378471Snik"sockstat -4l" for IPv4, and "sockstat -l" for IPv4 and IPv6. 42478355Snik -- Dru <genesis@istar.ca> 42581558Smharo% 42678355SnikCan't remember is you've installed a certain port or not? Try "pkg_info | 42778355Snikgrep port_name". 42878355Snik -- Dru <genesis@istar.ca> 42981558Smharo% 43078355SnikGot some time to kill? Try typing "hangman". 43178355Snik -- Dru <genesis@istar.ca> 43281558Smharo% 43378355SnikTo erase a line you've written at the command prompt, use "Ctrl u". 43478355Snik -- Dru <genesis@istar.ca> 43581558Smharo% 43678355SnikTo repeat the last command in the C shell, type "!!". 43778355Snik -- Dru <genesis@istar.ca> 43881558Smharo% 43978355SnikNeed to quickly empty a file? Use "echo > filename". 44078355Snik -- Dru <genesis@istar.ca> 44181558Smharo% 44278355SnikTo see all of the directories on your FreeBSD system, type 44378355Snik 44478471Snik ls -R / | more 44578355Snik -- Dru <genesis@istar.ca> 44681558Smharo% 44778355SnikTo see the IP addresses currently set on your active interfaces, type 44878355Snik"ifconfig -u". 44978355Snik -- Dru <genesis@istar.ca> 45081558Smharo% 45178355SnikTo see the MAC addresses of the NICs on your system, type 45278355Snik 45378471Snik ifconfig -a 45478355Snik -- Dru <genesis@istar.ca> 45578471Snik% 45678471SnikYou can save your kernel startup configuration with kget(8). The 45778471SnikConfiguration can be edited at boot time with 'boot -c' command in loader. 45878471SnikSee boot(8), loader(8) for details. 45978773Sbrian% 46078773SbrianYou can open up a new split-screen window in (n)vi with :N or :E and then 46178773Sbrianuse ^w to switch between the two. 46278774Sbrian% 46378774Sbriansh (the default bourne shell in FreeBSD) supports command-line editing. Just 46478774Sbrian``set -o emacs'' or ``set -o vi'' to enable it. 46578777Sbrian% 46678777SbrianWhen you've made modifications to a file in vi(1) and then find that 46778777Sbrianyou can't write it, type ``<ESC>!rm -f %'' then ``:w!'' to force the 46878777Sbrianwrite 46978777Sbrian 47078777SbrianThis won't work if you don't have write permissions to the directory 47178777Sbrianand probably won't be suitable if you're editing through a symbolic link. 47290516Skeramida% 47390516SkeramidaIf you want to quickly check for duplicate package/port installations, 47490516Skeramidatry the following pkg_info command. 47590516Skeramida 47690516Skeramida pkg_info | sort | sed -e 's/-[0-9].*$//' | \ 47790516Skeramida uniq -c | grep -v '^[[:space:]]*1' 478