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