freebsd-tips revision 241934
190716SbdeThis fortune brought to you by: 21541Srgrimes$FreeBSD: head/games/fortune/datfiles/freebsd-tips 241934 2012-10-23 15:03:25Z eadler $ 31541Srgrimes% 41541SrgrimesAny user that is a member of the wheel group can use "su -" to simulate 51541Srgrimesa root login. You can add a user to the wheel group by editing /etc/group. 61541Srgrimes -- Konstantinos Konstantinidis <kkonstan@duth.gr> 71541Srgrimes% 81541SrgrimesBy pressing "Scroll Lock" you can use the arrow keys to scroll backward 91541Srgrimesthrough the console output. Press "Scroll Lock" again to turn it off. 101541Srgrimes% 111541SrgrimesCan't remember if you've installed a certain port or not? Try "pkg_info 121541Srgrimes-Ix port_name". 131541Srgrimes% 141541SrgrimesEver wonder what those numbers after command names were, as in cat(1)? It's 151541Srgrimesthe section of the manual the man page is in. "man man" will tell you more. 161541Srgrimes -- David Scheidt <dscheidt@tumbolia.com> 171541Srgrimes% 181541SrgrimesForget how to spell a word or a variation of a word? Use 191541Srgrimes 201541Srgrimes look portion_of_word_you_know 211541Srgrimes -- Dru <genesis@istar.ca> 221541Srgrimes% 231541SrgrimesForget what directory you are in? Type "pwd". 241541Srgrimes -- Dru <genesis@istar.ca> 251541Srgrimes% 261541SrgrimesForget when Easter is? Try "ncal -e". If you need the date for Orthodox 271541SrgrimesEaster, use "ncal -o" instead. 281541Srgrimes -- Dru <genesis@istar.ca> 291541Srgrimes% 301541SrgrimesFreeBSD is started up by the program 'init'. The first thing init does when 311541Srgrimesstarting multiuser mode (ie, starting the computer up for normal use) is to 321541Srgrimesrun the shell script /etc/rc. By reading /etc/rc and the /etc/rc.d/ scripts, 3322521Sdysonyou can learn a lot about how the system is put together, which again will 341541Srgrimesmake you more confident about what happens when you do something with it. 3522521Sdyson% 3690716SbdeHandy bash(1) prompt: PS1="\u@\h \w \!$ " 3750477Speter -- David Scheidt <dscheidt@tumbolia.com> 381541Srgrimes% 391541SrgrimesHaving trouble using fetch through a firewall? Try setting the environment 40147692Spetervariable FTP_PASSIVE_MODE to yes, and see fetch(3) for more details. 41147692Speter% 421541SrgrimesIf other operating systems have damaged your Master Boot Record, you can 4376166Smarkmreinstall it with boot0cfg(8). See 4476166Smarkm"man boot0cfg" for details. 4576166Smarkm% 461541SrgrimesIf you accidentally end up inside vi, you can quit it by pressing Escape, colon 4784637Sdes(:), q (q), bang (!) and pressing return. 4887321Sdes% 4976166SmarkmIf you are in the C shell and have just installed a new program, you won't 501541Srgrimesbe able to run it unless you first type "rehash". 5176166Smarkm -- Dru <genesis@istar.ca> 5287321Sdes% 5377031SruIf you do not want to get beeps in X11 (X Windows), you can turn them off with 5476166Smarkm 55147692Speter xset b off 56147692Speter% 57147692SpeterIf you have a CD-ROM drive in your machine, you can make the CD-ROM that is 58147692Speterpresently inserted available by typing 'mount /cdrom' as root. The CD-ROM 59147692Speterwill be available under /cdrom/. Remember to do 'umount /cdrom' before 60147692Speterremoving the CD-ROM (it will usually not be possible to remove the CD-ROM 61147692Speterwithout doing this.) 62147692Speter 63147692SpeterNote: This tip may not work in all configurations. 64147692Speter% 65147692SpeterIf you need a reminder to leave your terminal, type "leave +hhmm" where 66147692Speter"hhmm" represents in how many hours and minutes you need to leave. 67147692Speter -- Dru <genesis@istar.ca> 68147692Speter% 69147692SpeterIf you need to ask a question on the FreeBSD-questions mailing list then 70147692Speter 71147692Speter http://www.FreeBSD.org/doc/en_US.ISO8859-1/articles/\ 72147692Speter freebsd-questions/index.html 73147692Speter 74147692Spetercontains lots of useful advice to help you get the best results. 75147692Speter% 76147692SpeterIf you write part of a filename in tcsh, 77147692Speterpressing TAB will show you the available choices when there 78147692Speteris more than one, or complete the filename if there's only one match. 79147692Speter% 80147692SpeterIf you `set watch = (0 any any)' in tcsh, you will be notified when 811541Srgrimessomeone logs in or out of your system. 8287321Sdes% 831541SrgrimesIf you use the C shell, add the following line to the .cshrc file in your 841541Srgrimeshome directory to prevent core files from being written to disk: 851541Srgrimes 86147692Speter limit coredumpsize 0 87147692Speter -- Dru <genesis@istar.ca> 88147692Speter% 89147692SpeterIf you want df(1) and other commands to display disk sizes in 90147692Speterkilobytes instead of 512-byte blocks, set BLOCKSIZE in your 911541Srgrimesenvironment to 'K'. You can also use 'M' for Megabytes or 'G' for 92168759SdesGigabytes. If you want df(1) to automatically select the best size 93168759Sdesthen use 'df -h'. 94168759Sdes% 9594622SjhbIf you want to play CDs with FreeBSD, a utility for this is already included. 96136004SdasType 'cdcontrol' then 'help' to learn more. (You may need to set the CDROM 9796886Sjhbenvironment variable in order to make cdcontrol want to start.) 9894622Sjhb% 9990716SbdeIf you want to quickly check for duplicate package/port installations, 10094622Sjhbtry the following pkg_info command. 1011541Srgrimes 102120665Snectar pkg_info | sort | sed -e 's/-[0-9].*$//' | \ 103147692Speter uniq -c | grep -v '^[[:space:]]*1' 104147692Speter% 105147692SpeterIf you'd like to keep track of applications in the FreeBSD ports tree, take a 106147692Speterlook at FreshPorts; 107147692Speter 108147692Speter http://www.freshports.org/ 109147692Speter% 110147692SpeterIn order to make fetch (the FreeBSD downloading tool) ask for 111147692Speterusername/password when it encounters a password-protected web page, you can set 112147692Speterthe environment variable HTTP_AUTH to 'basic:*'. 113147692Speter% 114114734SrwatsonIn order to search for a string in some files, use 'grep' like this: 115114734Srwatson 116147692Speter grep "string" filename1 [filename2 filename3 ...] 117114734Srwatson 118114734SrwatsonThis will print out the lines in the files that contain the string. grep can 1191541Srgrimesalso do a lot more advanced searches - type 'man grep' for details. 12099072Sjulian% 1211541SrgrimesIn order to support national characters for European languages in tools like 1221541Srgrimesless without creating other nationalisation aspects, set the environment 12390716Sbdevariable LC_ALL to 'en_US.ISO8859-1'. 124147692Speter% 1251541Srgrimes"man firewall" will give advice for building a FreeBSD firewall 12694622Sjhb -- David Scheidt <dscheidt@tumbolia.com> 1271541Srgrimes% 1281541Srgrimes"man hier" will explain the way FreeBSD filesystems are normally laid out. 1291541Srgrimes -- David Scheidt <dscheidt@tumbolia.com> 130% 131Man pages are divided into section depending on topic. There are 9 different 132sections numbered from 1 (General Commands) to 9 (Kernel Developer's Manual). 133You can get an introduction to each topic by typing 134 135 man <number> intro 136 137In other words, to get the intro to general commands, type 138 139 man 1 intro 140% 141"man ports" gives many useful hints about installing FreeBSD ports. 142% 143"man security" gives very good advice on how to tune the security of your 144FreeBSD system. 145% 146"man tuning" gives some tips how to tune performance of your FreeBSD system. 147 -- David Scheidt <dscheidt@tumbolia.com> 148% 149Need to do a search in a manpage or in a file you've sent to a pager? Use 150"/search_word". To repeat the same search, type "n" for next. 151 -- Dru <genesis@istar.ca> 152% 153Need to find the location of a program? Use "locate program_name". 154 -- Dru <genesis@istar.ca> 155% 156Need to leave your terminal for a few minutes and don't want to logout? 157Use "lock -p". When you return, use your password as the key to unlock the 158terminal. 159 -- Dru <genesis@istar.ca> 160% 161Need to print a manpage? Use 162 163 man name_of_manpage | col -bx | lpr 164 -- Dru <genesis@istar.ca> 165% 166Need to quickly empty a file? Use ": > filename". 167 -- Dru <genesis@istar.ca> 168% 169Need to quickly return to your home directory? Type "cd". 170 -- Dru <genesis@istar.ca> 171% 172Need to remove all those ^M characters from a DOS file? Try 173 174 tr -d \\r < dosfile > newfile 175 -- Originally by Dru <genesis@istar.ca> 176% 177Need to see the calendar for this month? Simply type "cal". To see the 178whole year, type "cal -y". 179 -- Dru <genesis@istar.ca> 180% 181Need to see which daemons are listening for connection requests? Use 182"sockstat -4l" for IPv4, and "sockstat -l" for IPv4 and IPv6. 183 -- Dru <genesis@istar.ca> 184% 185Need to see your routing table? Type "netstat -rn". The entry with the G 186flag is your gateway. 187 -- Dru <genesis@istar.ca> 188% 189Nice bash prompt: PS1='(\[$(tput md)\]\t <\w>\[$(tput me)\]) $(echo $?) \$ ' 190 -- Mathieu <mathieu@hal.interactionvirtuelle.com> 191% 192Over quota? "du -s * | sort -n " will give you a sorted list of your 193directory sizes. 194 -- David Scheidt <dscheidt@tumbolia.com> 195% 196nc(1) (or netcat) is useful not only for redirecting input/output to 197TCP or UDP connections, but also for proxying them with inetd(8). 198% 199sh (the default Bourne shell in FreeBSD) supports command-line editing. Just 200``set -o emacs'' or ``set -o vi'' to enable it. 201% 202Simple tcsh prompt: set prompt = '%# ' 203% 204The default editor in FreeBSD is vi, which is efficient to use when you have 205learned it, but somewhat user-unfriendly. To use ee (an easier but less 206powerful editor) instead, set the environment variable EDITOR to /usr/bin/ee 207% 208Time to change your password? Type "passwd" and follow the prompts. 209 -- Dru <genesis@istar.ca> 210% 211To change an environment variable in /bin/sh use: 212 213 $ VARIABLE="value" 214 $ export VARIABLE 215% 216To change an environment variable in tcsh you use: setenv NAME "value" 217where NAME is the name of the variable and "value" its new value. 218% 219To clear the screen, use "clear". To re-display your screen buffer, press 220the scroll lock key and use your page up button. When you're finished, 221press the scroll lock key again to get your prompt back. 222 -- Dru <genesis@istar.ca> 223% 224To determine whether a file is a text file, executable, or some other type 225of file, use 226 227 file filename 228 -- Dru <genesis@istar.ca> 229% 230To do a fast search for a file, try 231 232 locate filename 233 234locate uses a database that is updated every Saturday (assuming your computer 235is running FreeBSD at the time) to quickly find files based on name only. 236% 237To erase a line you've written at the command prompt, use "Ctrl-U". 238 -- Dru <genesis@istar.ca> 239% 240To find out the hostname associated with an IP address, use 241 242 dig -x IP_address 243 -- Dru <genesis@istar.ca> 244% 245To obtain a neat PostScript rendering of a manual page, use ``-t'' switch 246of the man(1) utility: ``man -t <topic>''. For example: 247 248 man -t grep > grep.ps # Save the PostScript version to a file 249or 250 man -t printf | lp # Send the PostScript directly to printer 251% 252To quickly create an empty file, use "touch filename". 253 -- Dru <genesis@istar.ca> 254% 255To read a compressed file without having to first uncompress it, use 256"zcat" or "zless" to view it. 257 -- Dru <genesis@istar.ca> 258% 259To repeat the last command in the C shell, type "!!". 260 -- Dru <genesis@istar.ca> 261% 262To save disk space in your home directory, compress files you rarely 263use with "gzip filename". 264 -- Dru <genesis@istar.ca> 265% 266To search for files that match a particular name, use find(1); for example 267 268 find / -name "*GENERIC*" -ls 269 270will search '/', and all subdirectories, for files with 'GENERIC' in the name. 271 -- Stephen Hilton <nospam@hiltonbsd.com> 272% 273To see all of the directories on your FreeBSD system, type 274 275 find / -type d | less 276 277All the files? 278 279 find / -type f | less 280% 281To see how long it takes a command to run, type the word "time" before the 282command name. 283 -- Dru <genesis@istar.ca> 284% 285To see how much disk space is left on your partitions, use 286 287 df -h 288 -- Dru <genesis@istar.ca> 289% 290To see the 10 largest files on a directory or partition, use 291 292 du /partition_or_directory_name | sort -rn | head 293 -- Dru <genesis@istar.ca> 294% 295To see the IP addresses currently set on your active interfaces, type 296"ifconfig -u". 297 -- Dru <genesis@istar.ca> 298% 299To see the last 10 lines of a long file, use "tail filename". To see the 300first 10 lines, use "head filename". 301 -- Dru <genesis@istar.ca> 302% 303To see the last time that you logged in, use lastlogin(8). 304 -- Dru <genesis@istar.ca> 305% 306To see the MAC addresses of the NICs on your system, type 307 308 ifconfig -a 309 -- Dru <genesis@istar.ca> 310% 311To see the output from when your computer started, run dmesg(8). If it has 312been replaced with other messages, look at /var/run/dmesg.boot. 313 -- Francisco Reyes <lists@natserv.com> 314% 315Want colour in your directory listings? Use "ls -G". "ls -F" is also useful, 316and they can be combined as "ls -FG". 317% 318Want to find a specific port, just type the following under /usr/ports 319or one its subdirectories: 320 321 make search name=<port-name> 322 or 323 make search key=<keyword> 324% 325Want to know how many words, lines, or bytes are contained in a file? Type 326"wc filename". 327 -- Dru <genesis@istar.ca> 328% 329Want to see how much virtual memory you're using? Just type "swapinfo" to 330be shown information about the usage of your swap partitions. 331% 332Want to strip UTF-8 BOM(Byte Order Mark) from given files? 333 334 sed -e '1s/^\xef\xbb\xbf//' < bomfile > newfile 335% 336Want to use sed(1) to edit a file in place? Well, to replace every 'e' with 337an 'o', in a file named 'foo', you can do: 338 339 sed -i.bak s/e/o/g foo 340 341And you'll get a backup of the original in a file named 'foo.bak', but if you 342want no backup: 343 344 sed -i '' s/e/o/g foo 345% 346When you've made modifications to a file in vi(1) and then find that 347you can't write it, type ``<ESC>!rm -f %'' then ``:w!'' to force the 348write 349 350This won't work if you don't have write permissions to the directory 351and probably won't be suitable if you're editing through a symbolic link. 352% 353You can adjust the volume of various parts of the sound system in your 354computer by typing 'mixer <type> <volume>'. To get a list of what you can 355adjust, just type 'mixer'. 356% 357You can automatically download and install binary packages by doing 358 359 pkg_add -r <URL> 360 361where you replace <URL> with the URL to the package. This will also 362automatically install the packages the package you download is dependent on 363(ie, the packages it needs in order to work.) 364% 365You can change the video mode on all consoles by adding something like 366the following to /etc/rc.conf: 367 368 allscreens="80x30" 369 370You can use "vidcontrol -i mode | grep T" for a list of supported text 371modes. 372 -- Konstantinos Konstantinidis <kkonstan@duth.gr> 373% 374You can disable tcsh's terminal beep if you `set nobeep'. 375% 376You can get a good generic server install by using the 377instant-server port/package. If you have ports installed, you can 378install it by doing 379 380 # cd /usr/ports/misc/instant-server 381 # make install && make clean 382 383as root. This will install a collection of packages that is appropriate for 384running a "generic" server. 385% 386You can install extra packages for FreeBSD by using the ports system. 387If you have installed it, you can download, compile, and install software by 388just typing 389 390 # cd /usr/ports/<category>/<portname> 391 # make install && make clean 392 393as root. The ports infrastructure will download the software, change it so 394it works on FreeBSD, compile it, install it, register the installation so it 395will be possible to automatically uninstall it, and clean out the temporary 396working space it used. You can remove an installed port you decide you do not 397want after all by typing 398 399 # cd /usr/ports/<category>/<portname> 400 # make deinstall 401 402as root. 403% 404You can look through a file in a nice text-based interface by typing 405 406 less filename 407% 408You can make a log of your terminal session with script(1). 409% 410You can often get answers to your questions about FreeBSD by searching in the 411FreeBSD mailing list archives at 412 413 http://www.FreeBSD.org/search/search.html 414% 415You can open up a new split-screen window in (n)vi with :N or :E and then 416use ^w to switch between the two. 417% 418You can permanently set environment variables for your shell by putting them 419in a startup file for the shell. The name of the startup file varies 420depending on the shell - csh and tcsh uses .login, bash, sh, ksh and zsh use 421.profile. When using bash, sh, ksh or zsh, don't forget to export the 422variable. 423% 424You can press Ctrl-D to quickly exit from a shell, or logout from a 425login shell. 426 -- Konstantinos Konstantinidis <kkonstan@duth.gr> 427% 428You can press Ctrl-L while in the shell to clear the screen. 429% 430You can press up-arrow or down-arrow to walk through a list of 431previous commands in tcsh. 432% 433You can search for documentation on a keyword by typing 434 435 apropos keyword 436% 437You can `set autologout = 30' to have tcsh log you off automatically 438if you leave the shell idle for more than 30 minutes. 439% 440You can use aliases to decrease the amount of typing you need to do to get 441commands you commonly use. Examples of fairly popular aliases include (in 442Bourne shell style, as in /bin/sh, bash, ksh, and zsh): 443 444 alias lf="ls -FA" 445 alias ll="ls -lA" 446 alias su="su -m" 447 448In csh or tcsh, these would be 449 450 alias lf ls -FA 451 alias ll ls -lA 452 alias su su -m 453 454To remove an alias, you can usually use 'unalias aliasname'. To list all 455aliases, you can usually type just 'alias'. 456% 457You can use /etc/make.conf to control the options used to compile software 458on this system. Example entries are in 459/usr/share/examples/etc/make.conf. 460% 461You can use "pkg_info" to see a list of packages you have installed. 462 -- Konstantinos Konstantinidis <kkonstan@duth.gr> 463% 464You can use the 'fetch' command to retrieve files over ftp or http. 465 466 fetch http://www.FreeBSD.org/index.html 467 468will download the front page of the FreeBSD web site. 469% 470You can use "whereis" to search standard binary, manual page and source 471directories for the specified programs. This can be particularly handy 472when you are trying to find where in the ports tree an application is. 473 474Try "whereis firefox" and "whereis whereis". 475 -- Konstantinos Konstantinidis <kkonstan@duth.gr> 476% 477Want to run the same command again? 478In tcsh you can type "!!" 479% 480Want to go the directory you were just in? 481Type "cd -" 482% 483