免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3134 | 回复: 2

[FreeBSD] FreeBSD: 102 Tips and Tricks [复制链接]

论坛徽章:
0
发表于 2012-10-10 19:22 |显示全部楼层
http://mebsd.com/cheat-sheets/102-freebsd-tips-trick.html

  1. FreeBSD: 102 Tips and Tricks
  2. These tips will look familiar to any one who has games/fortune in their MOTD, because indeed this is where they’re from. These tips are well worth reading, even for an experienced FreeBSD user. For example, how many users know about the “look” command, I for one am enlightened!

  3. FreeBSD Tip: #1
  4. Any user that is a member of the wheel group can use "su -" to simulate
  5. a root login. You can add a user to the wheel group by editing /etc/group.
  6.                 -- Konstantinos Konstantinidis <kkonstan at duth.gr>
  7. FreeBSD Tip: #2
  8. By pressing "Scroll Lock" you can use the arrow keys to scroll backward
  9. through the console output.  Press "Scroll Lock" again to turn it off.
  10. FreeBSD Tip: #3
  11. Can't remember if you've installed a certain port or not? Try "pkg_info
  12. -Ix port_name".
  13. FreeBSD Tip: #4
  14. Ever wonder what those numbers after command names were, as in cat(1)?  It's
  15. the section of the manual the man page is in.  "man man" will tell you more.
  16.                 -- David Scheidt <dscheidt at tumbolia.com>
  17. FreeBSD Tip: #5
  18. Forget how to spell a word or a variation of a word? Use

  19.         look portion_of_word_you_know
  20.                 -- Dru <genesis at istar.ca>
  21. FreeBSD Tip: #6
  22. Forget what directory you are in? Type "pwd".
  23.                 -- Dru <genesis at istar.ca>
  24. FreeBSD Tip: #7
  25. Forget when Easter is? Try "ncal -e". If you need the date for Orthodox
  26. Easter, use "ncal -o" instead.
  27.                 -- Dru <genesis at istar.ca>
  28. FreeBSD Tip: #8
  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. FreeBSD Tip: #9
  35. Handy bash(1) prompt:  PS1="\u at \h \w \!$ "
  36.                 -- David Scheidt <dscheidt at tumbolia.com>
  37. FreeBSD Tip: #10
  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. FreeBSD Tip: #11
  41. If other operating systems have damaged your Master Boot Record, you can
  42. reinstall it either with /usr/sbin/sysinstall or with boot0cfg(8). See
  43. "man boot0cfg" for details.
  44. FreeBSD Tip: #12
  45. If you accidentally end up inside vi, you can quit it by pressing Escape, colon
  46. (:), q (q), bang (!) and pressing return.
  47. FreeBSD Tip: #13
  48. If you are in the C shell and have just installed a new program, you won't
  49. be able to run it unless you first type "rehash".
  50.                 -- Dru <genesis at istar.ca>
  51. FreeBSD Tip: #14
  52. If you do not want to get beeps in X11 (X Windows), you can turn them off with

  53.         xset b off
  54. FreeBSD Tip: #15
  55. If you have a CD-ROM drive in your machine, you can make the CD-ROM that is
  56. presently inserted available by typing 'mount /cdrom' as root.  The CD-ROM
  57. will be available under /cdrom/.  Remember to do 'umount /cdrom' before
  58. removing the CD-ROM (it will usually not be possible to remove the CD-ROM
  59. without doing this.)

  60. Note: This tip may not work in all configurations.
  61. FreeBSD Tip: #16
  62. If you need a reminder to leave your terminal, type "leave +hhmm" where
  63. "hhmm" represents in how many hours and minutes you need to leave.
  64.                 -- Dru <genesis at istar.ca>
  65. FreeBSD Tip: #17
  66. If you need to ask a question on the FreeBSD-questions mailing list then

  67. http://www.FreeBSD.org/doc/en_US.ISO8859-1/articles/\

  68.                 freebsd-questions/index.html

  69. contains lots of useful advice to help you get the best results.
  70. FreeBSD Tip: #18
  71. If you write part of a filename in tcsh,
  72. pressing TAB will show you the available choices when there
  73. is more than one, or complete the filename if there's only one match.
  74. FreeBSD Tip: #19
  75. If you `set watch = (0 any any)' in tcsh, you will be notified when
  76. someone logs in or out of your system.
  77. FreeBSD Tip: #20
  78. If you use the C shell, add the following line to the .cshrc file in your
  79. home directory to prevent core files from being written to disk:

  80.         limit coredumpsize 0
  81.                 -- Dru <genesis at istar.ca>
  82. FreeBSD Tip: #21
  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. FreeBSD Tip: #22
  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. FreeBSD Tip: #23
  93. If you want to quickly check for duplicate package/port installations,
  94. try the following pkg_info command.

  95.         pkg_info | sort | sed -e 's/-[0-9].*$//' | \
  96.         uniq -c | grep -v '^[[:space:]]*1'
  97. FreeBSD Tip: #24
  98. If you'd like to keep track of applications in the FreeBSD ports tree, take a
  99. look at FreshPorts;

  100. http://www.freshports.org/
  101. FreeBSD Tip: #25
  102. In order to make fetch (the FreeBSD downloading tool) ask for
  103. username/password when it encounters a password-protected web page, you can set
  104. the environment variable HTTP_AUTH to 'basic:*'.
  105. FreeBSD Tip: #26
  106. In order to search for a string in some files, use 'grep' like this:

  107.          grep "string" filename1 [filename2 filename3 ...]

  108. This will print out the lines in the files that contain the string.  grep can
  109. also do a lot more advanced searches - type 'man grep' for details.
  110. FreeBSD Tip: #27
  111. In order to support national characters for European languages in tools like
  112. less without creating other nationalisation aspects, set the environment
  113. variable LC_ALL to 'en_US.ISO8859-1'.
  114. FreeBSD Tip: #28
  115. "man firewall" will give advice for building a FreeBSD firewall
  116.                 -- David Scheidt <dscheidt at tumbolia.com>
  117. FreeBSD Tip: #29
  118. "man hier" will explain the way FreeBSD filesystems are normally laid out.
  119.                 -- David Scheidt <dscheidt at tumbolia.com>
  120. FreeBSD Tip: #30
  121. Man pages are divided into section depending on topic.  There are 9 different
  122. sections numbered from 1 (General Commands) to 9 (Kernel Developer's Manual).
  123. You can get an introduction to each topic by typing

  124.         man <number> intro

  125. In other words, to get the intro to general commands, type

  126.         man 1 intro
  127. FreeBSD Tip: #31
  128. "man ports" gives many useful hints about installing FreeBSD ports.
  129. FreeBSD Tip: #32
  130. "man security" gives very good advice on how to tune the security of your
  131. FreeBSD system.
  132. FreeBSD Tip: #33
  133. "man tuning" gives some tips how to tune performance of your FreeBSD system.
  134.                 -- David Scheidt <dscheidt at tumbolia.com>
  135. FreeBSD Tip: #34
  136. Need to do a search in a manpage or in a file you've sent to a pager? Use
  137. "/search_word". To repeat the same search, type "n" for next.
  138.                 -- Dru <genesis at istar.ca>
  139. FreeBSD Tip: #35
  140. Need to find the location of a program? Use "locate program_name".
  141.                 -- Dru <genesis at istar.ca>
  142. FreeBSD Tip: #36
  143. Need to leave your terminal for a few minutes and don't want to logout?
  144. Use "lock -p". When you return, use your password as the key to unlock the
  145. terminal.
  146.                 -- Dru <genesis at istar.ca>
  147. FreeBSD Tip: #37
  148. Need to print a manpage? Use

  149.         man name_of_manpage | col -bx | lpr
  150.                 -- Dru <genesis at istar.ca>
  151. FreeBSD Tip: #38
  152. Need to quickly empty a file? Use ": > filename".
  153.                 -- Dru <genesis at istar.ca>
  154. FreeBSD Tip: #39
  155. Need to quickly return to your home directory? Type "cd".
  156.                 -- Dru <genesis at istar.ca>
  157. FreeBSD Tip: #40
  158. Need to remove all those ^M characters from a DOS file? Try

  159.         tr -d \\r < dosfile > newfile
  160.                 -- Originally by Dru <genesis at istar.ca>
  161. FreeBSD Tip: #41
  162. Need to see the calendar for this month? Simply type "cal".  To see the
  163. whole year, type "cal -y".
  164.                 -- Dru <genesis at istar.ca>
  165. FreeBSD Tip: #42
  166. Need to see which daemons are listening for connection requests? Use
  167. "sockstat -4l" for IPv4, and "sockstat -l" for IPv4 and IPv6.
  168.                 -- Dru <genesis at istar.ca>
  169. FreeBSD Tip: #43
  170. Need to see your routing table? Type "netstat -rn". The entry with the G
  171. flag is your gateway.
  172.                 -- Dru <genesis at istar.ca>
  173. FreeBSD Tip: #44
  174. Nice bash prompt: PS1='(\[$(tput md)\]\t <\w>\[$(tput me)\]) $(echo $?) \$ '
  175.                 -- Mathieu <mathieu at hal.interactionvirtuelle.com>
  176. FreeBSD Tip: #45
  177. Over quota?  "du -s * | sort -n " will give you a sorted list of your
  178. directory sizes.
  179.                 -- David Scheidt <dscheidt at tumbolia.com>
  180. FreeBSD Tip: #46
  181. nc(1) (or netcat) is useful not only for redirecting input/output to
  182. TCP or UDP connections, but also for proxying them with inetd(8).
  183. FreeBSD Tip: #47
  184. sh (the default Bourne shell in FreeBSD) supports command-line editing.  Just
  185. ``set -o emacs'' or ``set -o vi'' to enable it.
  186. FreeBSD Tip: #48
  187. Simple tcsh prompt: set prompt = '%# '
  188. FreeBSD Tip: #49
  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. FreeBSD Tip: #50
  193. Time to change your password? Type "passwd" and follow the prompts.
  194.                 -- Dru <genesis at istar.ca>
  195. FreeBSD Tip: #51
  196. To change an environment variable in /bin/sh use:

  197.         $ VARIABLE="value"
  198.         $ export VARIABLE
  199. FreeBSD Tip: #52
  200. To change an environment variable in tcsh you use: setenv NAME "value"
  201. where NAME is the name of the variable and "value" its new value.
  202. FreeBSD Tip: #53
  203. To clear the screen, use "clear". To re-display your screen buffer, press
  204. the scroll lock key and use your page up button. When you're finished,
  205. press the scroll lock key again to get your prompt back.
  206.                 -- Dru <genesis at istar.ca>
  207. FreeBSD Tip: #54
  208. To determine whether a file is a text file, executable, or some other type
  209. of file, use

  210.         file filename
  211.                 -- Dru <genesis at istar.ca>
  212. FreeBSD Tip: #55
  213. To do a fast search for a file, try

  214.          locate filename

  215. locate uses a database that is updated every Saturday (assuming your computer
  216. is running FreeBSD at the time) to quickly find files based on name only.
  217. FreeBSD Tip: #56
  218. To erase a line you've written at the command prompt, use "Ctrl-U".
  219.                 -- Dru <genesis at istar.ca>
  220. FreeBSD Tip: #57
  221. To find out the hostname associated with an IP address, use

  222.         dig -x IP_address
  223.                 -- Dru <genesis at istar.ca>
  224. FreeBSD Tip: #58
  225. To obtain a neat PostScript rendering of a manual page, use ``-t'' switch
  226. of the man(1) utility: ``man -t <topic>''.  For example:

  227.         man -t grep > grep.ps        # Save the PostScript version to a file
  228. or
  229.         man -t printf | lp        # Send the PostScript directly to printer
  230. FreeBSD Tip: #59
  231. To quickly create an empty file, use "touch filename".
  232.                 -- Dru <genesis at istar.ca>
  233. FreeBSD Tip: #60
  234. To read a compressed file without having to first uncompress it, use
  235. "zcat" or "zless" to view it.
  236.                 -- Dru <genesis at istar.ca>
  237. FreeBSD Tip: #61
  238. To repeat the last command in the C shell, type "!!".
  239.                 -- Dru <genesis at istar.ca>
  240. FreeBSD Tip: #62
  241. To save disk space in your home directory, compress files you rarely
  242. use with "gzip filename".
  243.                 -- Dru <genesis at istar.ca>
  244. FreeBSD Tip: #63
  245. To search for files that match a particular name, use find(1); for example

  246.         find / -name "*GENERIC*" -ls

  247. will search '/', and all subdirectories, for files with 'GENERIC' in the name.
  248.               --  Stephen Hilton <nospam at hiltonbsd.com>
  249. FreeBSD Tip: #64
  250. To see all of the directories on your FreeBSD system, type

  251.         find / -type d | less

  252. All the files?

  253.         find / -type f | less
  254. FreeBSD Tip: #65
  255. To see how long it takes a command to run, type the word "time" before the
  256. command name.
  257.                 -- Dru <genesis at istar.ca>
  258. FreeBSD Tip: #66
  259. To see how much disk space is left on your partitions, use

  260.         df -h
  261.                 -- Dru <genesis at istar.ca>
  262. FreeBSD Tip: #67
  263. To see the 10 largest files on a directory or partition, use

  264.         du /partition_or_directory_name | sort -rn | head
  265.                 -- Dru <genesis at istar.ca>
  266. FreeBSD Tip: #68
  267. To see the IP addresses currently set on your active interfaces, type
  268. "ifconfig -u".
  269.                 -- Dru <genesis at istar.ca>
  270. FreeBSD Tip: #69
  271. To see the last 10 lines of a long file, use "tail filename". To see the
  272. first 10 lines, use "head filename".
  273.                 -- Dru <genesis at istar.ca>
  274. FreeBSD Tip: #70
  275. To see the last time that you logged in, use lastlogin(8).
  276.                 -- Dru <genesis at istar.ca>
  277. FreeBSD Tip: #71
  278. To see the MAC addresses of the NICs on your system, type

  279.         ifconfig -a
  280.                 -- Dru <genesis at istar.ca>
  281. FreeBSD Tip: #72
  282. To see the output from when your computer started, run dmesg(8).  If it has
  283. been replaced with other messages, look at /var/run/dmesg.boot.
  284.                 -- Francisco Reyes <lists at natserv.com>
  285. FreeBSD Tip: #73
  286. Want colour in your directory listings?  Use "ls -G".  "ls -F" is also useful,
  287. and they can be combined as "ls -FG".
  288. FreeBSD Tip: #74
  289. Want to find a specific port, just type the following under /usr/ports
  290. or one its subdirectories:

  291.         make search name=<port-name>
  292.     or
  293.         make search key=<keyword>
  294. FreeBSD Tip: #75
  295. Want to know how many words, lines, or bytes are contained in a file? Type
  296. "wc filename".
  297.                 -- Dru <genesis at istar.ca>
  298. FreeBSD Tip: #76
  299. Want to see how much virtual memory you're using? Just type "swapinfo" to
  300. be shown information about the usage of your swap partitions.
  301. FreeBSD Tip: #77
  302. Want to strip UTF-8 BOM(Byte Order Mark) from given files?

  303.         sed -e '1s/^\xef\xbb\xbf//' < bomfile > newfile
  304. FreeBSD Tip: #78
  305. Want to use sed(1) to edit a file in place?  Well, to replace every 'e' with
  306. an 'o', in a file named 'foo', you can do:

  307.         sed -i.bak s/e/o/g foo

  308. And you'll get a backup of the original in a file named 'foo.bak', but if you
  309. want no backup:

  310.         sed -i '' s/e/o/g foo
  311. FreeBSD Tip: #79
  312. When you've made modifications to a file in vi(1) and then find that
  313. you can't write it, type ``<ESC>!rm -f %'' then ``:w!'' to force the
  314. write

  315. This won't work if you don't have write permissions to the directory
  316. and probably won't be suitable if you're editing through a symbolic link.
  317. FreeBSD Tip: #80
  318. You can adjust the volume of various parts of the sound system in your
  319. computer by typing 'mixer <type> <volume>'.  To get a list of what you can
  320. adjust, just type 'mixer'.
  321. FreeBSD Tip: #81
  322. You can automatically download and install binary packages by doing

  323.         pkg_add -r <URL>

  324. where you replace <URL> with the URL to the package.  This will also
  325. automatically install the packages the package you download is dependent on
  326. (ie, the packages it needs in order to work.)
  327. FreeBSD Tip: #82
  328. You can change the video mode on all consoles by adding something like
  329. the following to /etc/rc.conf:

  330.         allscreens="80x30"

  331. You can use "vidcontrol -i mode | grep T" for a list of supported text
  332. modes.
  333.                 -- Konstantinos Konstantinidis <kkonstan at duth.gr>
  334. FreeBSD Tip: #83
  335. You can disable tcsh's terminal beep if you `set nobeep'.
  336. FreeBSD Tip: #84
  337. You can get a good generic server install by using the
  338. instant-server port/package.  If you have ports installed, you can
  339. install it by doing

  340.         # cd /usr/ports/misc/instant-server
  341.         # make install && make clean

  342. as root.  This will install a collection of packages that is appropriate for
  343. running a "generic" server.
  344. FreeBSD Tip: #85
  345. You can install extra packages for FreeBSD by using the ports system.
  346. If you have installed it, you can download, compile, and install software by
  347. just typing

  348.         # cd /usr/ports/<category>/<portname>
  349.         # make install && make clean

  350. as root.  The ports infrastructure will download the software, change it so
  351. it works on FreeBSD, compile it, install it, register the installation so it
  352. will be possible to automatically uninstall it, and clean out the temporary
  353. working space it used.  You can remove an installed port you decide you do not
  354. want after all by typing

  355.         # cd /usr/ports/<category>/<portname>
  356.         # make deinstall

  357. as root.
  358. FreeBSD Tip: #86
  359. You can look through a file in a nice text-based interface by typing

  360.         less filename
  361. FreeBSD Tip: #87
  362. You can make a log of your terminal session with script(1).
  363. FreeBSD Tip: #88
  364. You can often get answers to your questions about FreeBSD by searching in the
  365. FreeBSD mailing list archives at

  366. http://www.FreeBSD.org/search/search.html
  367. FreeBSD Tip: #89
  368. You can open up a new split-screen window in (n)vi with :N or :E and then
  369. use ^w to switch between the two.
  370. FreeBSD Tip: #90
  371. You can permanently set environment variables for your shell by putting them
  372. in a startup file for the shell.  The name of the startup file varies
  373. depending on the shell - csh and tcsh uses .login, bash, sh, ksh and zsh use
  374. .profile.  When using bash, sh, ksh or zsh, don't forget to export the
  375. variable.
  376. FreeBSD Tip: #91
  377. You can press Ctrl-D to quickly exit from a shell, or logout from a
  378. login shell.
  379.                 -- Konstantinos Konstantinidis <kkonstan at duth.gr>
  380. FreeBSD Tip: #92
  381. You can press Ctrl-L while in the shell to clear the screen.
  382. FreeBSD Tip: #93
  383. You can press up-arrow or down-arrow to walk through a list of
  384. previous commands in tcsh.
  385. FreeBSD Tip: #94
  386. You can search for documentation on a keyword by typing

  387.         apropos keyword
  388. FreeBSD Tip: #95
  389. You can `set autologout = 30' to have tcsh log you off automatically
  390. if you leave the shell idle for more than 30 minutes.
  391. FreeBSD Tip: #96
  392. You can use aliases to decrease the amount of typing you need to do to get
  393. commands you commonly use.  Examples of fairly popular aliases include (in
  394. Bourne shell style, as in /bin/sh, bash, ksh, and zsh):

  395.         alias lf="ls -FA"
  396.         alias ll="ls -lA"
  397.         alias su="su -m"

  398. In csh or tcsh, these would be

  399.         alias lf ls -FA
  400.         alias ll ls -lA
  401.         alias su su -m

  402. To remove an alias, you can usually use 'unalias aliasname'.  To list all
  403. aliases, you can usually type just 'alias'.
  404. FreeBSD Tip: #97
  405. You can use /etc/make.conf to control the options used to compile software
  406. on this system.  Example entries are in
  407. /usr/share/examples/etc/make.conf.
  408. FreeBSD Tip: #98
  409. You can use "pkg_info" to see a list of packages you have installed.
  410.                 -- Konstantinos Konstantinidis <kkonstan at duth.gr>
  411. FreeBSD Tip: #99
  412. You can use the 'fetch' command to retrieve files over ftp or http.

  413.          fetch http://www.FreeBSD.org/index.html

  414. will download the front page of the FreeBSD web site.
  415. FreeBSD Tip: #100
  416. You can use "whereis" to search standard binary, manual page and source
  417. directories for the specified programs. This can be particularly handy
  418. when you are trying to find where in the ports tree an application is.

  419. Try "whereis firefox" and "whereis whereis".
  420.                 -- Konstantinos Konstantinidis <kkonstan at duth.gr>
  421. FreeBSD Tip: #101
  422. Want to run the same command again?
  423. In tcsh you can type "!!"
  424. FreeBSD Tip: #102
  425. Want to go the directory you were just in?
  426. Type "cd -"
复制代码

评分

参与人数 2可用积分 +12 收起 理由
ulovko + 6 欢迎分享 ^_^
gvim + 6 感谢分享

查看全部评分

论坛徽章:
4
天秤座
日期:2015-01-09 16:08:43狮子座
日期:2015-01-10 12:54:442015年亚洲杯之卡塔尔
日期:2015-01-29 23:02:232015亚冠之卡尔希纳萨夫
日期:2015-10-17 10:41:11
发表于 2012-10-10 20:17 |显示全部楼层
谢谢楼主!

收藏了,以后慢慢看。

论坛徽章:
0
发表于 2013-03-07 18:42 |显示全部楼层
精品文章
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP