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