freebsd-tips revision 86620
1This fortune brought to you by: 2$FreeBSD: head/games/fortune/datfiles/freebsd-tips 86620 2001-11-19 20:17:19Z keramida $ 3% 4Having trouble using FTP through a firewall? Try setting the environment 5variable FTP_PASSIVE_MODE to yes, and see ftp(1) for more details. 6% 7By pressing "Scroll Lock" you can use the arrow keys to scroll backward 8through the console output. Press "Scroll Lock" again to turn it off. 9% 10Want colour in your directory listings? Use "ls -G". "ls -F" is also useful, 11and they can be combined as "ls -FG". 12% 13If you need to ask a question on the FreeBSD-questions mailing list then 14 15 http://www.freebsd.org/doc/en_US.ISO8859-1/articles/\ 16 freebsd-questions/index.html 17 18contains lots of useful advice to help you get the best results. 19% 20If you'd like to keep track of applications in the FreeBSD ports tree, take a 21look at FreshPorts; 22 23 http://www.freshports.org/ 24% 25To search for files that match a particular name, use find(1); for example 26 27 find / -name "*GENERIC*" -ls 28 29will search '/', and all subdirectories, for files with 'GENERIC' in the name. 30 -- Stephen Hilton <nospam@hiltonbsd.com> 31% 32In tcsh, you can `set autolist' to have the shell automatically show 33all the possible matches when doing filename/directory expansion. 34% 35You can `set autologout = 30' to have tcsh log you off automatically 36if you leave the shell idle for more than 30 minutes. 37% 38If you `set filec' (file completion) in tcsh and write a part of the 39filename, pressing TAB will show you the available choices when there 40is more than one, or complete the filename if there's only one match. 41% 42You can press up-arrow or down-arrow to walk through a list of 43previous commands in tcsh. 44% 45You can disable tcsh's terminal beep if you `set nobeep'. 46% 47If you `set watch (0 any any)' in tcsh, you will be notified when 48someone logs in or out of your system. 49% 50Nice tcsh prompt: set prompt = '%m %# ' 51% 52Nice tcsh prompt: set prompt = '%n@%m%# ' 53% 54Nice tcsh prompt: set prompt = '%n@%m:%~%# ' 55% 56Nice tcsh prompt: set prompt = '%n@%m:%/%# ' 57% 58Nice tcsh prompt: set prompt = '[%B%m%b] %B%~%b%# ' 59% 60Simple tcsh prompt: set prompt = '%# ' 61% 62If you want df(1) and other commands to display disk sizes in 63kilobytes instead of 512-byte blocks, set BLOCKSIZE in your 64environment to 'K'. 65% 66To change an environment variable in tcsh you use: setenv NAME "value" 67where NAME is the name of the variable and "value" its new value. 68% 69To change an environment variable in /bin/sh use: 70 71 $ VARIABLE="value" 72 $ export VARIABLE 73% 74You can use /etc/make.conf to control the options used to compile software 75on this system. Example entries are in /usr/share/examples/etc/make.conf. 76% 77To do a fast search for a file, try 78 79 locate filename 80 81locate uses a database that is updated every Saturday (assuming your computer 82is running FreeBSD at the time) to quickly find files based on name only. 83% 84In order to search for a string in some files, use 'grep' like this: 85 86 grep "string" filename1 [filename2 filename3 ...] 87 88This will print out the lines in the files that contain the string. grep can 89also do a lot more advanced searches - type 'man grep' for details. 90% 91You can use the 'fetch' command to retrieve files over ftp or http. 92 93 fetch http://www.freebsd.org/index.html 94 95will download the front page of the FreeBSD web site. 96% 97In order to make fetch (the FreeBSD downloading tool) ask for 98username/password when it encounter a password-protected web page, you can set 99the environment variable HTTP_AUTH to 'basic:*'. 100% 101You can permanently set environment variables for your shell by putting them 102in a startup file for the shell. The name of the startup file varies 103depending on the shell - csh and tcsh uses .login, bash, sh, ksh and zsh use 104.profile. When using bash, sh, ksh or zsh, don't forget to export the 105variable. 106% 107If you are running xterm, the default TERM variable will be 'xterm'. If you 108set this environment variable to 'xterm-color' instead, a lot of programs will 109use colors. You can do this by 110 111 TERM=xterm-color; export TERM 112 113in Bourne-derived shells, and 114 115 setenv TERM xterm-color 116 117in csh-derived shells. 118% 119If you do not want to get beeps in X11 (X Windows), you can turn them off with 120 121 xset b off 122% 123You can look through a file in a nice text-based interface by typing 124 125 less filename 126% 127The default editor in FreeBSD is vi, which is efficient to use when you have 128learned it, but somewhat user-unfriendly. To use ee (an easier but less 129powerful editor) instead, set the environment variable EDITOR to /usr/bin/ee 130% 131If you accidently end up inside vi, you can quit it by pressing Escape, colon 132(:), q (q), bang (!) and pressing return. 133% 134You can use aliases to decrease the amount of typing you need to do to get 135commands you commonly use. Examples of fairly popular aliases include (in 136bourne shell style, as in /bin/sh, bash, ksh, and zsh): 137 138 alias lf="ls -FA" 139 alias ll="ls -lA" 140 alias su="su -m" 141 142In csh or tcsh, these would be 143 144 alias lf ls -FA 145 alias ll ls -lA 146 alias su su -m 147 148To remove an alias, you can usually use 'unalias aliasname'. To list all 149aliases, you can usually type just 'alias'. 150% 151In order to support national characters for european languages in tools like 152less without creating other nationalisation aspects, set the environment 153variable LC_ALL to 'en_US.ISO8859-1'. 154% 155You can search for documentation on a keyword by typing 156 157 apropos keyword 158% 159Man pages are divided into section depending on topic. There are 9 different 160sections numbered from 1 (General Commands) to 9 (Kernel Developer's Manual). 161You can get an introduction to each topic by typing 162 163 man <number> intro 164 165In other words, to get the intro to general commands, type 166 167 man 1 intro 168% 169FreeBSD is started up by the program 'init'. The first thing init does when 170starting multiuser mode (ie, starting the computer up for normal use) is to 171run the shell script /etc/rc. By reading /etc/rc, you can learn a lot about 172how the system is put together, which again will make you more confident about 173what happens when you do something with it. 174% 175If you want to play CDs with FreeBSD, a utility for this is already included. 176Type 'cdcontrol' then 'help' to learn more. (You may need to set the CDROM 177environment variable in order to make cdcontrol want to start.) 178% 179If you have a CD-ROM drive in your machine, you can make the CD-ROM that is 180presently inserted available by typing 'mount /cdrom' as root. The CD-ROM 181will be available under /cdrom/. Remember to do 'umount /cdrom' before 182removing the CD-ROM (it will usually not be possible to remove the CD-ROM 183without doing this.) 184 185Note: This tip may not work in all configurations. 186% 187You can install extra packages for FreeBSD by using the ports system. 188If you have installed it, you can download, compile, and install software by 189just typing 190 191 # cd /usr/ports/<category>/<portname> 192 # make install && make clean 193 194as root. The ports infrastructure will download the software, change it so 195it works on FreeBSD, compile it, install it, register the installation so it 196will be possible to automatically uninstall it, and clean out the temporary 197working space it used. You can remove an installed port you decide you do not 198want after all by typing 199 200 # cd /usr/ports/<category>/<portname> 201 # make deinstall 202 203as root. 204% 205Nice bash prompt: PS1='(\[$(tput md)\]\t <\w>\[$(tput me)\]) $(echo $?) \$ ' 206 -- Mathieu <mathieu@hal.interactionvirtuelle.com> 207% 208To see the output from when your computer started, run dmesg(8). If it has 209been replaced with other messages, look at /var/run/dmesg.boot. 210 -- Francisco Reyes <lists@natserv.com> 211% 212You can use "whereis" to locate standard binary, manual page and source 213directories for the specified programs. This can be particularly handy 214when you are trying to find where in the ports tree an application is. 215 216Try "whereis netscape" and "whereis whereis". 217 -- Konstantinos Konstantinidis <kkonstan@duth.gr> 218% 219You can press Ctrl-D to quickly exit from a shell, or logout from a 220login shell. 221 -- Konstantinos Konstantinidis <kkonstan@duth.gr> 222% 223You can use "pkg_info" to see a list of packages you have installed. 224 -- Konstantinos Konstantinidis <kkonstan@duth.gr> 225% 226You can change the video mode on all consoles by adding something like 227the following to /etc/rc.conf: 228 229 allscreens="80x30" 230 231You can use "vidcontrol -i mode | grep T" for a list of supported text 232modes. 233 -- Konstantinos Konstantinidis <kkonstan@duth.gr> 234% 235Any user that is a member of the wheel group can use "su -" to simulate 236a root login. You can add a user to the wheel group by editing /etc/group. 237 -- Konstantinos Konstantinidis <kkonstan@duth.gr> 238% 239Over quota? "du -s * | sort -n " will give you a sorted list of your 240directory sizes. 241 -- David Scheidt <dscheidt@tumbolia.com> 242% 243Handy bash(1) prompt: PS1="\u@\h \w \!$ " 244 -- David Scheidt <dscheidt@tumbolia.com> 245% 246Ever wonder what those numbers after command names were, as in cat(1)? It's 247the section of the manual the man page is in. "man man" will tell you more. 248 -- David Scheidt <dscheidt@tumbolia.com> 249% 250"man hier" will explain the way FreeBSD filesystems are normally laid out. 251 -- David Scheidt <dscheidt@tumbolia.com> 252% 253"man tuning" gives some tips how to tune performance of your FreeBSD system. 254 -- David Scheidt <dscheidt@tumbolia.com> 255% 256"man firewall" will give advice for building a FreeBSD firewall 257 -- David Scheidt <dscheidt@tumbolia.com> 258% 259You can often get answers to your questions about FreeBSD by searching in the 260FreeBSD mailing list archives at 261 262 http://www.freebsd.org/search.html 263% 264You can adjust the volume of various parts of the sound system in your 265computer by typing 'mixer <type> <volume>'. To get a list of what you can 266adjust, just type 'mixer'. 267% 268You can automatically download and install binary packages by doing 269 270 pkg_add -r <URL> 271 272where you replace <URL> with the URL to the package. This will also 273automatically install the packages the package you download is dependent on 274(ie, the packages it needs in order to work.) 275% 276You can get a good standard workstation install by using the 277instant-workstation port/package. If you have ports installed, you can 278install it by doing 279 280 # cd /usr/ports/misc/instant-workstation 281 # make install && make clean 282 283as root. This will install a collection of packages that is convenient to 284have on a workstation. 285% 286You can get a good generic server install by using the 287instant-server port/package. If you have ports installed, you can 288install it by doing 289 290 # cd /usr/ports/misc/instant-server 291 # make install && make clean 292 293as root. This will install a collection of packages that is appropriate for 294running a "generic" server. 295% 296You can make a log of your terminal session with script(1). 297% 298"man ports" gives many useful hints about installing FreeBSD ports. 299% 300ports/net/netcat port is useful not only for redirecting input/output 301to TCP or UDP connections, but also for proxying them. See inetd(8) for 302details. 303% 304If other operating systems have damaged your Master Boot Record, you can 305reinstall it either with /stand/sysinstall or with boot0cfg(8). See 306"man boot0cfg" for details. 307% 308Need to see the calendar for this month? Simply type "cal". To see the 309whole year, type "cal 2001". 310 -- Dru <genesis@istar.ca> 311% 312Need to quickly return to your home directory? Type "cd". 313 -- Dru <genesis@istar.ca> 314% 315To see the last time that you logged in, use lastlogin(8). 316 -- Dru <genesis@istar.ca> 317% 318To clear the screen, use "clear". To re-display your screen buffer, press 319the scroll lock key and use your page up button. When you're finished, 320press the scroll lock key again to get your prompt back. 321 -- Dru <genesis@istar.ca> 322% 323To save disk space in your home directory, can compress files you 324rarely use with "gzip filename". 325 -- Dru <genesis@istar.ca> 326% 327To read a compressed file without having to first uncompress it, use 328"zcat" or "zmore" to view it. 329 -- Dru <genesis@istar.ca> 330% 331To see how much disk space is left on your partitions, use 332 333 df -h 334 -- Dru <genesis@istar.ca> 335% 336To see the 10 largest files on a directory or partition, use 337 338 du /partition_or_directory_name | sort -rn | head 339 -- Dru <genesis@istar.ca> 340% 341To determine whether a file is a text file, executable, or some other type 342of file, use 343 344 file filename 345 -- Dru <genesis@istar.ca> 346% 347Time to change your password? Type "passwd" and follow the prompts. 348 -- Dru <genesis@istar.ca> 349% 350Want to know how many words, lines, or bytes are contained in a file? Type 351"wc filename". 352 -- Dru <genesis@istar.ca> 353% 354Need to print a manpage? Use 355 356 man name_of_manpage | col -bx | lpr 357 -- Dru <genesis@istar.ca> 358% 359Need to remove all those ^M characters from a DOS file? Try 360 361 col -bx < dosfile > newfile 362 -- Dru <genesis@istar.ca> 363% 364Forget what directory you are in? Type "pwd". 365 -- Dru <genesis@istar.ca> 366% 367If you are in the C shell and have just installed a new program, you won't 368be able to run it unless you first type "rehash". 369 -- Dru <genesis@istar.ca> 370% 371Need to leave your terminal for a few minutes and don't want to logout? 372Use "lock -p". When you return, use your password as the key to unlock the 373terminal. 374 -- Dru <genesis@istar.ca> 375% 376Need to find the location of a program? Use "locate program_name". 377 -- Dru <genesis@istar.ca> 378% 379Forget how to spell a word or a variation of a word? Use 380 381 look portion_of_word_you_know 382 -- Dru <genesis@istar.ca> 383% 384To see the last 10 lines of a long file, use "tail filename". To see the 385first 10 lines, use "head filename". 386 -- Dru <genesis@istar.ca> 387% 388To see how long it takes a command to run, type the word "time" before the 389command name. 390 -- Dru <genesis@istar.ca> 391% 392To quickly create an empty file, use "touch filename". 393 -- Dru <genesis@istar.ca> 394% 395To find out the hostname associated with an IP address, use 396 397 dig -x IP_address 398 -- Dru <genesis@istar.ca> 399% 400If you use the C shell, add the following line to the .cshrc file in your 401home directory to prevent core files from being written to disk: 402 403 limit coredumpsize 0 404 -- Dru <genesis@istar.ca> 405% 406If you need a reminder to leave your terminal, type "leave hhmm" where 407"hhmm" represents in how many hours and minutes you need to leave. 408 -- Dru <genesis@istar.ca> 409% 410Need to do a search in a manpage or in a file you've sent to a pager? Use 411"/search_word". To repeat the same search, type "n" for next. 412 -- Dru <genesis@istar.ca> 413% 414Forget when Easter is? Try "ncal -e". If you need the date for Orthodox 415Easter, use "ncal -o" instead. 416 -- Dru <genesis@istar.ca> 417% 418Need to see your routing table? Type "netstat -rn". The entry with the G 419flag is your gateway. 420 -- Dru <genesis@istar.ca> 421% 422Need to see which daemons are listening for connection requests? Use 423"sockstat -4l" for IPv4, and "sockstat -l" for IPv4 and IPv6. 424 -- Dru <genesis@istar.ca> 425% 426Can't remember is you've installed a certain port or not? Try "pkg_info | 427grep port_name". 428 -- Dru <genesis@istar.ca> 429% 430Got some time to kill? Try typing "hangman". 431 -- Dru <genesis@istar.ca> 432% 433To erase a line you've written at the command prompt, use "Ctrl u". 434 -- Dru <genesis@istar.ca> 435% 436To repeat the last command in the C shell, type "!!". 437 -- Dru <genesis@istar.ca> 438% 439Need to quickly empty a file? Use "echo > filename". 440 -- Dru <genesis@istar.ca> 441% 442To see all of the directories on your FreeBSD system, type 443 444 ls -R / | more 445 -- Dru <genesis@istar.ca> 446% 447To see the IP addresses currently set on your active interfaces, type 448"ifconfig -u". 449 -- Dru <genesis@istar.ca> 450% 451To see the MAC addresses of the NICs on your system, type 452 453 ifconfig -a 454 -- Dru <genesis@istar.ca> 455% 456You can save your kernel startup configuration with kget(8). The 457Configuration can be edited at boot time with 'boot -c' command in loader. 458See boot(8), loader(8) for details. 459% 460You can open up a new split-screen window in (n)vi with :N or :E and then 461use ^w to switch between the two. 462% 463sh (the default bourne shell in FreeBSD) supports command-line editing. Just 464``set -o emacs'' or ``set -o vi'' to enable it. 465% 466When you've made modifications to a file in vi(1) and then find that 467you can't write it, type ``<ESC>!rm -f %'' then ``:w!'' to force the 468write 469 470This won't work if you don't have write permissions to the directory 471and probably won't be suitable if you're editing through a symbolic link. 472