xref: /freebsd/usr.bin/fortune/datfiles/freebsd-tips (revision 278e370066734a06f6b35e585568ac34969b1e84)
16ae1554aSColin PercivalAny user that is a member of the wheel group can use "su -" to simulate
26ae1554aSColin Percivala root login. You can add a user to the wheel group by editing /etc/group.
36ae1554aSColin Percival		-- Konstantinos Konstantinidis <kkonstan@duth.gr>
46ae1554aSColin Percival%
56ae1554aSColin PercivalBy pressing "Scroll Lock" you can use the arrow keys to scroll backward
66ae1554aSColin Percivalthrough the console output.  Press "Scroll Lock" again to turn it off.
71909a1f4SAlfred PerlsteinDon't have a "Scroll Lock" key? The "Pause / Break" key acts alike.
86ae1554aSColin Percival%
96ae1554aSColin PercivalCan't remember if you've installed a certain port or not? Try "pkg info
106ae1554aSColin Percival-x port_name".
116ae1554aSColin Percival%
126ae1554aSColin PercivalEver wonder what those numbers after command names were, as in cat(1)?  It's
136ae1554aSColin Percivalthe section of the manual the man page is in.  "man man" will tell you more.
146ae1554aSColin Percival		-- David Scheidt <dscheidt@tumbolia.com>
156ae1554aSColin Percival%
166ae1554aSColin PercivalForget how to spell a word or a variation of a word? Use
176ae1554aSColin Percival
186ae1554aSColin Percival	look portion_of_word_you_know
196ae1554aSColin Percival		-- Dru <genesis@istar.ca>
206ae1554aSColin Percival%
216ae1554aSColin PercivalForget what directory you are in? Type "pwd".
226ae1554aSColin Percival		-- Dru <genesis@istar.ca>
236ae1554aSColin Percival%
246ae1554aSColin PercivalForget when Easter is? Try "ncal -e". If you need the date for Orthodox
256ae1554aSColin PercivalEaster, use "ncal -o" instead.
266ae1554aSColin Percival		-- Dru <genesis@istar.ca>
276ae1554aSColin Percival%
286ae1554aSColin PercivalFreeBSD is started up by the program 'init'.  The first thing init does when
296ae1554aSColin Percivalstarting multiuser mode (ie, starting the computer up for normal use) is to
306ae1554aSColin Percivalrun the shell script /etc/rc.  By reading /etc/rc and the /etc/rc.d/ scripts,
316ae1554aSColin Percivalyou can learn a lot about how the system is put together, which again will
326ae1554aSColin Percivalmake you more confident about what happens when you do something with it.
336ae1554aSColin Percival%
346ae1554aSColin PercivalHandy bash(1) prompt:  PS1="\u@\h \w \!$ "
356ae1554aSColin Percival		-- David Scheidt <dscheidt@tumbolia.com>
366ae1554aSColin Percival%
376ae1554aSColin PercivalHaving trouble using fetch through a firewall? Try setting the environment
386ae1554aSColin Percivalvariable FTP_PASSIVE_MODE to yes, and see fetch(3) for more details.
396ae1554aSColin Percival%
405b990a94SBaptiste DaroussinIf other operating systems have damaged your Master Boot Record, you can
411909a1f4SAlfred Perlsteinreinstall it with gpart(8). See
421909a1f4SAlfred Perlstein"man gpart" for details.
436ae1554aSColin Percival%
446ae1554aSColin PercivalIf you accidentally end up inside vi, you can quit it by pressing Escape, colon
456ae1554aSColin Percival(:), q (q), bang (!) and pressing return.
466ae1554aSColin Percival%
476ae1554aSColin PercivalIf you do not want to get beeps in X11 (X Windows), you can turn them off with
486ae1554aSColin Percival
496ae1554aSColin Percival	xset b off
506ae1554aSColin Percival%
516ae1554aSColin PercivalIf you have a CD-ROM drive in your machine, you can make the CD-ROM that is
526ae1554aSColin Percivalpresently inserted available by typing 'mount /cdrom' as root.  The CD-ROM
536ae1554aSColin Percivalwill be available under /cdrom/.  Remember to do 'umount /cdrom' before
546ae1554aSColin Percivalremoving the CD-ROM (it will usually not be possible to remove the CD-ROM
556ae1554aSColin Percivalwithout doing this.)
566ae1554aSColin Percival
576ae1554aSColin PercivalNote: This tip may not work in all configurations.
586ae1554aSColin Percival%
596ae1554aSColin PercivalIf you need a reminder to leave your terminal, type "leave +hhmm" where
606ae1554aSColin Percival"hhmm" represents in how many hours and minutes you need to leave.
616ae1554aSColin Percival		-- Dru <genesis@istar.ca>
626ae1554aSColin Percival%
636ae1554aSColin PercivalIf you need to ask a question on the FreeBSD-questions mailing list then
646ae1554aSColin Percival
65c1a14887SCeri Davies	https://docs.freebsd.org/en/articles/freebsd-questions
666ae1554aSColin Percival
676ae1554aSColin Percivalcontains lots of useful advice to help you get the best results.
686ae1554aSColin Percival%
696ae1554aSColin PercivalIf you write part of a filename in tcsh,
706ae1554aSColin Percivalpressing TAB will show you the available choices when there
716ae1554aSColin Percivalis more than one, or complete the filename if there's only one match.
726ae1554aSColin Percival%
736ae1554aSColin PercivalIf you `set watch = (0 any any)' in tcsh, you will be notified when
746ae1554aSColin Percivalsomeone logs in or out of your system.
756ae1554aSColin Percival%
766ae1554aSColin PercivalIf you use the C shell, add the following line to the .cshrc file in your
776ae1554aSColin Percivalhome directory to prevent core files from being written to disk:
786ae1554aSColin Percival
796ae1554aSColin Percival	limit coredumpsize 0
806ae1554aSColin Percival		-- Dru <genesis@istar.ca>
816ae1554aSColin Percival%
826ae1554aSColin PercivalIf you want df(1) and other commands to display disk sizes in
836ae1554aSColin Percivalkilobytes instead of 512-byte blocks, set BLOCKSIZE in your
846ae1554aSColin Percivalenvironment to 'K'.  You can also use 'M' for Megabytes or 'G' for
856ae1554aSColin PercivalGigabytes.  If you want df(1) to automatically select the best size
866ae1554aSColin Percivalthen use 'df -h'.
876ae1554aSColin Percival%
886ae1554aSColin PercivalIf you want to play CDs with FreeBSD, a utility for this is already included.
896ae1554aSColin PercivalType 'cdcontrol' then 'help' to learn more.  (You may need to set the CDROM
906ae1554aSColin Percivalenvironment variable in order to make cdcontrol want to start.)
916ae1554aSColin Percival%
926ae1554aSColin PercivalIf you'd like to keep track of applications in the FreeBSD ports tree, take a
936ae1554aSColin Percivallook at FreshPorts;
946ae1554aSColin Percival
957e3f9a34SEitan Adler	https://www.freshports.org/
966ae1554aSColin Percival%
976ae1554aSColin PercivalIn order to make fetch (the FreeBSD downloading tool) ask for
986ae1554aSColin Percivalusername/password when it encounters a password-protected web page, you can set
996ae1554aSColin Percivalthe environment variable HTTP_AUTH to 'basic:*'.
1006ae1554aSColin Percival%
1016ae1554aSColin PercivalIn order to search for a string in some files, use 'grep' like this:
1026ae1554aSColin Percival
1036ae1554aSColin Percival	 grep "string" filename1 [filename2 filename3 ...]
1046ae1554aSColin Percival
1056ae1554aSColin PercivalThis will print out the lines in the files that contain the string.  grep can
1066ae1554aSColin Percivalalso do a lot more advanced searches - type 'man grep' for details.
1076ae1554aSColin Percival%
1086ae1554aSColin PercivalIn order to support national characters for European languages in tools like
1096ae1554aSColin Percivalless without creating other nationalisation aspects, set the environment
110ff744dbdSEitan Adlervariable LC_ALL to 'en_US.UTF-8'.
1116ae1554aSColin Percival%
1121909a1f4SAlfred Perlstein"man firewall" will give advice for building a FreeBSD firewall using ipfw(8).
1136ae1554aSColin Percival		-- David Scheidt <dscheidt@tumbolia.com>
1146ae1554aSColin Percival%
1156ae1554aSColin Percival"man hier" will explain the way FreeBSD filesystems are normally laid out.
1166ae1554aSColin Percival		-- David Scheidt <dscheidt@tumbolia.com>
1176ae1554aSColin Percival%
1186ae1554aSColin PercivalMan pages are divided into section depending on topic.  There are 9 different
1196ae1554aSColin Percivalsections numbered from 1 (General Commands) to 9 (Kernel Developer's Manual).
1206ae1554aSColin PercivalYou can get an introduction to each topic by typing
1216ae1554aSColin Percival
1226ae1554aSColin Percival	man <number> intro
1236ae1554aSColin Percival
1246ae1554aSColin PercivalIn other words, to get the intro to general commands, type
1256ae1554aSColin Percival
1266ae1554aSColin Percival	man 1 intro
1276ae1554aSColin Percival%
1286ae1554aSColin Percival"man ports" gives many useful hints about installing FreeBSD ports.
1296ae1554aSColin Percival%
1306ae1554aSColin Percival"man security" gives very good advice on how to tune the security of your
1316ae1554aSColin PercivalFreeBSD system.
1326ae1554aSColin Percival%
1336ae1554aSColin Percival"man tuning" gives some tips how to tune performance of your FreeBSD system.
1346ae1554aSColin Percival		-- David Scheidt <dscheidt@tumbolia.com>
1356ae1554aSColin Percival%
1366ae1554aSColin PercivalNeed to do a search in a manpage or in a file you've sent to a pager? Use
1371909a1f4SAlfred Perlstein"/search_word". To repeat the same search, type "n" for next or "p" for
1381909a1f4SAlfred Perlsteinprevious.
1396ae1554aSColin Percival		-- Dru <genesis@istar.ca>
1406ae1554aSColin Percival%
1416ae1554aSColin PercivalNeed to find the location of a program? Use "locate program_name".
1426ae1554aSColin Percival		-- Dru <genesis@istar.ca>
1436ae1554aSColin Percival%
1446ae1554aSColin PercivalNeed to leave your terminal for a few minutes and don't want to logout?
1456ae1554aSColin PercivalUse "lock -p". When you return, use your password as the key to unlock the
1466ae1554aSColin Percivalterminal.
1476ae1554aSColin Percival		-- Dru <genesis@istar.ca>
1486ae1554aSColin Percival%
1496ae1554aSColin PercivalNeed to quickly empty a file? Use ": > filename".
1506ae1554aSColin Percival		-- Dru <genesis@istar.ca>
1516ae1554aSColin Percival%
1526ae1554aSColin PercivalNeed to quickly return to your home directory? Type "cd".
1536ae1554aSColin Percival		-- Dru <genesis@istar.ca>
1546ae1554aSColin Percival%
1556ae1554aSColin PercivalNeed to remove all those ^M characters from a DOS file? Try
1566ae1554aSColin Percival
1576ae1554aSColin Percival	tr -d \\r < dosfile > newfile
1586ae1554aSColin Percival		-- Originally by Dru <genesis@istar.ca>
1596ae1554aSColin Percival%
1606ae1554aSColin PercivalNeed to see the calendar for this month? Simply type "cal".  To see the
1616ae1554aSColin Percivalwhole year, type "cal -y".
1626ae1554aSColin Percival		-- Dru <genesis@istar.ca>
1636ae1554aSColin Percival%
1646ae1554aSColin PercivalNeed to see which daemons are listening for connection requests? Use
1656ae1554aSColin Percival"sockstat -4l" for IPv4, and "sockstat -l" for IPv4 and IPv6.
1666ae1554aSColin Percival		-- Dru <genesis@istar.ca>
1676ae1554aSColin Percival%
1686ae1554aSColin PercivalNeed to see your routing table? Type "netstat -rn". The entry with the G
1696ae1554aSColin Percivalflag is your gateway.
1706ae1554aSColin Percival		-- Dru <genesis@istar.ca>
1716ae1554aSColin Percival%
1726ae1554aSColin PercivalNice bash prompt: PS1='(\[$(tput md)\]\t <\w>\[$(tput me)\]) $(echo $?) \$ '
1736ae1554aSColin Percival		-- Mathieu <mathieu@hal.interactionvirtuelle.com>
1746ae1554aSColin Percival%
1751909a1f4SAlfred PerlsteinOver quota?  "du -sh * | sort -h " will give you a sorted list of your
1766ae1554aSColin Percivaldirectory sizes.
1776ae1554aSColin Percival		-- David Scheidt <dscheidt@tumbolia.com>
1786ae1554aSColin Percival%
1796ae1554aSColin Percivalnc(1) (or netcat) is useful not only for redirecting input/output to
1806ae1554aSColin PercivalTCP or UDP connections, but also for proxying them with inetd(8).
1816ae1554aSColin Percival%
1826ae1554aSColin Percivalsh (the default Bourne shell in FreeBSD) supports command-line editing.  Just
1831909a1f4SAlfred Perlstein``set -o emacs'' or ``set -o vi'' to enable it. Use "<TAB>" key to complete
1841909a1f4SAlfred Perlsteinpaths.
1856ae1554aSColin Percival%
1866ae1554aSColin PercivalSimple tcsh prompt: set prompt = '%# '
1876ae1554aSColin Percival%
1886ae1554aSColin PercivalThe default editor in FreeBSD is vi, which is efficient to use when you have
1896ae1554aSColin Percivallearned it, but somewhat user-unfriendly.  To use ee (an easier but less
1906ae1554aSColin Percivalpowerful editor) instead, set the environment variable EDITOR to /usr/bin/ee
1916ae1554aSColin Percival%
1926ae1554aSColin PercivalTime to change your password? Type "passwd" and follow the prompts.
1936ae1554aSColin Percival		-- Dru <genesis@istar.ca>
1946ae1554aSColin Percival%
1956ae1554aSColin PercivalTo change an environment variable in /bin/sh use:
1966ae1554aSColin Percival
1976ae1554aSColin Percival	$ VARIABLE="value"
1986ae1554aSColin Percival	$ export VARIABLE
1996ae1554aSColin Percival%
2006ae1554aSColin PercivalTo change an environment variable in tcsh you use: setenv NAME "value"
2016ae1554aSColin Percivalwhere NAME is the name of the variable and "value" its new value.
2026ae1554aSColin Percival%
2036ae1554aSColin PercivalTo clear the screen, use "clear". To re-display your screen buffer, press
2046ae1554aSColin Percivalthe scroll lock key and use your page up button. When you're finished,
2056ae1554aSColin Percivalpress the scroll lock key again to get your prompt back.
2066ae1554aSColin Percival		-- Dru <genesis@istar.ca>
2076ae1554aSColin Percival%
2081909a1f4SAlfred PerlsteinYou can press Ctrl-L while in the shell to clear the screen.
2091909a1f4SAlfred Perlstein%
2106ae1554aSColin PercivalTo determine whether a file is a text file, executable, or some other type
2116ae1554aSColin Percivalof file, use
2126ae1554aSColin Percival
2136ae1554aSColin Percival	file filename
2146ae1554aSColin Percival		-- Dru <genesis@istar.ca>
2156ae1554aSColin Percival%
2166ae1554aSColin PercivalTo do a fast search for a file, try
2176ae1554aSColin Percival
2186ae1554aSColin Percival	 locate filename
2196ae1554aSColin Percival
2206ae1554aSColin Percivallocate uses a database that is updated every Saturday (assuming your computer
2216ae1554aSColin Percivalis running FreeBSD at the time) to quickly find files based on name only.
2226ae1554aSColin Percival%
2236ae1554aSColin PercivalTo erase a line you've written at the command prompt, use "Ctrl-U".
2246ae1554aSColin Percival		-- Dru <genesis@istar.ca>
2256ae1554aSColin Percival%
2261909a1f4SAlfred PerlsteinTo find out the hostname associated with an IP address, use
2276ae1554aSColin Percival
2286ae1554aSColin Percival	drill -x IP_address
2291909a1f4SAlfred Perlstein		-- Dru <genesis@istar.ca>
2306ae1554aSColin Percival%
2316ae1554aSColin PercivalTo obtain a neat PostScript rendering of a manual page, use ``-t'' switch
2326ae1554aSColin Percivalof the man(1) utility: ``man -t <topic>''.  For example:
2336ae1554aSColin Percival
2346ae1554aSColin Percival	man -t grep > grep.ps	# Save the PostScript version to a file
2356ae1554aSColin Percivalor
2366ae1554aSColin Percival	man -t printf | lp	# Send the PostScript directly to printer
2376ae1554aSColin Percival%
2386ae1554aSColin PercivalTo quickly create an empty file, use "touch filename".
2396ae1554aSColin Percival		-- Dru <genesis@istar.ca>
2406ae1554aSColin Percival%
2416ae1554aSColin PercivalTo read a compressed file without having to first uncompress it, use
2421909a1f4SAlfred Perlstein"zcat" or "zless" to view it. There is also "bzcat", "bzless", "xzcat"
2431909a1f4SAlfred Perlsteinand "xzless".
2446ae1554aSColin Percival		-- Dru <genesis@istar.ca>
2456ae1554aSColin Percival%
2466ae1554aSColin PercivalTo save disk space in your home directory, compress files you rarely
2476ae1554aSColin Percivaluse with "gzip filename".
2486ae1554aSColin Percival		-- Dru <genesis@istar.ca>
2496ae1554aSColin Percival%
2506ae1554aSColin PercivalTo search for files that match a particular name, use find(1); for example
2516ae1554aSColin Percival
2526ae1554aSColin Percival	find / -name "*GENERIC*" -ls
2536ae1554aSColin Percival
2546ae1554aSColin Percivalwill search '/', and all subdirectories, for files with 'GENERIC' in the name.
2556ae1554aSColin Percival      	--  Stephen Hilton <nospam@hiltonbsd.com>
2566ae1554aSColin Percival%
2576ae1554aSColin PercivalTo see all of the directories on your FreeBSD system, type
2586ae1554aSColin Percival
2596ae1554aSColin Percival	find / -type d | less
2606ae1554aSColin Percival
2616ae1554aSColin PercivalAll the files?
2626ae1554aSColin Percival
2636ae1554aSColin Percival	find / -type f | less
2646ae1554aSColin Percival%
2656ae1554aSColin PercivalTo see how long it takes a command to run, type the word "time" before the
2666ae1554aSColin Percivalcommand name.
2676ae1554aSColin Percival		-- Dru <genesis@istar.ca>
2686ae1554aSColin Percival%
26956d417fdSBenedict ReuschlingTo see how much disk space is left on your UFS partitions, use
2706ae1554aSColin Percival
2716ae1554aSColin Percival	df -h
2726ae1554aSColin Percival		-- Dru <genesis@istar.ca>
2736ae1554aSColin Percival%
274a9ea96eaSBenedict ReuschlingTo see the 10 largest files in a directory or on a UFS partition, use
2756ae1554aSColin Percival
2761909a1f4SAlfred Perlstein	du -h /partition_or_directory_name | sort -rh | head
2776ae1554aSColin Percival		-- Dru <genesis@istar.ca>
2786ae1554aSColin Percival%
2796ae1554aSColin PercivalTo see the IP addresses currently set on your active interfaces, type
2806ae1554aSColin Percival"ifconfig -u".
2816ae1554aSColin Percival		-- Dru <genesis@istar.ca>
2826ae1554aSColin Percival%
2836ae1554aSColin PercivalTo see the last 10 lines of a long file, use "tail filename". To see the
2841909a1f4SAlfred Perlsteinfirst 10 lines, use "head filename". To see new lines as they're appended
2851909a1f4SAlfred Perlsteinto a file, use "tail -f filename".
2866ae1554aSColin Percival		-- Dru <genesis@istar.ca>
2876ae1554aSColin Percival%
2886ae1554aSColin PercivalTo see the last time that you logged in, use lastlogin(8).
2896ae1554aSColin Percival		-- Dru <genesis@istar.ca>
2906ae1554aSColin Percival%
2916ae1554aSColin PercivalTo see the MAC addresses of the NICs on your system, type
2926ae1554aSColin Percival
2936ae1554aSColin Percival	ifconfig -a
2946ae1554aSColin Percival		-- Dru <genesis@istar.ca>
2956ae1554aSColin Percival%
2966ae1554aSColin PercivalTo see the output from when your computer started, run dmesg(8).  If it has
2976ae1554aSColin Percivalbeen replaced with other messages, look at /var/run/dmesg.boot.
2986ae1554aSColin Percival		-- Francisco Reyes <lists@natserv.com>
2996ae1554aSColin Percival%
3006ae1554aSColin PercivalWant colour in your directory listings?  Use "ls -G".  "ls -F" is also useful,
3016ae1554aSColin Percivaland they can be combined as "ls -FG".
3026ae1554aSColin Percival%
303cb556651SGordon BerglingWant to find a specific port? Just type the following under /usr/ports
304cb556651SGordon Berglingor one of its subdirectories:
3056ae1554aSColin Percival
3066ae1554aSColin Percival	make search name=<port-name>
3076ae1554aSColin Percival    or
3086ae1554aSColin Percival	make search key=<keyword>
3096ae1554aSColin Percival%
3106ae1554aSColin PercivalWant to know how many words, lines, or bytes are contained in a file? Type
3116ae1554aSColin Percival"wc filename".
3126ae1554aSColin Percival		-- Dru <genesis@istar.ca>
3136ae1554aSColin Percival%
3146ae1554aSColin PercivalWant to see how much virtual memory you're using? Just type "swapinfo" to
3156ae1554aSColin Percivalbe shown information about the usage of your swap partitions.
3166ae1554aSColin Percival%
3176ae1554aSColin PercivalWant to strip UTF-8 BOM(Byte Order Mark) from given files?
3186ae1554aSColin Percival
3196ae1554aSColin Percival	sed -e '1s/^\xef\xbb\xbf//' < bomfile > newfile
3206ae1554aSColin Percival%
3216ae1554aSColin PercivalWant to use sed(1) to edit a file in place?  Well, to replace every 'e' with
3226ae1554aSColin Percivalan 'o', in a file named 'foo', you can do:
3236ae1554aSColin Percival
3246ae1554aSColin Percival	sed -i.bak s/e/o/g foo
3256ae1554aSColin Percival
3266ae1554aSColin PercivalAnd you'll get a backup of the original in a file named 'foo.bak', but if you
3276ae1554aSColin Percivalwant no backup:
3286ae1554aSColin Percival
3296ae1554aSColin Percival	sed -i '' s/e/o/g foo
3306ae1554aSColin Percival%
3316ae1554aSColin PercivalWhen you've made modifications to a file in vi(1) and then find that
3326ae1554aSColin Percivalyou can't write it, type ``<ESC>!rm -f %'' then ``:w!'' to force the
3336ae1554aSColin Percivalwrite
3346ae1554aSColin Percival
3356ae1554aSColin PercivalThis won't work if you don't have write permissions to the directory
3366ae1554aSColin Percivaland probably won't be suitable if you're editing through a symbolic link.
3371909a1f4SAlfred Perlstein
3381909a1f4SAlfred PerlsteinIf you have sudo(8) installed and permissions to use it, type
3391909a1f4SAlfred Perlstein``<ESC>w ! sudo tee %'' to force a write.
3406ae1554aSColin Percival%
3416ae1554aSColin PercivalYou can adjust the volume of various parts of the sound system in your
3426ae1554aSColin Percivalcomputer by typing 'mixer <type> <volume>'.  To get a list of what you can
3436ae1554aSColin Percivaladjust, just type 'mixer'.
3446ae1554aSColin Percival%
3456ae1554aSColin PercivalYou can automatically download and install binary packages by doing
3466ae1554aSColin Percival
3476ae1554aSColin Percival	pkg install <package>
3486ae1554aSColin Percival
3496ae1554aSColin PercivalThis will also automatically install the packages that are dependencies
3506ae1554aSColin Percivalfor the package you install (ie, the packages it needs in order to work.)
3516ae1554aSColin Percival%
3526ae1554aSColin PercivalYou can change the video mode on all consoles by adding something like
3536ae1554aSColin Percivalthe following to /etc/rc.conf:
3546ae1554aSColin Percival
3556ae1554aSColin Percival	allscreens="80x30"
3566ae1554aSColin Percival
3576ae1554aSColin PercivalYou can use "vidcontrol -i mode | grep T" for a list of supported text
3586ae1554aSColin Percivalmodes.
3596ae1554aSColin Percival		-- Konstantinos Konstantinidis <kkonstan@duth.gr>
3606ae1554aSColin Percival%
3616ae1554aSColin PercivalYou can disable tcsh's terminal beep if you `set nobeep'.
3626ae1554aSColin Percival%
3636ae1554aSColin PercivalYou can install extra packages for FreeBSD by using the ports system.
3646ae1554aSColin PercivalIf you have installed it, you can download, compile, and install software by
3656ae1554aSColin Percivaljust typing
3666ae1554aSColin Percival
3676ae1554aSColin Percival	# cd /usr/ports/<category>/<portname>
3686ae1554aSColin Percival	# make install && make clean
3696ae1554aSColin Percival
3706ae1554aSColin Percivalas root.  The ports infrastructure will download the software, change it so
3716ae1554aSColin Percivalit works on FreeBSD, compile it, install it, register the installation so it
3726ae1554aSColin Percivalwill be possible to automatically uninstall it, and clean out the temporary
3736ae1554aSColin Percivalworking space it used.  You can remove an installed port you decide you do not
3746ae1554aSColin Percivalwant after all by typing
3756ae1554aSColin Percival
3766ae1554aSColin Percival	# cd /usr/ports/<category>/<portname>
3776ae1554aSColin Percival	# make deinstall
3786ae1554aSColin Percival
3796ae1554aSColin Percivalas root.
3806ae1554aSColin Percival%
3816ae1554aSColin PercivalYou can look through a file in a nice text-based interface by typing
3826ae1554aSColin Percival
3836ae1554aSColin Percival	less filename
3846ae1554aSColin Percival%
3856ae1554aSColin PercivalYou can make a log of your terminal session with script(1).
3866ae1554aSColin Percival%
3876ae1554aSColin PercivalYou can often get answers to your questions about FreeBSD by searching in the
3886ae1554aSColin PercivalFreeBSD mailing list archives at
3896ae1554aSColin Percival
3901909a1f4SAlfred Perlstein	http://freebsd.markmail.org
3916ae1554aSColin Percival%
3926ae1554aSColin PercivalYou can open up a new split-screen window in (n)vi with :N or :E and then
3936ae1554aSColin Percivaluse ^w to switch between the two.
3946ae1554aSColin Percival%
3956ae1554aSColin PercivalYou can permanently set environment variables for your shell by putting them
3966ae1554aSColin Percivalin a startup file for the shell.  The name of the startup file varies
3976ae1554aSColin Percivaldepending on the shell - csh and tcsh uses .login, bash, sh, ksh and zsh use
3986ae1554aSColin Percival.profile.  When using bash, sh, ksh or zsh, don't forget to export the
3996ae1554aSColin Percivalvariable.
4006ae1554aSColin Percival%
4016ae1554aSColin PercivalYou can press Ctrl-D to quickly exit from a shell, or logout from a
4026ae1554aSColin Percivallogin shell.
4036ae1554aSColin Percival		-- Konstantinos Konstantinidis <kkonstan@duth.gr>
4046ae1554aSColin Percival%
4056ae1554aSColin PercivalYou can press up-arrow or down-arrow to walk through a list of
4066ae1554aSColin Percivalprevious commands in tcsh.
4076ae1554aSColin Percival%
4086ae1554aSColin PercivalYou can search for documentation on a keyword by typing
4096ae1554aSColin Percival
4106ae1554aSColin Percival	apropos keyword
4116ae1554aSColin Percival%
4126ae1554aSColin PercivalYou can `set autologout = 30' to have tcsh log you off automatically
4136ae1554aSColin Percivalif you leave the shell idle for more than 30 minutes.
4146ae1554aSColin Percival%
4156ae1554aSColin PercivalYou can use aliases to decrease the amount of typing you need to do to get
4166ae1554aSColin Percivalcommands you commonly use.  Examples of fairly popular aliases include (in
4176ae1554aSColin PercivalBourne shell style, as in /bin/sh, bash, ksh, and zsh):
4186ae1554aSColin Percival
4196ae1554aSColin Percival	alias lf="ls -FA"
4206ae1554aSColin Percival	alias ll="ls -lA"
4216ae1554aSColin Percival	alias su="su -m"
4226ae1554aSColin Percival
4236ae1554aSColin PercivalIn csh or tcsh, these would be
4246ae1554aSColin Percival
4256ae1554aSColin Percival	alias lf ls -FA
4266ae1554aSColin Percival	alias ll ls -lA
4276ae1554aSColin Percival	alias su su -m
4286ae1554aSColin Percival
4296ae1554aSColin PercivalTo remove an alias, you can usually use 'unalias aliasname'.  To list all
4306ae1554aSColin Percivalaliases, you can usually type just 'alias'.
4316ae1554aSColin Percival%
4326ae1554aSColin PercivalYou can use /etc/make.conf to control the options used to compile software
4336ae1554aSColin Percivalon this system.  Example entries are in
4341909a1f4SAlfred Perlstein/usr/share/examples/etc/make.conf and in make.conf(5).
4351909a1f4SAlfred PerlsteinFor options that are set for building FreeBSD's kernel and its world, see
4361909a1f4SAlfred Perlsteinsrc.conf(5).
4376ae1554aSColin Percival%
4386ae1554aSColin PercivalYou can use "pkg info" to see a list of packages you have installed.
4396ae1554aSColin Percival%
4406ae1554aSColin PercivalYou can use the 'fetch' command to retrieve files over ftp, http or https.
4416ae1554aSColin Percival
4427e3f9a34SEitan Adler	 fetch https://www.FreeBSD.org/index.html
4436ae1554aSColin Percival
4446ae1554aSColin Percivalwill download the front page of the FreeBSD web site.
4456ae1554aSColin Percival%
4466ae1554aSColin PercivalYou can use "whereis" to search standard binary, manual page and source
4476ae1554aSColin Percivaldirectories for the specified programs. This can be particularly handy
4486ae1554aSColin Percivalwhen you are trying to find where in the ports tree an application is.
4496ae1554aSColin Percival
4506ae1554aSColin PercivalTry "whereis firefox" and "whereis whereis".
4516ae1554aSColin Percival		-- Konstantinos Konstantinidis <kkonstan@duth.gr>
4526ae1554aSColin Percival%
4536ae1554aSColin PercivalWant to run the same command again?
454c92116f3SEitan AdlerIn many shells (e.g., tcsh, zsh, bash) you can type "!!".
4556ae1554aSColin Percival%
4566ae1554aSColin PercivalWant to go the directory you were just in?
4576ae1554aSColin PercivalType "cd -"
4586ae1554aSColin Percival%
4591909a1f4SAlfred PerlsteinCan't delete /usr/obj? Enter "chflags -R noschg /usr/obj" to remove the
4601909a1f4SAlfred Perlsteinsystem immutable flag for all files in /usr/obj.
4611909a1f4SAlfred Perlstein
4621909a1f4SAlfred Perlstein		-- Lars Engels <lme@FreeBSD.org>
4631909a1f4SAlfred Perlstein%
4641909a1f4SAlfred PerlsteinWant to list all files of an installed package? Enter
4651909a1f4SAlfred Perlstein"pkg info -l packagename".
4661909a1f4SAlfred Perlstein
4671909a1f4SAlfred Perlstein		-- Lars Engels <lme@FreeBSD.org>
4681909a1f4SAlfred Perlstein%
4691909a1f4SAlfred PerlsteinAre you looking for a package? Search for it with
4701909a1f4SAlfred Perlstein"pkg search part_of_package_name"
4711909a1f4SAlfred Perlstein
4721909a1f4SAlfred Perlstein		-- Lars Engels <lme@FreeBSD.org>
4731909a1f4SAlfred Perlstein%
4741909a1f4SAlfred PerlsteinIf you want to recursively copy a directory preserving file and directory
4751909a1f4SAlfred Perlsteinattributes use
4761909a1f4SAlfred Perlstein"cp -a source target"
4771909a1f4SAlfred Perlstein
4781909a1f4SAlfred Perlstein		-- Lars Engels <lme@FreeBSD.org>
4791909a1f4SAlfred Perlstein%
4801909a1f4SAlfred PerlsteinDo you wonder what a terminal program is doing at the moment? dd(1) does not
48173132e7bSAlfred Perlsteinshow any throughput? Hit "^T" (Control + t) to send SIGINFO to the process
4821909a1f4SAlfred Perlsteinand see what it is doing.
4831909a1f4SAlfred Perlstein
4841909a1f4SAlfred Perlstein		-- Lars Engels <lme@FreeBSD.org>
4851909a1f4SAlfred Perlstein%
4861909a1f4SAlfred PerlsteinDo you want to know which version of FreeBSD you are running? Enter
4871909a1f4SAlfred Perlstein"freebsd-version -ku" to display kernel and userland version.
4881909a1f4SAlfred Perlstein
4891909a1f4SAlfred Perlstein		-- Lars Engels <lme@FreeBSD.org>
4901909a1f4SAlfred Perlstein%
4911909a1f4SAlfred PerlsteinIf you want to end one or more processes at a time using a regular expression
4921909a1f4SAlfred Perlsteinenter "pkill regex".
4931909a1f4SAlfred Perlstein
4941909a1f4SAlfred Perlstein		-- Lars Engels <lme@FreeBSD.org>
4951909a1f4SAlfred Perlstein%
4961909a1f4SAlfred PerlsteinDo you want to run a program directly after some other process has ended? Use
4971909a1f4SAlfred Perlstein"pwait pid && new_program"
4981909a1f4SAlfred Perlstein
4991909a1f4SAlfred Perlstein		-- Lars Engels <lme@FreeBSD.org>
5001909a1f4SAlfred Perlstein%
5011909a1f4SAlfred PerlsteinWhen you want your users to be able to reboot or shutdown FreeBSD, add them
5021909a1f4SAlfred Perlsteinto the group "operator" and they are allowed to use shutdown(8) and poweroff(8).
5031909a1f4SAlfred Perlstein
5041909a1f4SAlfred Perlstein		-- Lars Engels <lme@FreeBSD.org>
5051909a1f4SAlfred Perlstein%
5061909a1f4SAlfred PerlsteinIf you need to create a FAT32 formatted USB thumb drive, find out its devicename
5071909a1f4SAlfred Perlsteinrunning dmesg(8) after inserting it. Then create an MBR schema, a single slice and
5081909a1f4SAlfred Perlsteinformat it:
5091909a1f4SAlfred Perlstein
5101909a1f4SAlfred Perlstein# gpart create -s MBR ${devicename}
5111909a1f4SAlfred Perlstein# gpart add -t fat32 ${devicename}
5121909a1f4SAlfred Perlstein# newfs_msdos -F 32 -L thumbdrive ${devicename}s1
5131909a1f4SAlfred Perlstein
5141909a1f4SAlfred Perlstein		-- Lars Engels <lme@FreeBSD.org>
5151909a1f4SAlfred Perlstein%
5161909a1f4SAlfred PerlsteinIf you want to get a sorted list of all services that are started when FreeBSD boots,
5171909a1f4SAlfred Perlsteinenter "service -e".
5181909a1f4SAlfred Perlstein
5191909a1f4SAlfred Perlstein		-- Lars Engels <lme@FreeBSD.org>
5201909a1f4SAlfred Perlstein%
5211909a1f4SAlfred PerlsteinTo easily configure your installed FreeBSD use bsdconfig(8).
5221909a1f4SAlfred Perlstein
5231909a1f4SAlfred Perlstein		-- Lars Engels <lme@FreeBSD.org>
5241909a1f4SAlfred Perlstein%
5251909a1f4SAlfred PerlsteinAfter you compiled and installed a new version of FreeBSD, use etcupdate(8) to merge
5261909a1f4SAlfred Perlsteinconfiguration updates.
5271909a1f4SAlfred PerlsteinRun "etcupdate extract" once when your sources match your running system, then run
5281909a1f4SAlfred Perlstein"etcupdate" after every upgrade and "etcupdate resolve" to resolve any conflicts.
5291909a1f4SAlfred Perlstein
5301909a1f4SAlfred Perlstein		-- Lars Engels <lme@FreeBSD.org>
5311909a1f4SAlfred Perlstein%
5321909a1f4SAlfred PerlsteinDo you want to do a binary upgrade of your running FreeBSD installation? Use freebsd-update(8).
5331909a1f4SAlfred Perlstein
5341909a1f4SAlfred PerlsteinTo install updates and patches for the running branch use
5351909a1f4SAlfred Perlstein# freebsd-update fetch install
5361909a1f4SAlfred Perlstein
5371909a1f4SAlfred PerlsteinTo upgrade to a newer release use
5381909a1f4SAlfred Perlstein# freebsd-update upgrade -r ${name_of_release}
5391909a1f4SAlfred Perlstein
5401909a1f4SAlfred Perlstein		-- Lars Engels <lme@FreeBSD.org>
5411909a1f4SAlfred Perlstein%
5421909a1f4SAlfred PerlsteinTo run rc scripts in /etc/rc.d and /usr/local/etc/rc.d use service(8).
5431909a1f4SAlfred PerlsteinRun "service ${name_of_rc_script} start" to start a daemon and
5441909a1f4SAlfred Perlstein"service ${name_of_rc_script} stop" to stop it.
5451909a1f4SAlfred Perlstein
5461909a1f4SAlfred Perlstein		-- Lars Engels <lme@FreeBSD.org>
5471909a1f4SAlfred Perlstein%
5481909a1f4SAlfred PerlsteinIf you don't want to edit /etc/rc.conf directly, use sysrc(8) to add and remove entries.
5491909a1f4SAlfred PerlsteinUse "sysrc name=value" to add an entry and "sysrc -x name" to delete an entry.
5501909a1f4SAlfred Perlstein
5511909a1f4SAlfred Perlstein		-- Lars Engels <lme@FreeBSD.org>
5521909a1f4SAlfred Perlstein%
55356d417fdSBenedict ReuschlingYou can upload the dmesg of your system to help developers get an overview of commonly
55456d417fdSBenedict Reuschlingused hardware and peripherals for FreeBSD. Use the curl package to upload it like this:
555fd91f859SBenedict Reuschlingcurl -v -d "nickname=$USER" -d "description=FreeBSD/$(uname -m) on \
556fd91f859SBenedict Reuschling$(kenv smbios.system.maker) $(kenv smbios.system.product)" -d "do=addd" \
557fd91f859SBenedict Reuschling--data-urlencode 'dmesg@/var/run/dmesg.boot' http://dmesgd.nycbug.org/index.cgi
558fd91f859SBenedict Reuschling%
559a9ea96eaSBenedict ReuschlingWant to know how much memory (in bytes) your machine has installed? Let
56056d417fdSBenedict Reuschlingsysctl(8) tell you with the following command:
56156d417fdSBenedict Reuschling
562a9ea96eaSBenedict Reuschlingsysctl hw.realmem
563a9ea96eaSBenedict Reuschling
564a9ea96eaSBenedict ReuschlingThe realmem value is memory before the kernel and modules are loaded, whereas
565a9ea96eaSBenedict Reuschlinghw.physmem is what is left after they were loaded.
56656d417fdSBenedict Reuschling
56756d417fdSBenedict ReuschlingThe number of active CPUs is displayed using this command:
56856d417fdSBenedict Reuschling
56956d417fdSBenedict Reuschlingsysctl hw.ncpu
57056d417fdSBenedict Reuschling
57156d417fdSBenedict Reuschling		-- Benedict Reuschling <bcr@FreeBSD.org>
57256d417fdSBenedict Reuschling%
573a9ea96eaSBenedict ReuschlingWhen using ZFS as the file system the "df" command is reporting the pool size
574a9ea96eaSBenedict Reuschlingand not file system sizes. It also does not know about descendent ZFS
575a9ea96eaSBenedict Reuschlingdatasets, snapshots, quotas, and reservations with their individual space usage.
576a9ea96eaSBenedict ReuschlingUse the built-in "zfs list" command to get a better overview of space usage:
57756d417fdSBenedict Reuschling
57856d417fdSBenedict Reuschlingzfs list -o space
57956d417fdSBenedict Reuschling
58056d417fdSBenedict Reuschling		-- Benedict Reuschling <bcr@FreeBSD.org>
58156d417fdSBenedict Reuschling%
58256d417fdSBenedict ReuschlingTo learn more about what your system is doing, take a look at systat(1). For
5836b8f0ba8SBenedict Reuschlingexample, to get various statistics related to virtual memory usage, process
584a9ea96eaSBenedict Reuschlingscheduling, device interrupts, system name translation caching, and disk I/O,
585a9ea96eaSBenedict Reuschlingenter the following:
58656d417fdSBenedict Reuschling
587a9ea96eaSBenedict Reuschlingsystat -vmstat
58856d417fdSBenedict Reuschling
589a9ea96eaSBenedict ReuschlingOther values are icmp, icmp6, ifstat, iostat, ip, ip6, netstat, pigs, sctp,
590a9ea96eaSBenedict Reuschlingswap, tcp, or zarc. You can switch between displays using :<display> and exit
59156d417fdSBenedict Reuschlingback to your shell by typing
59256d417fdSBenedict Reuschling
59356d417fdSBenedict Reuschling:quit
59456d417fdSBenedict Reuschling
59556d417fdSBenedict Reuschling		-- Benedict Reuschling <bcr@FreeBSD.org>
59656d417fdSBenedict Reuschling%
59756d417fdSBenedict ReuschlingTo set a quota of 10 GB for the user named foo on a ZFS dataset, run the
59856d417fdSBenedict Reuschlingfollowing command:
59956d417fdSBenedict Reuschling
60056d417fdSBenedict Reuschling# zfs set userquota@foo=10G pool/home/foo
60156d417fdSBenedict Reuschling
60256d417fdSBenedict ReuschlingThe zfs userspace command can display the quota and current space usage:
60356d417fdSBenedict Reuschling
60456d417fdSBenedict Reuschling# zfs userspace pool/home/foo
60556d417fdSBenedict Reuschling
60656d417fdSBenedict ReuschlingTo unset a quota, assign "none" as the value.
60756d417fdSBenedict Reuschling		-- Benedict Reuschling <bcr@FreeBSD.org>
60856d417fdSBenedict Reuschling%
60956d417fdSBenedict ReuschlingZFS can display I/O statistics for a given pool using the iostat subcommand.
61056d417fdSBenedict ReuschlingBy default, it will display one line of current activity.  To display stats
61156d417fdSBenedict Reuschlingevery 5 seconds run the following command (cancel with CTRL+C):
61256d417fdSBenedict Reuschling
61356d417fdSBenedict Reuschlingzpool iostat 5
61456d417fdSBenedict Reuschling
61556d417fdSBenedict ReuschlingTo view individual disk activities, specify the -v parameter:
61656d417fdSBenedict Reuschling
61756d417fdSBenedict Reuschlingzpool iostat -v
61856d417fdSBenedict Reuschling
61956d417fdSBenedict ReuschlingOf course, both can be combined. For more options, see zpool(8).
62056d417fdSBenedict Reuschling		-- Benedict Reuschling <bcr@FreeBSD.org>
62156d417fdSBenedict Reuschling%
62256d417fdSBenedict ReuschlingFreeBSD's top(1) utility displays CPU statistics by default.
62356d417fdSBenedict ReuschlingTo display I/O activity for each process instead, run top like this:
62456d417fdSBenedict Reuschling
62556d417fdSBenedict Reuschlingtop -m io
62656d417fdSBenedict Reuschling
62756d417fdSBenedict Reuschling		-- Benedict Reuschling <bcr@FreeBSD.org>
62856d417fdSBenedict Reuschling%
62956d417fdSBenedict ReuschlingZFS keeps a history of commands run against a specific pool using the
63056d417fdSBenedict Reuschlinghistory subcommand to zpool:
63156d417fdSBenedict Reuschling
63256d417fdSBenedict Reuschlingzpool history
63356d417fdSBenedict Reuschling
63456d417fdSBenedict ReuschlingMore details are available using the -i and -l parameters. Note that ZFS
63556d417fdSBenedict Reuschlingwill not keep the complete pool history forever and will remove older
63656d417fdSBenedict Reuschlingevents in favor of never ones.
63756d417fdSBenedict Reuschling		-- Benedict Reuschling <bcr@FreeBSD.org>
63856d417fdSBenedict Reuschling%
63956d417fdSBenedict ReuschlingTo display the compression ratio for the ZFS dataset /var/log on the pool
64056d417fdSBenedict Reuschlingmypool, run the following command:
64156d417fdSBenedict Reuschling
64256d417fdSBenedict Reuschlingzfs get refcompressratio mypool/var/log
64356d417fdSBenedict Reuschling
64456d417fdSBenedict ReuschlingThe refcompressratio will only display the compression ratio for that specific
64556d417fdSBenedict Reuschlingdataset, not the descendant datasets. To include the child datasets, the
64656d417fdSBenedict Reuschlingcommand looks like this:
64756d417fdSBenedict Reuschling
64856d417fdSBenedict Reuschlingzfs get compressratio mypool/var
64956d417fdSBenedict Reuschling
65056d417fdSBenedict Reuschling		-- Benedict Reuschling <bcr@FreeBSD.org>
65156d417fdSBenedict Reuschling%
65256d417fdSBenedict ReuschlingYou can limit the depth of the displayed datasets in the "zfs list" output
65356d417fdSBenedict Reuschlingusing the -d parameter. To display only the first level of datasets below
65456d417fdSBenedict Reuschlingmypool/usr and not the ones deeper than those, run this command:
65556d417fdSBenedict Reuschling
65656d417fdSBenedict Reuschlingzfs list -d 1 mypool/usr
65756d417fdSBenedict Reuschling
65856d417fdSBenedict Reuschling		-- Benedict Reuschling <bcr@FreeBSD.org>
65956d417fdSBenedict Reuschling%
66056d417fdSBenedict ReuschlingThe "zfs list" command can be filtered in multiple ways. To display just
66156d417fdSBenedict Reuschlingthe dataset name, use the -o parameter:
66256d417fdSBenedict Reuschling
66356d417fdSBenedict Reuschlingzfs list -o name mypool/usr
66456d417fdSBenedict Reuschling
66556d417fdSBenedict ReuschlingMore columns and their order can be defined by separating them with commas:
66656d417fdSBenedict Reuschling
66756d417fdSBenedict Reuschlingzfs list -o mountpoint,name,avail
66856d417fdSBenedict Reuschling
66956d417fdSBenedict Reuschling		-- Benedict Reuschling <bcr@FreeBSD.org>
67056d417fdSBenedict Reuschling%
67156d417fdSBenedict ReuschlingThe output of "zfs list" can be sorted by a specific column using -s.  To
67256d417fdSBenedict Reuschlingsort the datasets by the "used" column in ascending order, run this command:
67356d417fdSBenedict Reuschling
67456d417fdSBenedict Reuschlingzfs list -s used
67556d417fdSBenedict Reuschling
67656d417fdSBenedict ReuschlingTo sort in descending order instead, use -S:
67756d417fdSBenedict Reuschling
67856d417fdSBenedict Reuschlingzfs list -S used
67956d417fdSBenedict Reuschling
68056d417fdSBenedict Reuschling		-- Benedict Reuschling <bcr@FreeBSD.org>
68156d417fdSBenedict Reuschling%
68256d417fdSBenedict ReuschlingTo make the "zfs list" output more script-friendly, you can suppress the
68356d417fdSBenedict Reuschlingoutput of the headers for each column by passing the -H parameter:
68456d417fdSBenedict Reuschling
68556d417fdSBenedict Reuschlingzfs list -H
68656d417fdSBenedict Reuschling
68756d417fdSBenedict ReuschlingAnother helpful option for script writers is -p, which displays the numbers
68856d417fdSBenedict Reuschlingin non-rounded, exact values:
68956d417fdSBenedict Reuschling
69056d417fdSBenedict Reuschlingzfs list -p
69156d417fdSBenedict Reuschling
69256d417fdSBenedict Reuschling		-- Benedict Reuschling <bcr@FreeBSD.org>
69356d417fdSBenedict Reuschling%
69456d417fdSBenedict ReuschlingBefore deleting a dataset or snapshot, perform a dry run using the -n
69556d417fdSBenedict Reuschlingparameter. This is to make sure you really want to delete just that
69656d417fdSBenedict Reuschlingdataset/snapshot and not any dependent ones. ZFS will display the resulting
69756d417fdSBenedict Reuschlingaction when -n is combined with the -v option without actually performing
69856d417fdSBenedict Reuschlingit:
69956d417fdSBenedict Reuschling
700a9ea96eaSBenedict Reuschlingzfs destroy -nrv mypool@mysnap
70156d417fdSBenedict Reuschling
70256d417fdSBenedict ReuschlingOnce you are sure this is exactly what you intend to do, remove the -n
70356d417fdSBenedict Reuschlingparameter to execute the destroy operation.
70456d417fdSBenedict Reuschling		-- Benedict Reuschling <bcr@FreeBSD.org>
70556d417fdSBenedict Reuschling%
70656d417fdSBenedict ReuschlingYou can delete a range of ZFS snapshots (a-z) in multiple ways.
70756d417fdSBenedict ReuschlingThe following will delete d and all earlier snapshots:
70856d417fdSBenedict Reuschling
70956d417fdSBenedict Reuschlingzfs destroy mypool/data@%d
71056d417fdSBenedict Reuschling
71156d417fdSBenedict ReuschlingTo delete d and all later snapshots:
71256d417fdSBenedict Reuschling
71356d417fdSBenedict Reuschlingzfs destroy mypool/data@d%
71456d417fdSBenedict Reuschling
71556d417fdSBenedict ReuschlingTo delete all dataset snapshots:
71656d417fdSBenedict Reuschling
71756d417fdSBenedict Reuschlingzfs destroy mypool/data@%
71856d417fdSBenedict Reuschling
71956d417fdSBenedict ReuschlingMake sure to let ZFS perform a dry run (-n option) first and display (-v) what
72056d417fdSBenedict Reuschlingit would do to confirm that the delete operation is removing exactly what you
72156d417fdSBenedict Reuschlingintended.
72256d417fdSBenedict Reuschling		-- Benedict Reuschling <bcr@FreeBSD.org>
72356d417fdSBenedict Reuschling%
72456d417fdSBenedict ReuschlingTo set a custom ZFS property on the mypool pool, you need to provide it
72556d417fdSBenedict Reuschlingusing the "key1:key2=value" syntax, where the colon (:) is used as the
72656d417fdSBenedict Reuschlingseparator and identifier from the built-in ZFS properties:
72756d417fdSBenedict Reuschling
72856d417fdSBenedict Reuschling# zfs set warranty:expires=2038-01-19 mypool
72956d417fdSBenedict Reuschling
73056d417fdSBenedict ReuschlingThe custom property is applied to all datasets and can be queried like any
73156d417fdSBenedict Reuschlingbuilt-in properties using zfs get:
73256d417fdSBenedict Reuschling
73356d417fdSBenedict Reuschlingzfs get warranty:expires mypool
73456d417fdSBenedict Reuschling
73556d417fdSBenedict ReuschlingTo reset the value of a custom property, use the inherit subcommand:
73656d417fdSBenedict Reuschling
73756d417fdSBenedict Reuschling# zfs inherit warranty:expires mypool
73856d417fdSBenedict Reuschling
73956d417fdSBenedict ReuschlingRemoving a custom property from a pool is done using the -r flag to the
74056d417fdSBenedict Reuschling"zfs inherit" command:
74156d417fdSBenedict Reuschling
74256d417fdSBenedict Reuschling# zfs inherit -r warranty:expires mypool
74356d417fdSBenedict Reuschling
74456d417fdSBenedict Reuschling		-- Benedict Reuschling <bcr@FreeBSD.org>
74556d417fdSBenedict Reuschling%
74656d417fdSBenedict ReuschlingTo delete a range of ZFS snapshots, use the % (percent) character after the
74756d417fdSBenedict Reuschlingfull path to the first snapshot that should be included. For example, to
74856d417fdSBenedict Reuschlingsimulate deleting snapshots a through (including) d, use this command:
74956d417fdSBenedict Reuschling
75056d417fdSBenedict Reuschling# zfs destroy -rvn mypool/tmp@a%d
75156d417fdSBenedict Reuschling
75256d417fdSBenedict ReuschlingOnce you are sure that this is what you want, remove the -n option:
75356d417fdSBenedict Reuschling
75456d417fdSBenedict Reuschling# zfs destroy -rv mypool/tmp@a%d
75556d417fdSBenedict Reuschling
75656d417fdSBenedict Reuschling		-- Benedict Reuschling <bcr@FreeBSD.org>
75756d417fdSBenedict Reuschling%
75856d417fdSBenedict ReuschlingYou can prevent the removal of a ZFS snapshot by using the hold subcommand.
75956d417fdSBenedict ReuschlingFor example, to prevent the snapshot called milestone from deletion, run the
76056d417fdSBenedict Reuschlingfollowing command:
76156d417fdSBenedict Reuschling
76256d417fdSBenedict Reuschling# zfs hold milestone_hold mypool/projects@my_milestone
76356d417fdSBenedict Reuschling
76456d417fdSBenedict ReuschlingThe "zfs holds" command will list all current snapshots that are protected
76556d417fdSBenedict Reuschlingthis way (-r for a recursive list):
76656d417fdSBenedict Reuschling
76756d417fdSBenedict Reuschling# zfs holds -r mypool
76856d417fdSBenedict Reuschling
76956d417fdSBenedict ReuschlingThe TIMESTAMP column in the output of the above command is from when the
77056d417fdSBenedict Reuschlinghold was created, not the snapshot it holds. The "zfs destroy" command will
77156d417fdSBenedict Reuschlingecho a "dataset is busy" message on the console when it encounters a hold.
77256d417fdSBenedict ReuschlingUse "zfs release" to release the hold on the snapshot:
77356d417fdSBenedict Reuschling
77456d417fdSBenedict Reuschling# zfs release milestone_hold mypool/projects@my_milestone
77556d417fdSBenedict Reuschling
77656d417fdSBenedict Reuschling		-- Benedict Reuschling <bcr@FreeBSD.org>
77756d417fdSBenedict Reuschling%
77856d417fdSBenedict ReuschlingA user "sender" needs the following permissions set to send a ZFS dataset:
77956d417fdSBenedict Reuschling
78056d417fdSBenedict Reuschling# zfs allow -u sender send,snapshot txpool
78156d417fdSBenedict Reuschling
78256d417fdSBenedict ReuschlingOn the receiving side, the user "receiver" requires these permissions:
78356d417fdSBenedict Reuschling
78456d417fdSBenedict Reuschling# zfs allow -u receiver compression,mountpoint,mount,create,receive rxpool
78556d417fdSBenedict Reuschling
78656d417fdSBenedict Reuschling		-- Benedict Reuschling <bcr@FreeBSD.org>
78756d417fdSBenedict Reuschling%
78856d417fdSBenedict ReuschlingDon't let your zpool fill up completely by creating a dataset with
78956d417fdSBenedict Reuschlingreservation.
79056d417fdSBenedict Reuschling
79156d417fdSBenedict Reuschling# zfs create -o refreservation=<5% of total pool space> <poolname>/reserved
79256d417fdSBenedict Reuschling
79356d417fdSBenedict ReuschlingYou can always shrink the reserve if you need the space, but your pool will
79456d417fdSBenedict Reuschlingalways have space left this way.
79556d417fdSBenedict Reuschling
79656d417fdSBenedict Reuschling		-- Benedict Reuschling <bcr@FreeBSD.org>
79756d417fdSBenedict Reuschling%
79854781763SDaniel Ebdrup JensenSometimes a single slow HDD can cripple the performance of your entire system.
79954781763SDaniel Ebdrup JensenYou can spot one like this:
80060a632f0SAlan Somers
80160a632f0SAlan Somers# gstat -I5s | sort -rn -k9 | head
80260a632f0SAlan Somers
80360a632f0SAlan Somers		-- Alan Somers <asomers@FreeBSD.org>
80460a632f0SAlan Somers%
805646bae45SDaniel Ebdrup JensenFreeBSD's ps(1) can create a dependency tree based on parent/child
806646bae45SDaniel Ebdrup Jensenrelationships between processes, like this:
807c2a39987SDaniel Ebdrup Jensen
808c2a39987SDaniel Ebdrup Jensen$ ps -d
809c2a39987SDaniel Ebdrup Jensen
810c2a39987SDaniel Ebdrup Jensen		-- Daniel Ebdrup Jensen <debdrup@FreeBSD.org>
811c2a39987SDaniel Ebdrup Jensen%
812646bae45SDaniel Ebdrup JensenIt is possible to measure the resident memory set:
813c2a39987SDaniel Ebdrup Jensen
814c2a39987SDaniel Ebdrup Jensen$ vmstat -o | awk 'NR>1 { t[$7] += $1 } \
815c2a39987SDaniel Ebdrup JensenEND { for (i in t) printf "%s %d\n",i,t[i] }'
816c2a39987SDaniel Ebdrup Jensen
817c2a39987SDaniel Ebdrup JensenThe rows have the following meaning:
818c2a39987SDaniel Ebdrup Jensendf = default (not assigned a specific pager)
819c2a39987SDaniel Ebdrup Jensensw = swap
820c2a39987SDaniel Ebdrup Jensendf = virtual
821c2a39987SDaniel Ebdrup Jensenvn = vnode
822c2a39987SDaniel Ebdrup Jensenph = heap
823c2a39987SDaniel Ebdrup Jensenmd = memory device
824c2a39987SDaniel Ebdrup Jensen
825c2a39987SDaniel Ebdrup JensenThis will be reported in number of pages, so it needs to be multiplied by the
826c2a39987SDaniel Ebdrup Jensenpage size of the architecture which can be found via:
827c2a39987SDaniel Ebdrup Jensen
828c2a39987SDaniel Ebdrup Jensen$ sysctl -n hw.pagesize
829c2a39987SDaniel Ebdrup Jensen
830c2a39987SDaniel Ebdrup Jensen		-- Daniel Ebdrup Jensen <debdrup@FreeBSD.org>
831c2a39987SDaniel Ebdrup Jensen%
832c2a39987SDaniel Ebdrup JensenTo establish a serial connection to anything including a USB device,
833c2a39987SDaniel Ebdrup Jensennothing more than cu(1) is needed:
834c2a39987SDaniel Ebdrup Jensen
835c2a39987SDaniel Ebdrup Jensen$ cu -s 9600 -l /dev/ttyU0
836c2a39987SDaniel Ebdrup Jensen
837c2a39987SDaniel Ebdrup Jensen		-- Daniel Ebdrup Jensen <debdrup@FreeBSD.org>
838c2a39987SDaniel Ebdrup Jensen%
839*278e3700SMichael GmelinYou can control kernel stack(9) traces on ^T (tty info) by setting
840*278e3700SMichael Gmelinkern.tty_info_kstacks to 0 (off), 1 (on), or 2 (verbose), e.g.:
841*278e3700SMichael Gmelin
842*278e3700SMichael Gmelin# sysctl kern.tty_info_kstacks=2
843*278e3700SMichael Gmelin
844*278e3700SMichael Gmelin		-- Michael Gmelin <grembo@FreeBSD.org>
845*278e3700SMichael Gmelin%
846