freebsd-tips revision 93518
11556SrgrimesThis fortune brought to you by: 21556Srgrimes$FreeBSD: head/games/fortune/datfiles/freebsd-tips 93518 2002-04-01 08:53:21Z joe $ 31556Srgrimes% 41556SrgrimesHaving trouble using fetch through a firewall? Try setting the environment 51556Srgrimesvariable FTP_PASSIVE_MODE to yes, and see fetch(3) for more details. 61556Srgrimes% 71556SrgrimesBy pressing "Scroll Lock" you can use the arrow keys to scroll backward 81556Srgrimesthrough the console output. Press "Scroll Lock" again to turn it off. 91556Srgrimes% 101556SrgrimesWant colour in your directory listings? Use "ls -G". "ls -F" is also useful, 111556Srgrimesand they can be combined as "ls -FG". 121556Srgrimes% 131556SrgrimesIf you need to ask a question on the FreeBSD-questions mailing list then 141556Srgrimes 151556Srgrimes http://www.freebsd.org/doc/en_US.ISO8859-1/articles/\ 161556Srgrimes freebsd-questions/index.html 171556Srgrimes 181556Srgrimescontains lots of useful advice to help you get the best results. 191556Srgrimes% 201556SrgrimesIf you'd like to keep track of applications in the FreeBSD ports tree, take a 211556Srgrimeslook at FreshPorts; 221556Srgrimes 231556Srgrimes http://www.freshports.org/ 241556Srgrimes% 251556SrgrimesTo search for files that match a particular name, use find(1); for example 261556Srgrimes 271556Srgrimes find / -name "*GENERIC*" -ls 281556Srgrimes 291556Srgrimeswill search '/', and all subdirectories, for files with 'GENERIC' in the name. 301556Srgrimes -- Stephen Hilton <nospam@hiltonbsd.com> 311556Srgrimes% 321556SrgrimesIn tcsh, you can `set autolist' to have the shell automatically show 331556Srgrimesall the possible matches when doing filename/directory expansion. 341556Srgrimes% 351556SrgrimesYou can `set autologout = 30' to have tcsh log you off automatically 3617987Speterif you leave the shell idle for more than 30 minutes. 3717987Speter% 381556SrgrimesIf you `set filec' (file completion) in tcsh and write a part of the 391556Srgrimesfilename, pressing TAB will show you the available choices when there 4017987Speteris more than one, or complete the filename if there's only one match. 411556Srgrimes% 421556SrgrimesYou can press up-arrow or down-arrow to walk through a list of 431556Srgrimesprevious commands in tcsh. 441556Srgrimes% 451556SrgrimesYou can disable tcsh's terminal beep if you `set nobeep'. 461556Srgrimes% 471556SrgrimesIf you `set watch (0 any any)' in tcsh, you will be notified when 481556Srgrimessomeone logs in or out of your system. 491556Srgrimes% 501556SrgrimesNice tcsh prompt: set prompt = '%m %# ' 511556Srgrimes% 5217987SpeterNice tcsh prompt: set prompt = '%n@%m%# ' 5317987Speter% 541556SrgrimesNice tcsh prompt: set prompt = '%n@%m:%~%# ' 5517987Speter% 561556SrgrimesNice tcsh prompt: set prompt = '%n@%m:%/%# ' 571556Srgrimes% 581556SrgrimesNice tcsh prompt: set prompt = '[%B%m%b] %B%~%b%# ' 591556Srgrimes% 6017987SpeterSimple tcsh prompt: set prompt = '%# ' 6117987Speter% 6217987SpeterIf you want df(1) and other commands to display disk sizes in 6317987Speterkilobytes instead of 512-byte blocks, set BLOCKSIZE in your 6417987Speterenvironment to 'K'. You can also use 'M' for Megabytes or 'G' for 651556SrgrimesGigabytes. If you want df(1) to automatically select the best size 661556Srgrimesthen use 'df -h'. 671556Srgrimes% 681556SrgrimesTo change an environment variable in tcsh you use: setenv NAME "value" 691556Srgrimeswhere NAME is the name of the variable and "value" its new value. 701556Srgrimes% 711556SrgrimesTo change an environment variable in /bin/sh use: 721556Srgrimes 731556Srgrimes $ VARIABLE="value" 7417987Speter $ export VARIABLE 7517987Speter% 7617987SpeterYou can use /etc/make.conf to control the options used to compile software 7717987Speteron this system. Example entries are in /usr/share/examples/etc/make.conf. 7817987Speter% 7917987SpeterTo do a fast search for a file, try 8017987Speter 8117987Speter locate filename 8217987Speter 8317987Speterlocate uses a database that is updated every Saturday (assuming your computer 841556Srgrimesis running FreeBSD at the time) to quickly find files based on name only. 851556Srgrimes% 861556SrgrimesIn order to search for a string in some files, use 'grep' like this: 871556Srgrimes 881556Srgrimes grep "string" filename1 [filename2 filename3 ...] 891556Srgrimes 9017987SpeterThis will print out the lines in the files that contain the string. grep can 9117987Speteralso do a lot more advanced searches - type 'man grep' for details. 9217987Speter% 931556SrgrimesYou can use the 'fetch' command to retrieve files over ftp or http. 941556Srgrimes 951556Srgrimes fetch http://www.freebsd.org/index.html 961556Srgrimes 971556Srgrimeswill download the front page of the FreeBSD web site. 981556Srgrimes% 9917987SpeterIn order to make fetch (the FreeBSD downloading tool) ask for 10017987Speterusername/password when it encounter a password-protected web page, you can set 10117987Speterthe environment variable HTTP_AUTH to 'basic:*'. 10217987Speter% 10317987SpeterYou can permanently set environment variables for your shell by putting them 10417987Speterin a startup file for the shell. The name of the startup file varies 10517987Speterdepending on the shell - csh and tcsh uses .login, bash, sh, ksh and zsh use 1061556Srgrimes.profile. When using bash, sh, ksh or zsh, don't forget to export the 1071556Srgrimesvariable. 1081556Srgrimes% 1091556SrgrimesIf you are running xterm, the default TERM variable will be 'xterm'. If you 1101556Srgrimesset this environment variable to 'xterm-color' instead, a lot of programs will 1111556Srgrimesuse colors. You can do this by 11217987Speter 11317987Speter TERM=xterm-color; export TERM 11417987Speter 1151556Srgrimesin Bourne-derived shells, and 11617987Speter 11717987Speter setenv TERM xterm-color 1181556Srgrimes 1191556Srgrimesin csh-derived shells. 1201556Srgrimes% 1211556SrgrimesIf you do not want to get beeps in X11 (X Windows), you can turn them off with 1221556Srgrimes 12317987Speter xset b off 12417987Speter% 12517987SpeterYou can look through a file in a nice text-based interface by typing 12617987Speter 1271556Srgrimes less filename 12817987Speter% 12917987SpeterThe default editor in FreeBSD is vi, which is efficient to use when you have 13017987Speterlearned it, but somewhat user-unfriendly. To use ee (an easier but less 13117987Speterpowerful editor) instead, set the environment variable EDITOR to /usr/bin/ee 13217987Speter% 13317987SpeterIf you accidently end up inside vi, you can quit it by pressing Escape, colon 13417987Speter(:), q (q), bang (!) and pressing return. 13517987Speter% 13617987SpeterYou can use aliases to decrease the amount of typing you need to do to get 13717987Spetercommands you commonly use. Examples of fairly popular aliases include (in 1381556Srgrimesbourne shell style, as in /bin/sh, bash, ksh, and zsh): 1391556Srgrimes 1401556Srgrimes alias lf="ls -FA" 1411556Srgrimes alias ll="ls -lA" 1421556Srgrimes alias su="su -m" 1431556Srgrimes 14417987SpeterIn csh or tcsh, these would be 14517987Speter 14617987Speter alias lf ls -FA 14717987Speter alias ll ls -lA 14817987Speter alias su su -m 1491556Srgrimes 15017987SpeterTo remove an alias, you can usually use 'unalias aliasname'. To list all 15117987Speteraliases, you can usually type just 'alias'. 15217987Speter% 15317987SpeterIn order to support national characters for european languages in tools like 1541556Srgrimesless without creating other nationalisation aspects, set the environment 1551556Srgrimesvariable LC_ALL to 'en_US.ISO8859-1'. 1561556Srgrimes% 1571556SrgrimesYou can search for documentation on a keyword by typing 1581556Srgrimes 1591556Srgrimes apropos keyword 1601556Srgrimes% 1611556SrgrimesMan pages are divided into section depending on topic. There are 9 different 1621556Srgrimessections numbered from 1 (General Commands) to 9 (Kernel Developer's Manual). 1631556SrgrimesYou can get an introduction to each topic by typing 16417987Speter 16517987Speter man <number> intro 16617987Speter 16717987SpeterIn other words, to get the intro to general commands, type 1681556Srgrimes 169 man 1 intro 170% 171FreeBSD is started up by the program 'init'. The first thing init does when 172starting multiuser mode (ie, starting the computer up for normal use) is to 173run the shell script /etc/rc. By reading /etc/rc, you can learn a lot about 174how the system is put together, which again will make you more confident about 175what happens when you do something with it. 176% 177If you want to play CDs with FreeBSD, a utility for this is already included. 178Type 'cdcontrol' then 'help' to learn more. (You may need to set the CDROM 179environment variable in order to make cdcontrol want to start.) 180% 181If you have a CD-ROM drive in your machine, you can make the CD-ROM that is 182presently inserted available by typing 'mount /cdrom' as root. The CD-ROM 183will be available under /cdrom/. Remember to do 'umount /cdrom' before 184removing the CD-ROM (it will usually not be possible to remove the CD-ROM 185without doing this.) 186 187Note: This tip may not work in all configurations. 188% 189You can install extra packages for FreeBSD by using the ports system. 190If you have installed it, you can download, compile, and install software by 191just typing 192 193 # cd /usr/ports/<category>/<portname> 194 # make install && make clean 195 196as root. The ports infrastructure will download the software, change it so 197it works on FreeBSD, compile it, install it, register the installation so it 198will be possible to automatically uninstall it, and clean out the temporary 199working space it used. You can remove an installed port you decide you do not 200want after all by typing 201 202 # cd /usr/ports/<category>/<portname> 203 # make deinstall 204 205as root. 206% 207Nice bash prompt: PS1='(\[$(tput md)\]\t <\w>\[$(tput me)\]) $(echo $?) \$ ' 208 -- Mathieu <mathieu@hal.interactionvirtuelle.com> 209% 210To see the output from when your computer started, run dmesg(8). If it has 211been replaced with other messages, look at /var/run/dmesg.boot. 212 -- Francisco Reyes <lists@natserv.com> 213% 214You can use "whereis" to locate standard binary, manual page and source 215directories for the specified programs. This can be particularly handy 216when you are trying to find where in the ports tree an application is. 217 218Try "whereis netscape" and "whereis whereis". 219 -- Konstantinos Konstantinidis <kkonstan@duth.gr> 220% 221You can press Ctrl-D to quickly exit from a shell, or logout from a 222login shell. 223 -- Konstantinos Konstantinidis <kkonstan@duth.gr> 224% 225You can use "pkg_info" to see a list of packages you have installed. 226 -- Konstantinos Konstantinidis <kkonstan@duth.gr> 227% 228You can change the video mode on all consoles by adding something like 229the following to /etc/rc.conf: 230 231 allscreens="80x30" 232 233You can use "vidcontrol -i mode | grep T" for a list of supported text 234modes. 235 -- Konstantinos Konstantinidis <kkonstan@duth.gr> 236% 237Any user that is a member of the wheel group can use "su -" to simulate 238a root login. You can add a user to the wheel group by editing /etc/group. 239 -- Konstantinos Konstantinidis <kkonstan@duth.gr> 240% 241Over quota? "du -s * | sort -n " will give you a sorted list of your 242directory sizes. 243 -- David Scheidt <dscheidt@tumbolia.com> 244% 245Handy bash(1) prompt: PS1="\u@\h \w \!$ " 246 -- David Scheidt <dscheidt@tumbolia.com> 247% 248Ever wonder what those numbers after command names were, as in cat(1)? It's 249the section of the manual the man page is in. "man man" will tell you more. 250 -- David Scheidt <dscheidt@tumbolia.com> 251% 252"man hier" will explain the way FreeBSD filesystems are normally laid out. 253 -- David Scheidt <dscheidt@tumbolia.com> 254% 255"man tuning" gives some tips how to tune performance of your FreeBSD system. 256 -- David Scheidt <dscheidt@tumbolia.com> 257% 258"man firewall" will give advice for building a FreeBSD firewall 259 -- David Scheidt <dscheidt@tumbolia.com> 260% 261You can often get answers to your questions about FreeBSD by searching in the 262FreeBSD mailing list archives at 263 264 http://www.freebsd.org/search.html 265% 266You can adjust the volume of various parts of the sound system in your 267computer by typing 'mixer <type> <volume>'. To get a list of what you can 268adjust, just type 'mixer'. 269% 270You can automatically download and install binary packages by doing 271 272 pkg_add -r <URL> 273 274where you replace <URL> with the URL to the package. This will also 275automatically install the packages the package you download is dependent on 276(ie, the packages it needs in order to work.) 277% 278You can get a good standard workstation install by using the 279instant-workstation port/package. If you have ports installed, you can 280install it by doing 281 282 # cd /usr/ports/misc/instant-workstation 283 # make install && make clean 284 285as root. This will install a collection of packages that is convenient to 286have on a workstation. 287% 288You can get a good generic server install by using the 289instant-server port/package. If you have ports installed, you can 290install it by doing 291 292 # cd /usr/ports/misc/instant-server 293 # make install && make clean 294 295as root. This will install a collection of packages that is appropriate for 296running a "generic" server. 297% 298You can make a log of your terminal session with script(1). 299% 300"man ports" gives many useful hints about installing FreeBSD ports. 301% 302"man security" gives very good advice on how to tune the security of your 303FreeBSD system. 304% 305Want to find a specific port, just type the following under /usr/ports, 306or one its subdirectories: 307 308 "make search port=<port-name>" 309 or 310 "make search key="<keyword>" 311% 312Want to see how much virtual memory you're using? Just type "swapinfo" to 313be shown information about the usage of your swap partitions. 314% 315ports/net/netcat port is useful not only for redirecting input/output 316to TCP or UDP connections, but also for proxying them. See inetd(8) for 317details. 318% 319If other operating systems have damaged your Master Boot Record, you can 320reinstall it either with /stand/sysinstall or with boot0cfg(8). See 321"man boot0cfg" for details. 322% 323Need to see the calendar for this month? Simply type "cal". To see the 324whole year, type "cal 2002". 325 -- Dru <genesis@istar.ca> 326% 327Need to quickly return to your home directory? Type "cd". 328 -- Dru <genesis@istar.ca> 329% 330To see the last time that you logged in, use lastlogin(8). 331 -- Dru <genesis@istar.ca> 332% 333To clear the screen, use "clear". To re-display your screen buffer, press 334the scroll lock key and use your page up button. When you're finished, 335press the scroll lock key again to get your prompt back. 336 -- Dru <genesis@istar.ca> 337% 338To save disk space in your home directory, can compress files you 339rarely use with "gzip filename". 340 -- Dru <genesis@istar.ca> 341% 342To read a compressed file without having to first uncompress it, use 343"zcat" or "zmore" to view it. 344 -- Dru <genesis@istar.ca> 345% 346To see how much disk space is left on your partitions, use 347 348 df -h 349 -- Dru <genesis@istar.ca> 350% 351To see the 10 largest files on a directory or partition, use 352 353 du /partition_or_directory_name | sort -rn | head 354 -- Dru <genesis@istar.ca> 355% 356To determine whether a file is a text file, executable, or some other type 357of file, use 358 359 file filename 360 -- Dru <genesis@istar.ca> 361% 362Time to change your password? Type "passwd" and follow the prompts. 363 -- Dru <genesis@istar.ca> 364% 365Want to know how many words, lines, or bytes are contained in a file? Type 366"wc filename". 367 -- Dru <genesis@istar.ca> 368% 369Need to print a manpage? Use 370 371 man name_of_manpage | col -bx | lpr 372 -- Dru <genesis@istar.ca> 373% 374Need to remove all those ^M characters from a DOS file? Try 375 376 col -bx < dosfile > newfile 377 -- Dru <genesis@istar.ca> 378% 379Forget what directory you are in? Type "pwd". 380 -- Dru <genesis@istar.ca> 381% 382If you are in the C shell and have just installed a new program, you won't 383be able to run it unless you first type "rehash". 384 -- Dru <genesis@istar.ca> 385% 386Need to leave your terminal for a few minutes and don't want to logout? 387Use "lock -p". When you return, use your password as the key to unlock the 388terminal. 389 -- Dru <genesis@istar.ca> 390% 391Need to find the location of a program? Use "locate program_name". 392 -- Dru <genesis@istar.ca> 393% 394Forget how to spell a word or a variation of a word? Use 395 396 look portion_of_word_you_know 397 -- Dru <genesis@istar.ca> 398% 399To see the last 10 lines of a long file, use "tail filename". To see the 400first 10 lines, use "head filename". 401 -- Dru <genesis@istar.ca> 402% 403To see how long it takes a command to run, type the word "time" before the 404command name. 405 -- Dru <genesis@istar.ca> 406% 407To quickly create an empty file, use "touch filename". 408 -- Dru <genesis@istar.ca> 409% 410To find out the hostname associated with an IP address, use 411 412 dig -x IP_address 413 -- Dru <genesis@istar.ca> 414% 415If you use the C shell, add the following line to the .cshrc file in your 416home directory to prevent core files from being written to disk: 417 418 limit coredumpsize 0 419 -- Dru <genesis@istar.ca> 420% 421If you need a reminder to leave your terminal, type "leave hhmm" where 422"hhmm" represents in how many hours and minutes you need to leave. 423 -- Dru <genesis@istar.ca> 424% 425Need to do a search in a manpage or in a file you've sent to a pager? Use 426"/search_word". To repeat the same search, type "n" for next. 427 -- Dru <genesis@istar.ca> 428% 429Forget when Easter is? Try "ncal -e". If you need the date for Orthodox 430Easter, use "ncal -o" instead. 431 -- Dru <genesis@istar.ca> 432% 433Need to see your routing table? Type "netstat -rn". The entry with the G 434flag is your gateway. 435 -- Dru <genesis@istar.ca> 436% 437Need to see which daemons are listening for connection requests? Use 438"sockstat -4l" for IPv4, and "sockstat -l" for IPv4 and IPv6. 439 -- Dru <genesis@istar.ca> 440% 441Can't remember is you've installed a certain port or not? Try "pkg_info | 442grep port_name". 443 -- Dru <genesis@istar.ca> 444% 445Got some time to kill? Try typing "hangman". 446 -- Dru <genesis@istar.ca> 447% 448To erase a line you've written at the command prompt, use "Ctrl-U". 449 -- Dru <genesis@istar.ca> 450% 451To repeat the last command in the C shell, type "!!". 452 -- Dru <genesis@istar.ca> 453% 454Need to quickly empty a file? Use "echo > filename". 455 -- Dru <genesis@istar.ca> 456% 457To see all of the directories on your FreeBSD system, type 458 459 ls -R / | more 460 -- Dru <genesis@istar.ca> 461% 462To see the IP addresses currently set on your active interfaces, type 463"ifconfig -u". 464 -- Dru <genesis@istar.ca> 465% 466To see the MAC addresses of the NICs on your system, type 467 468 ifconfig -a 469 -- Dru <genesis@istar.ca> 470% 471You can save your kernel startup configuration with kget(8). The 472Configuration can be edited at boot time with 'boot -c' command in loader. 473See boot(8), loader(8) for details. 474% 475You can open up a new split-screen window in (n)vi with :N or :E and then 476use ^w to switch between the two. 477% 478sh (the default bourne shell in FreeBSD) supports command-line editing. Just 479``set -o emacs'' or ``set -o vi'' to enable it. 480% 481When you've made modifications to a file in vi(1) and then find that 482you can't write it, type ``<ESC>!rm -f %'' then ``:w!'' to force the 483write 484 485This won't work if you don't have write permissions to the directory 486and probably won't be suitable if you're editing through a symbolic link. 487% 488If you want to quickly check for duplicate package/port installations, 489try the following pkg_info command. 490 491 pkg_info | sort | sed -e 's/-[0-9].*$//' | \ 492 uniq -c | grep -v '^[[:space:]]*1' 493