]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.bin/fortune/datfiles/freebsd-tips
Merge llvm-project release/16.x llvmorg-16.0.1-0-gcd89023f7979
[FreeBSD/FreeBSD.git] / usr.bin / fortune / datfiles / freebsd-tips
1 Any user that is a member of the wheel group can use "su -" to simulate
2 a root login. You can add a user to the wheel group with:
3 pw groupmod -n wheel -m user_name 
4                 -- Konstantinos Konstantinidis <kkonstan@duth.gr>
5 %
6 By pressing "Scroll Lock" you can use the arrow keys to scroll backward
7 through the console output.  Press "Scroll Lock" again to turn it off.
8 Don't have a "Scroll Lock" key? The "Pause / Break" key acts alike.
9 %
10 Can't remember if you've installed a certain port or not? Try "pkg info
11 -x port_name".
12 %
13 Ever wonder what those numbers after command names were, as in cat(1)?  It's
14 the section of the manual the man page is in.  "man man" will tell you more.
15                 -- David Scheidt <dscheidt@tumbolia.com>
16 %
17 Forget how to spell a word or a variation of a word? Use
18
19         look portion_of_word_you_know
20                 -- Dru <genesis@istar.ca>
21 %
22 Forget what directory you are in? Type "pwd".
23                 -- Dru <genesis@istar.ca>
24 %
25 Forget when Easter is? Try "ncal -e". If you need the date for Orthodox
26 Easter, use "ncal -o" instead.
27                 -- Dru <genesis@istar.ca>
28 %
29 FreeBSD is started up by the program 'init'.  The first thing init does when
30 starting multiuser mode (ie, starting the computer up for normal use) is to
31 run the shell script /etc/rc.  By reading /etc/rc and the /etc/rc.d/ scripts,
32 you can learn a lot about how the system is put together, which again will
33 make you more confident about what happens when you do something with it.
34 %
35 Handy bash(1) prompt:  PS1="\u@\h \w \!$ "
36                 -- David Scheidt <dscheidt@tumbolia.com>
37 %
38 Having trouble using fetch through a firewall? Try setting the environment
39 variable FTP_PASSIVE_MODE to yes, and see fetch(3) for more details.
40 %
41 If other operating systems have damaged your Master Boot Record, you can
42 reinstall it with gpart(8). See
43 "man gpart" for details.
44 %
45 If you accidentally end up inside vi, you can quit it by pressing Escape, colon
46 (:), q (q), bang (!) and pressing return.
47 %
48 If you do not want to get beeps in X11 (X Windows), you can turn them off with
49
50         xset b off
51 %
52 If you have a CD-ROM drive in your machine, you can make the CD-ROM that is
53 presently inserted available by typing 'mount /cdrom' as root.  The CD-ROM
54 will be available under /cdrom/.  Remember to do 'umount /cdrom' before
55 removing the CD-ROM (it will usually not be possible to remove the CD-ROM
56 without doing this.)
57
58 Note: This tip may not work in all configurations.
59 %
60 If you need a reminder to leave your terminal, type "leave +hhmm" where
61 "hhmm" represents in how many hours and minutes you need to leave.
62                 -- Dru <genesis@istar.ca>
63 %
64 If you need to ask a question on the FreeBSD-questions mailing list then
65
66         https://docs.freebsd.org/en/articles/freebsd-questions
67
68 contains lots of useful advice to help you get the best results.
69 %
70 If you write part of a filename in tcsh,
71 pressing TAB will show you the available choices when there
72 is more than one, or complete the filename if there's only one match.
73 %
74 If you `set watch = (0 any any)' in tcsh, you will be notified when
75 someone logs in or out of your system.
76 %
77 If you use the C shell, add the following line to the .cshrc file in your
78 home directory to prevent core files from being written to disk:
79
80         limit coredumpsize 0
81                 -- Dru <genesis@istar.ca>
82 %
83 If you want df(1) and other commands to display disk sizes in
84 kilobytes instead of 512-byte blocks, set BLOCKSIZE in your
85 environment to 'K'.  You can also use 'M' for Megabytes or 'G' for
86 Gigabytes.  If you want df(1) to automatically select the best size
87 then use 'df -h'.
88 %
89 If you want to play CDs with FreeBSD, a utility for this is already included.
90 Type 'cdcontrol' then 'help' to learn more.  (You may need to set the CDROM
91 environment variable in order to make cdcontrol want to start.)
92 %
93 If you'd like to keep track of applications in the FreeBSD ports tree, take a
94 look at FreshPorts;
95
96         https://www.freshports.org/
97 %
98 In order to make fetch (the FreeBSD downloading tool) ask for
99 username/password when it encounters a password-protected web page, you can set
100 the environment variable HTTP_AUTH to 'basic:*'.
101 %
102 In order to search for a string in some files, use 'grep' like this:
103
104          grep "string" filename1 [filename2 filename3 ...]
105
106 This will print out the lines in the files that contain the string.  grep can
107 also do a lot more advanced searches - type 'man grep' for details.
108 %
109 In order to support national characters for European languages in tools like
110 less without creating other nationalisation aspects, set the environment
111 variable LC_ALL to 'en_US.UTF-8'.
112 %
113 "man firewall" will give advice for building a FreeBSD firewall using ipfw(8).
114                 -- David Scheidt <dscheidt@tumbolia.com>
115 %
116 "man hier" will explain the way FreeBSD filesystems are normally laid out.
117                 -- David Scheidt <dscheidt@tumbolia.com>
118 %
119 Man pages are divided into section depending on topic.  There are 9 different
120 sections numbered from 1 (General Commands) to 9 (Kernel Developer's Manual).
121 You can get an introduction to each topic by typing
122
123         man <number> intro
124
125 In other words, to get the intro to general commands, type
126
127         man 1 intro
128 %
129 "man ports" gives many useful hints about installing FreeBSD ports.
130 %
131 "man security" gives very good advice on how to tune the security of your
132 FreeBSD system.
133 %
134 "man tuning" gives some tips how to tune performance of your FreeBSD system.
135                 -- David Scheidt <dscheidt@tumbolia.com>
136 %
137 Need to do a search in a manpage or in a file you've sent to a pager? Use
138 "/search_word". To repeat the same search, type "n" for next or "p" for
139 previous.
140                 -- Dru <genesis@istar.ca>
141 %
142 Need to find the location of a program? Use "locate program_name".
143                 -- Dru <genesis@istar.ca>
144 %
145 Need to leave your terminal for a few minutes and don't want to logout?
146 Use "lock -p". When you return, use your password as the key to unlock the
147 terminal.
148                 -- Dru <genesis@istar.ca>
149 %
150 Need to quickly empty a file? Use ": > filename".
151                 -- Dru <genesis@istar.ca>
152 %
153 Need to quickly return to your home directory? Type "cd".
154                 -- Dru <genesis@istar.ca>
155 %
156 Need to remove all those ^M characters from a DOS file? Try
157
158         tr -d \\r < dosfile > newfile
159                 -- Originally by Dru <genesis@istar.ca>
160 %
161 Need to see the calendar for this month? Simply type "cal".  To see the
162 whole year, type "cal -y".
163                 -- Dru <genesis@istar.ca>
164 %
165 Need to see which daemons are listening for connection requests? Use
166 "sockstat -4l" for IPv4, and "sockstat -l" for IPv4 and IPv6.
167                 -- Dru <genesis@istar.ca>
168 %
169 Need to see your routing table? Type "netstat -rn". The entry with the G
170 flag is your gateway.
171                 -- Dru <genesis@istar.ca>
172 %
173 Nice bash prompt: PS1='(\[$(tput md)\]\t <\w>\[$(tput me)\]) $(echo $?) \$ '
174                 -- Mathieu <mathieu@hal.interactionvirtuelle.com>
175 %
176 Over quota?  "du -sh * | sort -h " will give you a sorted list of your
177 directory sizes.
178                 -- David Scheidt <dscheidt@tumbolia.com>
179 %
180 nc(1) (or netcat) is useful not only for redirecting input/output to
181 TCP or UDP connections, but also for proxying them with inetd(8).
182 %
183 sh (the default Bourne shell in FreeBSD) supports command-line editing.  Just
184 ``set -o emacs'' or ``set -o vi'' to enable it. Use "<TAB>" key to complete
185 paths.
186 %
187 Simple tcsh prompt: set prompt = '%# '
188 %
189 The default editor in FreeBSD is vi, which is efficient to use when you have
190 learned it, but somewhat user-unfriendly.  To use ee (an easier but less
191 powerful editor) instead, set the environment variable EDITOR to /usr/bin/ee
192 %
193 Time to change your password? Type "passwd" and follow the prompts.
194                 -- Dru <genesis@istar.ca>
195 %
196 To change an environment variable in /bin/sh use:
197
198         $ VARIABLE="value"
199         $ export VARIABLE
200 %
201 To change an environment variable in tcsh you use: setenv NAME "value"
202 where NAME is the name of the variable and "value" its new value.
203 %
204 To clear the screen, use "clear". To re-display your screen buffer, press
205 the scroll lock key and use your page up button. When you're finished,
206 press the scroll lock key again to get your prompt back.
207                 -- Dru <genesis@istar.ca>
208 %
209 You can press Ctrl-L while in the shell to clear the screen.
210 %
211 To determine whether a file is a text file, executable, or some other type
212 of file, use
213
214         file filename
215                 -- Dru <genesis@istar.ca>
216 %
217 To do a fast search for a file, try
218
219          locate filename
220
221 locate uses a database that is updated every Saturday (assuming your computer
222 is running FreeBSD at the time) to quickly find files based on name only.
223 %
224 To erase a line you've written at the command prompt, use "Ctrl-U".
225                 -- Dru <genesis@istar.ca>
226 %
227 To find out the hostname associated with an IP address, use
228
229         drill -x IP_address
230                 -- Dru <genesis@istar.ca>
231 %
232 To obtain a neat PostScript rendering of a manual page, use ``-t'' switch
233 of the man(1) utility: ``man -t <topic>''.  For example:
234
235         man -t grep > grep.ps   # Save the PostScript version to a file
236 or
237         man -t printf | lp      # Send the PostScript directly to printer
238 %
239 To quickly create an empty file, use "touch filename".
240                 -- Dru <genesis@istar.ca>
241 %
242 To read a compressed file without having to first uncompress it, use
243 "zcat" or "zless" to view it. There is also "bzcat", "bzless", "xzcat"
244 and "xzless".
245                 -- Dru <genesis@istar.ca>
246 %
247 To save disk space in your home directory, compress files you rarely
248 use with "gzip filename".
249                 -- Dru <genesis@istar.ca>
250 %
251 To search for files that match a particular name, use find(1); for example
252
253         find / -name "*GENERIC*" -ls
254
255 will search '/', and all subdirectories, for files with 'GENERIC' in the name.
256         --  Stephen Hilton <nospam@hiltonbsd.com>
257 %
258 To see all of the directories on your FreeBSD system, type
259
260         find / -type d | less
261
262 All the files?
263
264         find / -type f | less
265 %
266 To see how long it takes a command to run, type the word "time" before the
267 command name.
268                 -- Dru <genesis@istar.ca>
269 %
270 To see how much disk space is left on your UFS partitions, use
271
272         df -h
273                 -- Dru <genesis@istar.ca>
274 %
275 To see the 10 largest files in a directory or on a UFS partition, use
276
277         du -h /partition_or_directory_name | sort -rh | head
278                 -- Dru <genesis@istar.ca>
279 %
280 To see the IP addresses currently set on your active interfaces, type
281 "ifconfig -u".
282                 -- Dru <genesis@istar.ca>
283 %
284 To see the last 10 lines of a long file, use "tail filename". To see the
285 first 10 lines, use "head filename". To see new lines as they're appended
286 to a file, use "tail -f filename".
287                 -- Dru <genesis@istar.ca>
288 %
289 To see the last time that you logged in, use lastlogin(8).
290                 -- Dru <genesis@istar.ca>
291 %
292 To see the MAC addresses of the NICs on your system, type
293
294         ifconfig -a
295                 -- Dru <genesis@istar.ca>
296 %
297 To see the output from when your computer started, run dmesg(8).  If it has
298 been replaced with other messages, look at /var/run/dmesg.boot.
299                 -- Francisco Reyes <lists@natserv.com>
300 %
301 Want colour in your directory listings?  Use "ls -G".  "ls -F" is also useful,
302 and they can be combined as "ls -FG".
303 %
304 Want to find a specific port? Just type the following under /usr/ports
305 or one of its subdirectories:
306
307         make search name=<port-name>
308     or
309         make search key=<keyword>
310 %
311 Want to know how many words, lines, or bytes are contained in a file? Type
312 "wc filename".
313                 -- Dru <genesis@istar.ca>
314 %
315 Want to see how much virtual memory you're using? Just type "swapinfo" to
316 be shown information about the usage of your swap partitions.
317 %
318 Want to strip UTF-8 BOM(Byte Order Mark) from given files?
319
320         sed -e '1s/^\xef\xbb\xbf//' < bomfile > newfile
321 %
322 Want to use sed(1) to edit a file in place?  Well, to replace every 'e' with
323 an 'o', in a file named 'foo', you can do:
324
325         sed -i.bak s/e/o/g foo
326
327 And you'll get a backup of the original in a file named 'foo.bak', but if you
328 want no backup:
329
330         sed -i '' s/e/o/g foo
331 %
332 When you've made modifications to a file in vi(1) and then find that
333 you can't write it, type ``<ESC>!rm -f %'' then ``:w!'' to force the
334 write
335
336 This won't work if you don't have write permissions to the directory
337 and probably won't be suitable if you're editing through a symbolic link.
338
339 If you have sudo(8) installed and permissions to use it, type
340 ``<ESC>w ! sudo tee %'' to force a write.
341 %
342 You can adjust the volume of various parts of the sound system in your
343 computer by typing 'mixer <type>.volume=<volume>%'.  To get a list of what
344 you can adjust, just type 'mixer'.
345 %
346 You can automatically download and install binary packages by doing
347
348         pkg install <package>
349
350 This will also automatically install the packages that are dependencies
351 for the package you install (ie, the packages it needs in order to work.)
352 %
353 You can change the video mode on all consoles by adding something like
354 the following to /etc/rc.conf:
355
356         allscreens="80x30"
357
358 You can use "vidcontrol -i mode | grep T" for a list of supported text
359 modes.
360                 -- Konstantinos Konstantinidis <kkonstan@duth.gr>
361 %
362 You can disable tcsh's terminal beep if you `set nobeep'.
363 %
364 You can install extra packages for FreeBSD by using the ports system.
365 If you have installed it, you can download, compile, and install software by
366 just typing
367
368         # cd /usr/ports/<category>/<portname>
369         # make install && make clean
370
371 as root.  The ports infrastructure will download the software, change it so
372 it works on FreeBSD, compile it, install it, register the installation so it
373 will be possible to automatically uninstall it, and clean out the temporary
374 working space it used.  You can remove an installed port you decide you do not
375 want after all by typing
376
377         # cd /usr/ports/<category>/<portname>
378         # make deinstall
379
380 as root.
381 %
382 You can look through a file in a nice text-based interface by typing
383
384         less filename
385 %
386 You can make a log of your terminal session with script(1).
387 %
388 You can often get answers to your questions about FreeBSD by searching in the
389 FreeBSD mailing list archives at
390
391         http://freebsd.markmail.org
392 %
393 You can open up a new split-screen window in (n)vi with :N or :E and then
394 use ^w to switch between the two.
395 %
396 You can permanently set environment variables for your shell by putting them
397 in a startup file for the shell.  The name of the startup file varies
398 depending on the shell - csh and tcsh uses .login, bash, sh, ksh and zsh use
399 .profile.  When using bash, sh, ksh or zsh, don't forget to export the
400 variable.
401 %
402 You can press Ctrl-D to quickly exit from a shell, or logout from a
403 login shell.
404                 -- Konstantinos Konstantinidis <kkonstan@duth.gr>
405 %
406 You can press up-arrow or down-arrow to walk through a list of
407 previous commands in tcsh.
408 %
409 You can search for documentation on a keyword by typing
410
411         apropos keyword
412 %
413 You can `set autologout = 30' to have tcsh log you off automatically
414 if you leave the shell idle for more than 30 minutes.
415 %
416 You can use aliases to decrease the amount of typing you need to do to get
417 commands you commonly use.  Examples of fairly popular aliases include (in
418 Bourne shell style, as in /bin/sh, bash, ksh, and zsh):
419
420         alias lf="ls -FA"
421         alias ll="ls -lA"
422         alias su="su -m"
423
424 In csh or tcsh, these would be
425
426         alias lf ls -FA
427         alias ll ls -lA
428         alias su su -m
429
430 To remove an alias, you can usually use 'unalias aliasname'.  To list all
431 aliases, you can usually type just 'alias'.
432 %
433 You can use /etc/make.conf to control the options used to compile software
434 on this system.  Example entries are in
435 /usr/share/examples/etc/make.conf and in make.conf(5).
436 For options that are set for building FreeBSD's kernel and its world, see
437 src.conf(5).
438 %
439 You can use "pkg info" to see a list of packages you have installed.
440 %
441 You can use the 'fetch' command to retrieve files over ftp, http or https.
442
443          fetch https://www.FreeBSD.org/images/beastie.png
444
445 will download the beastie image from the FreeBSD web site.
446 %
447 You can use "whereis" to search standard binary, manual page and source
448 directories for the specified programs. This can be particularly handy
449 when you are trying to find where in the ports tree an application is.
450
451 Try "whereis firefox" and "whereis whereis".
452                 -- Konstantinos Konstantinidis <kkonstan@duth.gr>
453 %
454 Want to run the same command again?
455 In many shells (e.g., tcsh, zsh, bash) you can type "!!".
456 %
457 Want to go the directory you were just in?
458 Type "cd -"
459 %
460 Can't delete /usr/obj? Enter "chflags -R noschg /usr/obj" to remove the
461 system immutable flag for all files in /usr/obj.
462
463                 -- Lars Engels <lme@FreeBSD.org>
464 %
465 Want to list all files of an installed package? Enter
466 "pkg info -l packagename".
467
468                 -- Lars Engels <lme@FreeBSD.org>
469 %
470 Are you looking for a package? Search for it with
471 "pkg search part_of_package_name"
472
473                 -- Lars Engels <lme@FreeBSD.org>
474 %
475 If you want to recursively copy a directory preserving file and directory
476 attributes use
477 "cp -a source target"
478
479                 -- Lars Engels <lme@FreeBSD.org>
480 %
481 Do you wonder what a terminal program is doing at the moment? dd(1) does not
482 show any throughput? Hit "^T" (Control + t) to send SIGINFO to the process
483 and see what it is doing.
484
485                 -- Lars Engels <lme@FreeBSD.org>
486 %
487 Do you want to know which version of FreeBSD you are running? Enter
488 "freebsd-version -ku" to display kernel and userland version.
489
490                 -- Lars Engels <lme@FreeBSD.org>
491 %
492 If you want to end one or more processes at a time using a regular expression
493 enter "pkill regex".
494
495                 -- Lars Engels <lme@FreeBSD.org>
496 %
497 Do you want to run a program directly after some other process has ended? Use
498 "pwait pid && new_program"
499
500                 -- Lars Engels <lme@FreeBSD.org>
501 %
502 When you want your users to be able to reboot or shutdown FreeBSD, add them
503 to the group "operator" and they are allowed to use shutdown(8) and poweroff(8).
504
505                 -- Lars Engels <lme@FreeBSD.org>
506 %
507 If you need to create a FAT32 formatted USB thumb drive, find out its devicename
508 running dmesg(8) after inserting it. Then create an MBR schema, a single slice and
509 format it:
510
511 # gpart create -s MBR ${devicename}
512 # gpart add -t fat32 ${devicename}
513 # newfs_msdos -F 32 -L thumbdrive ${devicename}s1
514
515                 -- Lars Engels <lme@FreeBSD.org>
516 %
517 If you want to get a sorted list of all services that are started when FreeBSD boots,
518 enter "service -e".
519
520                 -- Lars Engels <lme@FreeBSD.org>
521 %
522 To easily configure your installed FreeBSD use bsdconfig(8).
523
524                 -- Lars Engels <lme@FreeBSD.org>
525 %
526 After you compiled and installed a new version of FreeBSD, use etcupdate(8) to merge
527 configuration updates.
528 Run "etcupdate extract" once when your sources match your running system, then run
529 "etcupdate" after every upgrade and "etcupdate resolve" to resolve any conflicts.
530
531                 -- Lars Engels <lme@FreeBSD.org>
532 %
533 Do you want to do a binary upgrade of your running FreeBSD installation? Use freebsd-update(8).
534
535 To install updates and patches for the running branch use
536 # freebsd-update fetch install
537
538 To upgrade to a newer release use
539 # freebsd-update upgrade -r ${name_of_release}
540
541                 -- Lars Engels <lme@FreeBSD.org>
542 %
543 To run rc scripts in /etc/rc.d and /usr/local/etc/rc.d use service(8).
544 Run "service ${name_of_rc_script} start" to start a daemon and
545 "service ${name_of_rc_script} stop" to stop it.
546
547                 -- Lars Engels <lme@FreeBSD.org>
548 %
549 If you don't want to edit /etc/rc.conf directly, use sysrc(8) to add and remove entries.
550 Use "sysrc name=value" to add an entry and "sysrc -x name" to delete an entry.
551
552                 -- Lars Engels <lme@FreeBSD.org>
553 %
554 You can upload the dmesg of your system to help developers get an overview of commonly
555 used hardware and peripherals for FreeBSD. Use the curl package to upload it like this:
556 curl -v -d "nickname=$USER" -d "description=FreeBSD/$(uname -m) on \
557 $(kenv smbios.system.maker) $(kenv smbios.system.product)" -d "do=addd" \
558 --data-urlencode 'dmesg@/var/run/dmesg.boot' http://dmesgd.nycbug.org/index.cgi
559 %
560 Want to know how much memory (in bytes) your machine has installed? Let
561 sysctl(8) tell you with the following command:
562
563 sysctl hw.realmem
564
565 The realmem value is memory before the kernel and modules are loaded, whereas
566 hw.physmem is what is left after they were loaded.
567
568 The number of active CPUs is displayed using this command:
569
570 sysctl hw.ncpu
571
572                 -- Benedict Reuschling <bcr@FreeBSD.org>
573 %
574 When using ZFS as the file system the "df" command is reporting the pool size
575 and not file system sizes. It also does not know about descendent ZFS
576 datasets, snapshots, quotas, and reservations with their individual space usage.
577 Use the built-in "zfs list" command to get a better overview of space usage:
578
579 zfs list -o space
580
581                 -- Benedict Reuschling <bcr@FreeBSD.org>
582 %
583 To learn more about what your system is doing, take a look at systat(1). For
584 example, to get various statistics related to virtual memory usage, process
585 scheduling, device interrupts, system name translation caching, and disk I/O,
586 enter the following:
587
588 systat -vmstat
589
590 Other values are icmp, icmp6, ifstat, iostat, ip, ip6, netstat, pigs, sctp,
591 swap, tcp, or zarc. You can switch between displays using :<display> and exit
592 back to your shell by typing
593
594 :quit
595
596                 -- Benedict Reuschling <bcr@FreeBSD.org>
597 %
598 To set a quota of 10 GB for the user named foo on a ZFS dataset, run the
599 following command:
600
601 # zfs set userquota@foo=10G pool/home/foo
602
603 The zfs userspace command can display the quota and current space usage:
604
605 # zfs userspace pool/home/foo
606
607 To unset a quota, assign "none" as the value.
608                 -- Benedict Reuschling <bcr@FreeBSD.org>
609 %
610 ZFS can display I/O statistics for a given pool using the iostat subcommand.
611 By default, it will display one line of current activity.  To display stats
612 every 5 seconds run the following command (cancel with CTRL+C):
613
614 zpool iostat 5
615
616 To view individual disk activities, specify the -v parameter:
617
618 zpool iostat -v
619
620 Of course, both can be combined. For more options, see zpool(8).
621                 -- Benedict Reuschling <bcr@FreeBSD.org>
622 %
623 FreeBSD's top(1) utility displays CPU statistics by default.
624 To display I/O activity for each process instead, run top like this:
625
626 top -m io
627
628                 -- Benedict Reuschling <bcr@FreeBSD.org>
629 %
630 ZFS keeps a history of commands run against a specific pool using the
631 history subcommand to zpool:
632
633 zpool history
634
635 More details are available using the -i and -l parameters. Note that ZFS
636 will not keep the complete pool history forever and will remove older
637 events in favor of never ones.
638                 -- Benedict Reuschling <bcr@FreeBSD.org>
639 %
640 To display the compression ratio for the ZFS dataset /var/log on the pool
641 mypool, run the following command:
642
643 zfs get refcompressratio mypool/var/log
644
645 The refcompressratio will only display the compression ratio for that specific
646 dataset, not the descendant datasets. To include the child datasets, the
647 command looks like this:
648
649 zfs get compressratio mypool/var
650
651                 -- Benedict Reuschling <bcr@FreeBSD.org>
652 %
653 You can limit the depth of the displayed datasets in the "zfs list" output
654 using the -d parameter. To display only the first level of datasets below
655 mypool/usr and not the ones deeper than those, run this command:
656
657 zfs list -d 1 mypool/usr
658
659                 -- Benedict Reuschling <bcr@FreeBSD.org>
660 %
661 The "zfs list" command can be filtered in multiple ways. To display just
662 the dataset name, use the -o parameter:
663
664 zfs list -o name mypool/usr
665
666 More columns and their order can be defined by separating them with commas:
667
668 zfs list -o mountpoint,name,avail
669
670                 -- Benedict Reuschling <bcr@FreeBSD.org>
671 %
672 The output of "zfs list" can be sorted by a specific column using -s.  To
673 sort the datasets by the "used" column in ascending order, run this command:
674
675 zfs list -s used
676
677 To sort in descending order instead, use -S:
678
679 zfs list -S used
680
681                 -- Benedict Reuschling <bcr@FreeBSD.org>
682 %
683 To make the "zfs list" output more script-friendly, you can suppress the
684 output of the headers for each column by passing the -H parameter:
685
686 zfs list -H
687
688 Another helpful option for script writers is -p, which displays the numbers
689 in non-rounded, exact values:
690
691 zfs list -p
692
693                 -- Benedict Reuschling <bcr@FreeBSD.org>
694 %
695 Before deleting a dataset or snapshot, perform a dry run using the -n
696 parameter. This is to make sure you really want to delete just that
697 dataset/snapshot and not any dependent ones. ZFS will display the resulting
698 action when -n is combined with the -v option without actually performing
699 it:
700
701 zfs destroy -nrv mypool@mysnap
702
703 Once you are sure this is exactly what you intend to do, remove the -n
704 parameter to execute the destroy operation.
705                 -- Benedict Reuschling <bcr@FreeBSD.org>
706 %
707 You can delete a range of ZFS snapshots (a-z) in multiple ways.
708 The following will delete d and all earlier snapshots:
709
710 zfs destroy mypool/data@%d
711
712 To delete d and all later snapshots:
713
714 zfs destroy mypool/data@d%
715
716 To delete all dataset snapshots:
717
718 zfs destroy mypool/data@%
719
720 Make sure to let ZFS perform a dry run (-n option) first and display (-v) what
721 it would do to confirm that the delete operation is removing exactly what you
722 intended.
723                 -- Benedict Reuschling <bcr@FreeBSD.org>
724 %
725 To set a custom ZFS property on the mypool pool, you need to provide it
726 using the "key1:key2=value" syntax, where the colon (:) is used as the
727 separator and identifier from the built-in ZFS properties:
728
729 # zfs set warranty:expires=2038-01-19 mypool
730
731 The custom property is applied to all datasets and can be queried like any
732 built-in properties using zfs get:
733
734 zfs get warranty:expires mypool
735
736 To reset the value of a custom property, use the inherit subcommand:
737
738 # zfs inherit warranty:expires mypool
739
740 Removing a custom property from a pool is done using the -r flag to the
741 "zfs inherit" command:
742
743 # zfs inherit -r warranty:expires mypool
744
745                 -- Benedict Reuschling <bcr@FreeBSD.org>
746 %
747 To delete a range of ZFS snapshots, use the % (percent) character after the
748 full path to the first snapshot that should be included. For example, to
749 simulate deleting snapshots a through (including) d, use this command:
750
751 # zfs destroy -rvn mypool/tmp@a%d
752
753 Once you are sure that this is what you want, remove the -n option:
754
755 # zfs destroy -rv mypool/tmp@a%d
756
757                 -- Benedict Reuschling <bcr@FreeBSD.org>
758 %
759 You can prevent the removal of a ZFS snapshot by using the hold subcommand.
760 For example, to prevent the snapshot called milestone from deletion, run the
761 following command:
762
763 # zfs hold milestone_hold mypool/projects@my_milestone
764
765 The "zfs holds" command will list all current snapshots that are protected
766 this way (-r for a recursive list):
767
768 # zfs holds -r mypool
769
770 The TIMESTAMP column in the output of the above command is from when the
771 hold was created, not the snapshot it holds. The "zfs destroy" command will
772 echo a "dataset is busy" message on the console when it encounters a hold.
773 Use "zfs release" to release the hold on the snapshot:
774
775 # zfs release milestone_hold mypool/projects@my_milestone
776
777                 -- Benedict Reuschling <bcr@FreeBSD.org>
778 %
779 A user "sender" needs the following permissions set to send a ZFS dataset:
780
781 # zfs allow -u sender send,snapshot txpool
782
783 On the receiving side, the user "receiver" requires these permissions:
784
785 # zfs allow -u receiver compression,mountpoint,mount,create,receive rxpool
786
787                 -- Benedict Reuschling <bcr@FreeBSD.org>
788 %
789 Don't let your zpool fill up completely by creating a dataset with
790 reservation.
791
792 # zfs create -o refreservation=<5% of total pool space> <poolname>/reserved
793
794 You can always shrink the reserve if you need the space, but your pool will
795 always have space left this way.
796
797                 -- Benedict Reuschling <bcr@FreeBSD.org>
798 %
799 Sometimes a single slow HDD can cripple the performance of your entire system.
800 You can spot one like this:
801
802 # gstat -I5s | sort -rn -k9 | head
803
804                 -- Alan Somers <asomers@FreeBSD.org>
805 %
806 FreeBSD's ps(1) can create a dependency tree based on parent/child
807 relationships between processes, like this:
808
809 $ ps -d
810
811                 -- Daniel Ebdrup Jensen <debdrup@FreeBSD.org>
812 %
813 It is possible to measure the resident memory set:
814
815 $ vmstat -o | awk 'NR>1 { t[$7] += $1 } \
816 END { for (i in t) printf "%s %d\n",i,t[i] }'
817
818 The rows have the following meaning:
819 df = default (not assigned a specific pager)
820 sw = swap
821 df = virtual
822 vn = vnode
823 ph = heap
824 md = memory device
825
826 This will be reported in number of pages, so it needs to be multiplied by the
827 page size of the architecture which can be found via:
828
829 $ sysctl -n hw.pagesize
830
831                 -- Daniel Ebdrup Jensen <debdrup@FreeBSD.org>
832 %
833 To establish a serial connection to anything including a USB device,
834 nothing more than cu(1) is needed:
835
836 $ cu -s 9600 -l /dev/ttyU0
837
838                 -- Daniel Ebdrup Jensen <debdrup@FreeBSD.org>
839 %
840 You can control kernel stack(9) traces on ^T (tty info) by setting
841 kern.tty_info_kstacks to 0 (off), 1 (on), or 2 (verbose), e.g.:
842
843 # sysctl kern.tty_info_kstacks=2
844
845                 -- Michael Gmelin <grembo@FreeBSD.org>
846 %