freebsd-tips revision 303975
191671SumeThis fortune brought to you by: 262587Sitojun$FreeBSD: releng/11.0/usr.bin/fortune/datfiles/freebsd-tips 287582 2015-09-08 22:51:10Z allanjude $ 355009Sshin% 4116174SobrienAny user that is a member of the wheel group can use "su -" to simulate 555009Sshina root login. You can add a user to the wheel group by editing /etc/group. 655009Sshin -- Konstantinos Konstantinidis <kkonstan@duth.gr> 755009Sshin% 855009SshinBy pressing "Scroll Lock" you can use the arrow keys to scroll backward 955009Sshinthrough the console output. Press "Scroll Lock" again to turn it off. 1055009Sshin% 1155009SshinCan't remember if you've installed a certain port or not? Try "pkg info 1255009Sshin-x port_name". 1355009Sshin% 1455009SshinEver wonder what those numbers after command names were, as in cat(1)? It's 1555009Sshinthe section of the manual the man page is in. "man man" will tell you more. 1655009Sshin -- David Scheidt <dscheidt@tumbolia.com> 1755009Sshin% 1855009SshinForget how to spell a word or a variation of a word? Use 1955009Sshin 2055009Sshin look portion_of_word_you_know 2155009Sshin -- Dru <genesis@istar.ca> 2255009Sshin% 2355009SshinForget what directory you are in? Type "pwd". 2455009Sshin -- Dru <genesis@istar.ca> 2555009Sshin% 2655009SshinForget when Easter is? Try "ncal -e". If you need the date for Orthodox 2755009SshinEaster, use "ncal -o" instead. 2855009Sshin -- Dru <genesis@istar.ca> 2955009Sshin% 3055009SshinFreeBSD is started up by the program 'init'. The first thing init does when 3155009Sshinstarting multiuser mode (ie, starting the computer up for normal use) is to 3255009Sshinrun the shell script /etc/rc. By reading /etc/rc and the /etc/rc.d/ scripts, 3355009Sshinyou can learn a lot about how the system is put together, which again will 3455009Sshinmake you more confident about what happens when you do something with it. 3555009Sshin% 3655009SshinHandy bash(1) prompt: PS1="\u@\h \w \!$ " 3755009Sshin -- David Scheidt <dscheidt@tumbolia.com> 3855009Sshin% 3955009SshinHaving trouble using fetch through a firewall? Try setting the environment 4055009Sshinvariable FTP_PASSIVE_MODE to yes, and see fetch(3) for more details. 4155009Sshin% 4255009SshinIf other operating systems have damaged your Master Boot Record, you can 4355009Sshinreinstall it with boot0cfg(8). See 4455009Sshin"man boot0cfg" for details. 4555009Sshin% 4655009SshinIf you accidentally end up inside vi, you can quit it by pressing Escape, colon 4755009Sshin(:), q (q), bang (!) and pressing return. 4855009Sshin% 4955009SshinIf you are in the C shell and have just installed a new program, you won't 5055009Sshinbe able to run it unless you first type "rehash". 5155009Sshin -- Dru <genesis@istar.ca> 5255009Sshin% 5355009SshinIf you do not want to get beeps in X11 (X Windows), you can turn them off with 5455009Sshin 5555009Sshin xset b off 5655009Sshin% 5755009SshinIf you have a CD-ROM drive in your machine, you can make the CD-ROM that is 5855009Sshinpresently inserted available by typing 'mount /cdrom' as root. The CD-ROM 5955009Sshinwill be available under /cdrom/. Remember to do 'umount /cdrom' before 6055009Sshinremoving the CD-ROM (it will usually not be possible to remove the CD-ROM 6155009Sshinwithout doing this.) 62116174Sobrien 63116174SobrienNote: This tip may not work in all configurations. 64116174Sobrien% 6555009SshinIf you need a reminder to leave your terminal, type "leave +hhmm" where 6655009Sshin"hhmm" represents in how many hours and minutes you need to leave. 6755009Sshin -- Dru <genesis@istar.ca> 6855009Sshin% 6955009SshinIf you need to ask a question on the FreeBSD-questions mailing list then 7055009Sshin 7155009Sshin http://www.FreeBSD.org/doc/en_US.ISO8859-1/articles/\ 7278064Sume freebsd-questions/index.html 7378064Sume 7478064Sumecontains lots of useful advice to help you get the best results. 7578064Sume% 7678064SumeIf you write part of a filename in tcsh, 7778064Sumepressing TAB will show you the available choices when there 7855009Sshinis more than one, or complete the filename if there's only one match. 7978064Sume% 8078064SumeIf you `set watch = (0 any any)' in tcsh, you will be notified when 8155009Sshinsomeone logs in or out of your system. 8291671Sume% 8378064SumeIf you use the C shell, add the following line to the .cshrc file in your 8455009Sshinhome directory to prevent core files from being written to disk: 8578064Sume 8678064Sume limit coredumpsize 0 8755009Sshin -- Dru <genesis@istar.ca> 8878064Sume% 8955009SshinIf you want df(1) and other commands to display disk sizes in 9078064Sumekilobytes instead of 512-byte blocks, set BLOCKSIZE in your 9178064Sumeenvironment to 'K'. You can also use 'M' for Megabytes or 'G' for 9278064SumeGigabytes. If you want df(1) to automatically select the best size 9355009Sshinthen use 'df -h'. 9478064Sume% 9578064SumeIf you want to play CDs with FreeBSD, a utility for this is already included. 9678064SumeType 'cdcontrol' then 'help' to learn more. (You may need to set the CDROM 9755009Sshinenvironment variable in order to make cdcontrol want to start.) 9878064Sume% 9978064SumeIf you'd like to keep track of applications in the FreeBSD ports tree, take a 10078064Sumelook at FreshPorts; 10155009Sshin 10278064Sume http://www.freshports.org/ 10378064Sume% 10478064SumeIn order to make fetch (the FreeBSD downloading tool) ask for 10555009Sshinusername/password when it encounters a password-protected web page, you can set 10678064Sumethe environment variable HTTP_AUTH to 'basic:*'. 10778064Sume% 10855009SshinIn order to search for a string in some files, use 'grep' like this: 10978064Sume 11078064Sume grep "string" filename1 [filename2 filename3 ...] 11178064Sume 11291671SumeThis will print out the lines in the files that contain the string. grep can 11378064Sumealso do a lot more advanced searches - type 'man grep' for details. 11478064Sume% 11578064SumeIn order to support national characters for European languages in tools like 11655009Sshinless without creating other nationalisation aspects, set the environment 11778064Sumevariable LC_ALL to 'en_US.ISO8859-1'. 11878064Sume% 11991671Sume"man firewall" will give advice for building a FreeBSD firewall 12078064Sume -- David Scheidt <dscheidt@tumbolia.com> 12178064Sume% 12255009Sshin"man hier" will explain the way FreeBSD filesystems are normally laid out. 12378064Sume -- David Scheidt <dscheidt@tumbolia.com> 124% 125Man pages are divided into section depending on topic. There are 9 different 126sections numbered from 1 (General Commands) to 9 (Kernel Developer's Manual). 127You can get an introduction to each topic by typing 128 129 man <number> intro 130 131In other words, to get the intro to general commands, type 132 133 man 1 intro 134% 135"man ports" gives many useful hints about installing FreeBSD ports. 136% 137"man security" gives very good advice on how to tune the security of your 138FreeBSD system. 139% 140"man tuning" gives some tips how to tune performance of your FreeBSD system. 141 -- David Scheidt <dscheidt@tumbolia.com> 142% 143Need to do a search in a manpage or in a file you've sent to a pager? Use 144"/search_word". To repeat the same search, type "n" for next. 145 -- Dru <genesis@istar.ca> 146% 147Need to find the location of a program? Use "locate program_name". 148 -- Dru <genesis@istar.ca> 149% 150Need to leave your terminal for a few minutes and don't want to logout? 151Use "lock -p". When you return, use your password as the key to unlock the 152terminal. 153 -- Dru <genesis@istar.ca> 154% 155Need to print a manpage? Use 156 157 man name_of_manpage | col -bx | lpr 158 -- Dru <genesis@istar.ca> 159% 160Need to quickly empty a file? Use ": > filename". 161 -- Dru <genesis@istar.ca> 162% 163Need to quickly return to your home directory? Type "cd". 164 -- Dru <genesis@istar.ca> 165% 166Need to remove all those ^M characters from a DOS file? Try 167 168 tr -d \\r < dosfile > newfile 169 -- Originally by Dru <genesis@istar.ca> 170% 171Need to see the calendar for this month? Simply type "cal". To see the 172whole year, type "cal -y". 173 -- Dru <genesis@istar.ca> 174% 175Need to see which daemons are listening for connection requests? Use 176"sockstat -4l" for IPv4, and "sockstat -l" for IPv4 and IPv6. 177 -- Dru <genesis@istar.ca> 178% 179Need to see your routing table? Type "netstat -rn". The entry with the G 180flag is your gateway. 181 -- Dru <genesis@istar.ca> 182% 183Nice bash prompt: PS1='(\[$(tput md)\]\t <\w>\[$(tput me)\]) $(echo $?) \$ ' 184 -- Mathieu <mathieu@hal.interactionvirtuelle.com> 185% 186Over quota? "du -s * | sort -n " will give you a sorted list of your 187directory sizes. 188 -- David Scheidt <dscheidt@tumbolia.com> 189% 190nc(1) (or netcat) is useful not only for redirecting input/output to 191TCP or UDP connections, but also for proxying them with inetd(8). 192% 193sh (the default Bourne shell in FreeBSD) supports command-line editing. Just 194``set -o emacs'' or ``set -o vi'' to enable it. 195% 196Simple tcsh prompt: set prompt = '%# ' 197% 198The default editor in FreeBSD is vi, which is efficient to use when you have 199learned it, but somewhat user-unfriendly. To use ee (an easier but less 200powerful editor) instead, set the environment variable EDITOR to /usr/bin/ee 201% 202Time to change your password? Type "passwd" and follow the prompts. 203 -- Dru <genesis@istar.ca> 204% 205To change an environment variable in /bin/sh use: 206 207 $ VARIABLE="value" 208 $ export VARIABLE 209% 210To change an environment variable in tcsh you use: setenv NAME "value" 211where NAME is the name of the variable and "value" its new value. 212% 213To clear the screen, use "clear". To re-display your screen buffer, press 214the scroll lock key and use your page up button. When you're finished, 215press the scroll lock key again to get your prompt back. 216 -- Dru <genesis@istar.ca> 217% 218To determine whether a file is a text file, executable, or some other type 219of file, use 220 221 file filename 222 -- Dru <genesis@istar.ca> 223% 224To do a fast search for a file, try 225 226 locate filename 227 228locate uses a database that is updated every Saturday (assuming your computer 229is running FreeBSD at the time) to quickly find files based on name only. 230% 231To erase a line you've written at the command prompt, use "Ctrl-U". 232 -- Dru <genesis@istar.ca> 233% 234To find the hostname associated with an IP address, use 235 236 drill -x IP_address 237 -- Allan Jude <allanjude@FreeBSD.org> 238% 239To obtain a neat PostScript rendering of a manual page, use ``-t'' switch 240of the man(1) utility: ``man -t <topic>''. For example: 241 242 man -t grep > grep.ps # Save the PostScript version to a file 243or 244 man -t printf | lp # Send the PostScript directly to printer 245% 246To quickly create an empty file, use "touch filename". 247 -- Dru <genesis@istar.ca> 248% 249To read a compressed file without having to first uncompress it, use 250"zcat" or "zless" to view it. 251 -- Dru <genesis@istar.ca> 252% 253To repeat the last command in the C shell, type "!!". 254 -- Dru <genesis@istar.ca> 255% 256To save disk space in your home directory, compress files you rarely 257use with "gzip filename". 258 -- Dru <genesis@istar.ca> 259% 260To search for files that match a particular name, use find(1); for example 261 262 find / -name "*GENERIC*" -ls 263 264will search '/', and all subdirectories, for files with 'GENERIC' in the name. 265 -- Stephen Hilton <nospam@hiltonbsd.com> 266% 267To see all of the directories on your FreeBSD system, type 268 269 find / -type d | less 270 271All the files? 272 273 find / -type f | less 274% 275To see how long it takes a command to run, type the word "time" before the 276command name. 277 -- Dru <genesis@istar.ca> 278% 279To see how much disk space is left on your partitions, use 280 281 df -h 282 -- Dru <genesis@istar.ca> 283% 284To see the 10 largest files on a directory or partition, use 285 286 du /partition_or_directory_name | sort -rn | head 287 -- Dru <genesis@istar.ca> 288% 289To see the IP addresses currently set on your active interfaces, type 290"ifconfig -u". 291 -- Dru <genesis@istar.ca> 292% 293To see the last 10 lines of a long file, use "tail filename". To see the 294first 10 lines, use "head filename". 295 -- Dru <genesis@istar.ca> 296% 297To see the last time that you logged in, use lastlogin(8). 298 -- Dru <genesis@istar.ca> 299% 300To see the MAC addresses of the NICs on your system, type 301 302 ifconfig -a 303 -- Dru <genesis@istar.ca> 304% 305To see the output from when your computer started, run dmesg(8). If it has 306been replaced with other messages, look at /var/run/dmesg.boot. 307 -- Francisco Reyes <lists@natserv.com> 308% 309Want colour in your directory listings? Use "ls -G". "ls -F" is also useful, 310and they can be combined as "ls -FG". 311% 312Want to find a specific port, just type the following under /usr/ports 313or one its subdirectories: 314 315 make search name=<port-name> 316 or 317 make search key=<keyword> 318% 319Want to know how many words, lines, or bytes are contained in a file? Type 320"wc filename". 321 -- Dru <genesis@istar.ca> 322% 323Want to see how much virtual memory you're using? Just type "swapinfo" to 324be shown information about the usage of your swap partitions. 325% 326Want to strip UTF-8 BOM(Byte Order Mark) from given files? 327 328 sed -e '1s/^\xef\xbb\xbf//' < bomfile > newfile 329% 330Want to use sed(1) to edit a file in place? Well, to replace every 'e' with 331an 'o', in a file named 'foo', you can do: 332 333 sed -i.bak s/e/o/g foo 334 335And you'll get a backup of the original in a file named 'foo.bak', but if you 336want no backup: 337 338 sed -i '' s/e/o/g foo 339% 340When you've made modifications to a file in vi(1) and then find that 341you can't write it, type ``<ESC>!rm -f %'' then ``:w!'' to force the 342write 343 344This won't work if you don't have write permissions to the directory 345and probably won't be suitable if you're editing through a symbolic link. 346% 347You can adjust the volume of various parts of the sound system in your 348computer by typing 'mixer <type> <volume>'. To get a list of what you can 349adjust, just type 'mixer'. 350% 351You can automatically download and install binary packages by doing 352 353 pkg install <package> 354 355This will also automatically install the packages that are dependencies 356for the package you install (ie, the packages it needs in order to work.) 357% 358You can change the video mode on all consoles by adding something like 359the following to /etc/rc.conf: 360 361 allscreens="80x30" 362 363You can use "vidcontrol -i mode | grep T" for a list of supported text 364modes. 365 -- Konstantinos Konstantinidis <kkonstan@duth.gr> 366% 367You can disable tcsh's terminal beep if you `set nobeep'. 368% 369You can install extra packages for FreeBSD by using the ports system. 370If you have installed it, you can download, compile, and install software by 371just typing 372 373 # cd /usr/ports/<category>/<portname> 374 # make install && make clean 375 376as root. The ports infrastructure will download the software, change it so 377it works on FreeBSD, compile it, install it, register the installation so it 378will be possible to automatically uninstall it, and clean out the temporary 379working space it used. You can remove an installed port you decide you do not 380want after all by typing 381 382 # cd /usr/ports/<category>/<portname> 383 # make deinstall 384 385as root. 386% 387You can look through a file in a nice text-based interface by typing 388 389 less filename 390% 391You can make a log of your terminal session with script(1). 392% 393You can often get answers to your questions about FreeBSD by searching in the 394FreeBSD mailing list archives at 395 396 http://www.FreeBSD.org/search/search.html 397% 398You can open up a new split-screen window in (n)vi with :N or :E and then 399use ^w to switch between the two. 400% 401You can permanently set environment variables for your shell by putting them 402in a startup file for the shell. The name of the startup file varies 403depending on the shell - csh and tcsh uses .login, bash, sh, ksh and zsh use 404.profile. When using bash, sh, ksh or zsh, don't forget to export the 405variable. 406% 407You can press Ctrl-D to quickly exit from a shell, or logout from a 408login shell. 409 -- Konstantinos Konstantinidis <kkonstan@duth.gr> 410% 411You can press Ctrl-L while in the shell to clear the screen. 412% 413You can press up-arrow or down-arrow to walk through a list of 414previous commands in tcsh. 415% 416You can search for documentation on a keyword by typing 417 418 apropos keyword 419% 420You can `set autologout = 30' to have tcsh log you off automatically 421if you leave the shell idle for more than 30 minutes. 422% 423You can use aliases to decrease the amount of typing you need to do to get 424commands you commonly use. Examples of fairly popular aliases include (in 425Bourne shell style, as in /bin/sh, bash, ksh, and zsh): 426 427 alias lf="ls -FA" 428 alias ll="ls -lA" 429 alias su="su -m" 430 431In csh or tcsh, these would be 432 433 alias lf ls -FA 434 alias ll ls -lA 435 alias su su -m 436 437To remove an alias, you can usually use 'unalias aliasname'. To list all 438aliases, you can usually type just 'alias'. 439% 440You can use /etc/make.conf to control the options used to compile software 441on this system. Example entries are in 442/usr/share/examples/etc/make.conf. 443% 444You can use "pkg info" to see a list of packages you have installed. 445% 446You can use the 'fetch' command to retrieve files over ftp, http or https. 447 448 fetch http://www.FreeBSD.org/index.html 449 450will download the front page of the FreeBSD web site. 451% 452You can use "whereis" to search standard binary, manual page and source 453directories for the specified programs. This can be particularly handy 454when you are trying to find where in the ports tree an application is. 455 456Try "whereis firefox" and "whereis whereis". 457 -- Konstantinos Konstantinidis <kkonstan@duth.gr> 458% 459Want to run the same command again? 460In tcsh you can type "!!" 461% 462Want to go the directory you were just in? 463Type "cd -" 464% 465