178266SnikThis fortune brought to you by: 278266Snik$FreeBSD: releng/11.0/usr.bin/fortune/datfiles/freebsd-tips 287582 2015-09-08 22:51:10Z allanjude $ 378266Snik% 4174425SdougbAny user that is a member of the wheel group can use "su -" to simulate 5174425Sdougba root login. You can add a user to the wheel group by editing /etc/group. 6174425Sdougb -- Konstantinos Konstantinidis <kkonstan@duth.gr> 778266Snik% 878266SnikBy pressing "Scroll Lock" you can use the arrow keys to scroll backward 978266Snikthrough the console output. Press "Scroll Lock" again to turn it off. 1078266Snik% 11256019SglebiusCan't remember if you've installed a certain port or not? Try "pkg info 12256019Sglebius-x port_name". 1378266Snik% 14174425SdougbEver wonder what those numbers after command names were, as in cat(1)? It's 15174425Sdougbthe section of the manual the man page is in. "man man" will tell you more. 16174425Sdougb -- David Scheidt <dscheidt@tumbolia.com> 1778266Snik% 18174425SdougbForget how to spell a word or a variation of a word? Use 1978266Snik 20174425Sdougb look portion_of_word_you_know 21174425Sdougb -- Dru <genesis@istar.ca> 2278266Snik% 23174425SdougbForget what directory you are in? Type "pwd". 24174425Sdougb -- Dru <genesis@istar.ca> 2578266Snik% 26174425SdougbForget when Easter is? Try "ncal -e". If you need the date for Orthodox 27174425SdougbEaster, use "ncal -o" instead. 28174425Sdougb -- Dru <genesis@istar.ca> 2978266Snik% 30174425SdougbFreeBSD is started up by the program 'init'. The first thing init does when 31174425Sdougbstarting multiuser mode (ie, starting the computer up for normal use) is to 32174425Sdougbrun the shell script /etc/rc. By reading /etc/rc and the /etc/rc.d/ scripts, 33174425Sdougbyou can learn a lot about how the system is put together, which again will 34174425Sdougbmake you more confident about what happens when you do something with it. 3578266Snik% 36174425SdougbHandy bash(1) prompt: PS1="\u@\h \w \!$ " 37174425Sdougb -- David Scheidt <dscheidt@tumbolia.com> 3878266Snik% 39174425SdougbHaving trouble using fetch through a firewall? Try setting the environment 40174425Sdougbvariable FTP_PASSIVE_MODE to yes, and see fetch(3) for more details. 4178266Snik% 42174425SdougbIf other operating systems have damaged your Master Boot Record, you can 43241934Seadlerreinstall it with boot0cfg(8). See 44174425Sdougb"man boot0cfg" for details. 4578266Snik% 46174425SdougbIf you accidentally end up inside vi, you can quit it by pressing Escape, colon 47174425Sdougb(:), q (q), bang (!) and pressing return. 4878266Snik% 49174425SdougbIf you are in the C shell and have just installed a new program, you won't 50174425Sdougbbe able to run it unless you first type "rehash". 51174425Sdougb -- Dru <genesis@istar.ca> 5278266Snik% 5378266SnikIf you do not want to get beeps in X11 (X Windows), you can turn them off with 5478266Snik 5578266Snik xset b off 5678266Snik% 57174425SdougbIf you have a CD-ROM drive in your machine, you can make the CD-ROM that is 58174425Sdougbpresently inserted available by typing 'mount /cdrom' as root. The CD-ROM 59174425Sdougbwill be available under /cdrom/. Remember to do 'umount /cdrom' before 60174425Sdougbremoving the CD-ROM (it will usually not be possible to remove the CD-ROM 61174425Sdougbwithout doing this.) 6278266Snik 63174425SdougbNote: This tip may not work in all configurations. 6478266Snik% 65174425SdougbIf you need a reminder to leave your terminal, type "leave +hhmm" where 66174425Sdougb"hhmm" represents in how many hours and minutes you need to leave. 67174425Sdougb -- Dru <genesis@istar.ca> 6878266Snik% 69174425SdougbIf you need to ask a question on the FreeBSD-questions mailing list then 7078266Snik 71174425Sdougb http://www.FreeBSD.org/doc/en_US.ISO8859-1/articles/\ 72174425Sdougb freebsd-questions/index.html 7378266Snik 74174425Sdougbcontains lots of useful advice to help you get the best results. 7578266Snik% 76235227SeadlerIf you write part of a filename in tcsh, 77235209Seadlerpressing TAB will show you the available choices when there 78174425Sdougbis more than one, or complete the filename if there's only one match. 7978266Snik% 80174425SdougbIf you `set watch = (0 any any)' in tcsh, you will be notified when 81174425Sdougbsomeone logs in or out of your system. 8278266Snik% 83174425SdougbIf you use the C shell, add the following line to the .cshrc file in your 84174425Sdougbhome directory to prevent core files from being written to disk: 8578266Snik 86174425Sdougb limit coredumpsize 0 87174425Sdougb -- Dru <genesis@istar.ca> 8878266Snik% 89174425SdougbIf you want df(1) and other commands to display disk sizes in 90174425Sdougbkilobytes instead of 512-byte blocks, set BLOCKSIZE in your 91174425Sdougbenvironment to 'K'. You can also use 'M' for Megabytes or 'G' for 92174425SdougbGigabytes. If you want df(1) to automatically select the best size 93174425Sdougbthen use 'df -h'. 9478266Snik% 9578266SnikIf you want to play CDs with FreeBSD, a utility for this is already included. 9678266SnikType 'cdcontrol' then 'help' to learn more. (You may need to set the CDROM 9778266Snikenvironment variable in order to make cdcontrol want to start.) 9878266Snik% 99174425SdougbIf you'd like to keep track of applications in the FreeBSD ports tree, take a 100174425Sdougblook at FreshPorts; 10178266Snik 102174425Sdougb http://www.freshports.org/ 103174425Sdougb% 104174425SdougbIn order to make fetch (the FreeBSD downloading tool) ask for 105174425Sdougbusername/password when it encounters a password-protected web page, you can set 106174425Sdougbthe environment variable HTTP_AUTH to 'basic:*'. 107174425Sdougb% 108174425SdougbIn order to search for a string in some files, use 'grep' like this: 10978266Snik 110174425Sdougb grep "string" filename1 [filename2 filename3 ...] 11178266Snik 112174425SdougbThis will print out the lines in the files that contain the string. grep can 113174425Sdougbalso do a lot more advanced searches - type 'man grep' for details. 11478266Snik% 115174425SdougbIn order to support national characters for European languages in tools like 116174425Sdougbless without creating other nationalisation aspects, set the environment 117174425Sdougbvariable LC_ALL to 'en_US.ISO8859-1'. 11878266Snik% 119174425Sdougb"man firewall" will give advice for building a FreeBSD firewall 120174425Sdougb -- David Scheidt <dscheidt@tumbolia.com> 12178266Snik% 122174425Sdougb"man hier" will explain the way FreeBSD filesystems are normally laid out. 123174425Sdougb -- David Scheidt <dscheidt@tumbolia.com> 12478266Snik% 125174425SdougbMan pages are divided into section depending on topic. There are 9 different 126174425Sdougbsections numbered from 1 (General Commands) to 9 (Kernel Developer's Manual). 127174425SdougbYou can get an introduction to each topic by typing 12878266Snik 129174425Sdougb man <number> intro 13078266Snik 131174425SdougbIn other words, to get the intro to general commands, type 132174425Sdougb 133174425Sdougb man 1 intro 13478266Snik% 135174425Sdougb"man ports" gives many useful hints about installing FreeBSD ports. 13678271Snik% 137174425Sdougb"man security" gives very good advice on how to tune the security of your 138174425SdougbFreeBSD system. 13978271Snik% 140174425Sdougb"man tuning" gives some tips how to tune performance of your FreeBSD system. 14178271Snik -- David Scheidt <dscheidt@tumbolia.com> 14278271Snik% 143174425SdougbNeed to do a search in a manpage or in a file you've sent to a pager? Use 144174425Sdougb"/search_word". To repeat the same search, type "n" for next. 145174425Sdougb -- Dru <genesis@istar.ca> 14678271Snik% 147174425SdougbNeed to find the location of a program? Use "locate program_name". 148174425Sdougb -- Dru <genesis@istar.ca> 14978271Snik% 150174425SdougbNeed to leave your terminal for a few minutes and don't want to logout? 151174425SdougbUse "lock -p". When you return, use your password as the key to unlock the 152174425Sdougbterminal. 153174425Sdougb -- Dru <genesis@istar.ca> 15478271Snik% 155174425SdougbNeed to print a manpage? Use 15678283Seivind 157174425Sdougb man name_of_manpage | col -bx | lpr 158174425Sdougb -- Dru <genesis@istar.ca> 15978283Seivind% 160174425SdougbNeed to quickly empty a file? Use ": > filename". 161174425Sdougb -- Dru <genesis@istar.ca> 16278283Seivind% 163174425SdougbNeed to quickly return to your home directory? Type "cd". 164174425Sdougb -- Dru <genesis@istar.ca> 16578283Seivind% 166174425SdougbNeed to remove all those ^M characters from a DOS file? Try 16778283Seivind 168174425Sdougb tr -d \\r < dosfile > newfile 169174425Sdougb -- Originally by Dru <genesis@istar.ca> 17078283Seivind% 171174425SdougbNeed to see the calendar for this month? Simply type "cal". To see the 172174425Sdougbwhole year, type "cal -y". 173174425Sdougb -- Dru <genesis@istar.ca> 17481558Smharo% 175174425SdougbNeed to see which daemons are listening for connection requests? Use 176174425Sdougb"sockstat -4l" for IPv4, and "sockstat -l" for IPv4 and IPv6. 177174425Sdougb -- Dru <genesis@istar.ca> 17881558Smharo% 179174425SdougbNeed to see your routing table? Type "netstat -rn". The entry with the G 180174425Sdougbflag is your gateway. 181174425Sdougb -- Dru <genesis@istar.ca> 18281558Smharo% 183174425SdougbNice bash prompt: PS1='(\[$(tput md)\]\t <\w>\[$(tput me)\]) $(echo $?) \$ ' 184174425Sdougb -- Mathieu <mathieu@hal.interactionvirtuelle.com> 18593518Sjoe% 186174425SdougbOver quota? "du -s * | sort -n " will give you a sorted list of your 187174425Sdougbdirectory sizes. 188174425Sdougb -- David Scheidt <dscheidt@tumbolia.com> 189174425Sdougb% 190187110Ssimonnc(1) (or netcat) is useful not only for redirecting input/output to 191187110SsimonTCP or UDP connections, but also for proxying them with inetd(8). 19281558Smharo% 193174425Sdougbsh (the default Bourne shell in FreeBSD) supports command-line editing. Just 194174425Sdougb``set -o emacs'' or ``set -o vi'' to enable it. 19581558Smharo% 196174425SdougbSimple tcsh prompt: set prompt = '%# ' 19781558Smharo% 198174425SdougbThe default editor in FreeBSD is vi, which is efficient to use when you have 199174425Sdougblearned it, but somewhat user-unfriendly. To use ee (an easier but less 200174425Sdougbpowerful editor) instead, set the environment variable EDITOR to /usr/bin/ee 20181558Smharo% 202174425SdougbTime to change your password? Type "passwd" and follow the prompts. 20378355Snik -- Dru <genesis@istar.ca> 20481558Smharo% 205174425SdougbTo change an environment variable in /bin/sh use: 206174425Sdougb 207174425Sdougb $ VARIABLE="value" 208174425Sdougb $ export VARIABLE 209174425Sdougb% 210174425SdougbTo change an environment variable in tcsh you use: setenv NAME "value" 211174425Sdougbwhere NAME is the name of the variable and "value" its new value. 212174425Sdougb% 21395677SdougbTo clear the screen, use "clear". To re-display your screen buffer, press 21495677Sdougbthe scroll lock key and use your page up button. When you're finished, 21595677Sdougbpress the scroll lock key again to get your prompt back. 21678355Snik -- Dru <genesis@istar.ca> 21781558Smharo% 21895677SdougbTo determine whether a file is a text file, executable, or some other type 21995677Sdougbof file, use 22078355Snik 22178355Snik file filename 22278355Snik -- Dru <genesis@istar.ca> 22381558Smharo% 224174425SdougbTo do a fast search for a file, try 225174425Sdougb 226174425Sdougb locate filename 227174425Sdougb 228174425Sdougblocate uses a database that is updated every Saturday (assuming your computer 229174425Sdougbis running FreeBSD at the time) to quickly find files based on name only. 23081558Smharo% 231174425SdougbTo erase a line you've written at the command prompt, use "Ctrl-U". 23278355Snik -- Dru <genesis@istar.ca> 23381558Smharo% 234269089SallanjudeTo find the hostname associated with an IP address, use 23578355Snik 236269089Sallanjude drill -x IP_address 237287582Sallanjude -- Allan Jude <allanjude@FreeBSD.org> 23881558Smharo% 239174425SdougbTo obtain a neat PostScript rendering of a manual page, use ``-t'' switch 240174425Sdougbof the man(1) utility: ``man -t <topic>''. For example: 24178355Snik 242174425Sdougb man -t grep > grep.ps # Save the PostScript version to a file 243174425Sdougbor 244174425Sdougb man -t printf | lp # Send the PostScript directly to printer 24581558Smharo% 246174425SdougbTo quickly create an empty file, use "touch filename". 24778355Snik -- Dru <genesis@istar.ca> 24881558Smharo% 249174425SdougbTo read a compressed file without having to first uncompress it, use 250235209Seadler"zcat" or "zless" to view it. 25178355Snik -- Dru <genesis@istar.ca> 25281558Smharo% 253174425SdougbTo repeat the last command in the C shell, type "!!". 25478355Snik -- Dru <genesis@istar.ca> 25581558Smharo% 256174425SdougbTo save disk space in your home directory, compress files you rarely 257174425Sdougbuse with "gzip filename". 25878355Snik -- Dru <genesis@istar.ca> 25981558Smharo% 260174425SdougbTo search for files that match a particular name, use find(1); for example 26178355Snik 262174425Sdougb find / -name "*GENERIC*" -ls 263174425Sdougb 264174425Sdougbwill search '/', and all subdirectories, for files with 'GENERIC' in the name. 265174425Sdougb -- Stephen Hilton <nospam@hiltonbsd.com> 26681558Smharo% 267174425SdougbTo see all of the directories on your FreeBSD system, type 268174425Sdougb 269241116Seadler find / -type d | less 270241116Seadler 271241116SeadlerAll the files? 272241116Seadler 273241116Seadler find / -type f | less 27481558Smharo% 27595677SdougbTo see how long it takes a command to run, type the word "time" before the 27695677Sdougbcommand name. 27778355Snik -- Dru <genesis@istar.ca> 27881558Smharo% 279174425SdougbTo see how much disk space is left on your partitions, use 28078355Snik 281174425Sdougb df -h 28278355Snik -- Dru <genesis@istar.ca> 28381558Smharo% 284174425SdougbTo see the 10 largest files on a directory or partition, use 28578355Snik 286174425Sdougb du /partition_or_directory_name | sort -rn | head 28778355Snik -- Dru <genesis@istar.ca> 28881558Smharo% 289174425SdougbTo see the IP addresses currently set on your active interfaces, type 290174425Sdougb"ifconfig -u". 29178355Snik -- Dru <genesis@istar.ca> 29281558Smharo% 293174425SdougbTo see the last 10 lines of a long file, use "tail filename". To see the 294174425Sdougbfirst 10 lines, use "head filename". 29578355Snik -- Dru <genesis@istar.ca> 29681558Smharo% 297174425SdougbTo see the last time that you logged in, use lastlogin(8). 29878355Snik -- Dru <genesis@istar.ca> 29981558Smharo% 300174425SdougbTo see the MAC addresses of the NICs on your system, type 301174425Sdougb 302174425Sdougb ifconfig -a 30378355Snik -- Dru <genesis@istar.ca> 30481558Smharo% 305174425SdougbTo see the output from when your computer started, run dmesg(8). If it has 306174425Sdougbbeen replaced with other messages, look at /var/run/dmesg.boot. 307174425Sdougb -- Francisco Reyes <lists@natserv.com> 30881558Smharo% 309174425SdougbWant colour in your directory listings? Use "ls -G". "ls -F" is also useful, 310174425Sdougband they can be combined as "ls -FG". 31181558Smharo% 312235227SeadlerWant to find a specific port, just type the following under /usr/ports 313174425Sdougbor one its subdirectories: 314174425Sdougb 315241116Seadler make search name=<port-name> 316174425Sdougb or 317241116Seadler make search key=<keyword> 31881558Smharo% 319174425SdougbWant to know how many words, lines, or bytes are contained in a file? Type 320174425Sdougb"wc filename". 32178355Snik -- Dru <genesis@istar.ca> 32281558Smharo% 323174425SdougbWant to see how much virtual memory you're using? Just type "swapinfo" to 324174425Sdougbbe shown information about the usage of your swap partitions. 32581558Smharo% 326174425SdougbWant to strip UTF-8 BOM(Byte Order Mark) from given files? 32778355Snik 328174425Sdougb sed -e '1s/^\xef\xbb\xbf//' < bomfile > newfile 32981558Smharo% 330174425SdougbWant to use sed(1) to edit a file in place? Well, to replace every 'e' with 331174425Sdougban 'o', in a file named 'foo', you can do: 33278355Snik 333174425Sdougb sed -i.bak s/e/o/g foo 334174425Sdougb 335174425SdougbAnd you'll get a backup of the original in a file named 'foo.bak', but if you 336174425Sdougbwant no backup: 337174425Sdougb 338174425Sdougb sed -i '' s/e/o/g foo 33978471Snik% 34078777SbrianWhen you've made modifications to a file in vi(1) and then find that 34178777Sbrianyou can't write it, type ``<ESC>!rm -f %'' then ``:w!'' to force the 34278777Sbrianwrite 34378777Sbrian 34478777SbrianThis won't work if you don't have write permissions to the directory 34578777Sbrianand probably won't be suitable if you're editing through a symbolic link. 34690516Skeramida% 347174425SdougbYou can adjust the volume of various parts of the sound system in your 348174425Sdougbcomputer by typing 'mixer <type> <volume>'. To get a list of what you can 349174425Sdougbadjust, just type 'mixer'. 350174425Sdougb% 351174425SdougbYou can automatically download and install binary packages by doing 35290516Skeramida 353256019Sglebius pkg install <package> 354174425Sdougb 355256019SglebiusThis will also automatically install the packages that are dependencies 356256019Sglebiusfor the package you install (ie, the packages it needs in order to work.) 357102943Sjmallett% 358174425SdougbYou can change the video mode on all consoles by adding something like 359174425Sdougbthe following to /etc/rc.conf: 360102943Sjmallett 361174425Sdougb allscreens="80x30" 362102943Sjmallett 363174425SdougbYou can use "vidcontrol -i mode | grep T" for a list of supported text 364174425Sdougbmodes. 365174425Sdougb -- Konstantinos Konstantinidis <kkonstan@duth.gr> 366174425Sdougb% 367174425SdougbYou can disable tcsh's terminal beep if you `set nobeep'. 368174425Sdougb% 369174425SdougbYou can install extra packages for FreeBSD by using the ports system. 370174425SdougbIf you have installed it, you can download, compile, and install software by 371174425Sdougbjust typing 372163144Schinsan 373174425Sdougb # cd /usr/ports/<category>/<portname> 374174425Sdougb # make install && make clean 375174425Sdougb 376174425Sdougbas root. The ports infrastructure will download the software, change it so 377174425Sdougbit works on FreeBSD, compile it, install it, register the installation so it 378174425Sdougbwill be possible to automatically uninstall it, and clean out the temporary 379174425Sdougbworking space it used. You can remove an installed port you decide you do not 380174425Sdougbwant after all by typing 381174425Sdougb 382174425Sdougb # cd /usr/ports/<category>/<portname> 383174425Sdougb # make deinstall 384174425Sdougb 385174425Sdougbas root. 386174422Sdougb% 387174425SdougbYou can look through a file in a nice text-based interface by typing 388174425Sdougb 389174425Sdougb less filename 390174425Sdougb% 391174425SdougbYou can make a log of your terminal session with script(1). 392174425Sdougb% 393174425SdougbYou can often get answers to your questions about FreeBSD by searching in the 394174425SdougbFreeBSD mailing list archives at 395174425Sdougb 396174425Sdougb http://www.FreeBSD.org/search/search.html 397174425Sdougb% 398174425SdougbYou can open up a new split-screen window in (n)vi with :N or :E and then 399174425Sdougbuse ^w to switch between the two. 400174425Sdougb% 401174425SdougbYou can permanently set environment variables for your shell by putting them 402174425Sdougbin a startup file for the shell. The name of the startup file varies 403174425Sdougbdepending on the shell - csh and tcsh uses .login, bash, sh, ksh and zsh use 404174425Sdougb.profile. When using bash, sh, ksh or zsh, don't forget to export the 405174425Sdougbvariable. 406174425Sdougb% 407174425SdougbYou can press Ctrl-D to quickly exit from a shell, or logout from a 408174425Sdougblogin shell. 409174425Sdougb -- Konstantinos Konstantinidis <kkonstan@duth.gr> 410174425Sdougb% 411241116SeadlerYou can press Ctrl-L while in the shell to clear the screen. 412241116Seadler% 413174425SdougbYou can press up-arrow or down-arrow to walk through a list of 414174425Sdougbprevious commands in tcsh. 415174425Sdougb% 416174425SdougbYou can search for documentation on a keyword by typing 417174425Sdougb 418174425Sdougb apropos keyword 419174425Sdougb% 420174425SdougbYou can `set autologout = 30' to have tcsh log you off automatically 421174425Sdougbif you leave the shell idle for more than 30 minutes. 422174425Sdougb% 423174425SdougbYou can use aliases to decrease the amount of typing you need to do to get 424174425Sdougbcommands you commonly use. Examples of fairly popular aliases include (in 425174425SdougbBourne shell style, as in /bin/sh, bash, ksh, and zsh): 426174425Sdougb 427174425Sdougb alias lf="ls -FA" 428174425Sdougb alias ll="ls -lA" 429174425Sdougb alias su="su -m" 430174425Sdougb 431174425SdougbIn csh or tcsh, these would be 432174425Sdougb 433174425Sdougb alias lf ls -FA 434174425Sdougb alias ll ls -lA 435174425Sdougb alias su su -m 436174425Sdougb 437174425SdougbTo remove an alias, you can usually use 'unalias aliasname'. To list all 438174425Sdougbaliases, you can usually type just 'alias'. 439174425Sdougb% 440174425SdougbYou can use /etc/make.conf to control the options used to compile software 441174425Sdougbon this system. Example entries are in 442174425Sdougb/usr/share/examples/etc/make.conf. 443174425Sdougb% 444256019SglebiusYou can use "pkg info" to see a list of packages you have installed. 445174425Sdougb% 446278543SjmgYou can use the 'fetch' command to retrieve files over ftp, http or https. 447174425Sdougb 448174425Sdougb fetch http://www.FreeBSD.org/index.html 449174425Sdougb 450174425Sdougbwill download the front page of the FreeBSD web site. 451174425Sdougb% 452174425SdougbYou can use "whereis" to search standard binary, manual page and source 453174425Sdougbdirectories for the specified programs. This can be particularly handy 454174425Sdougbwhen you are trying to find where in the ports tree an application is. 455174425Sdougb 456211094SfjoeTry "whereis firefox" and "whereis whereis". 457174425Sdougb -- Konstantinos Konstantinidis <kkonstan@duth.gr> 458174425Sdougb% 459235209SeadlerWant to run the same command again? 460235209SeadlerIn tcsh you can type "!!" 461235209Seadler% 462235209SeadlerWant to go the directory you were just in? 463235227SeadlerType "cd -" 464235209Seadler% 465