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