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