Skip to content

Instantly share code, notes, and snippets.

@AndersonFirmino
Forked from tokhi/unixToolbox.md
Created November 7, 2019 01:52
Show Gist options
  • Save AndersonFirmino/a288a424d66ce8e68f307ba9dfc803fb to your computer and use it in GitHub Desktop.
Save AndersonFirmino/a288a424d66ce8e68f307ba9dfc803fb to your computer and use it in GitHub Desktop.

Revisions

  1. @tokhi tokhi revised this gist Aug 18, 2015. No changes.
  2. @tokhi tokhi revised this gist Aug 18, 2015. No changes.
  3. @tokhi tokhi revised this gist Aug 18, 2015. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions unixToolbox.md
    Original file line number Diff line number Diff line change
    @@ -2936,5 +2936,3 @@ The minimal Makefile for the multi-source program is shown below. The lines with
    <div class="footerlast">
    This document: "Unix Toolbox revision 14.4" is licensed under a <a rel="nofollow" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Licence [Attribution - Share Alike]</a>. © <a href="mailto:c_at_cb.vu">Colin Barschel</a> 2007-2012. Some rights reserved.
    </div>

    <span class="gorgias-qa-btn"><span class="gorgias-qa-btn-badge"></span></span><div class="gorgias-qa-tooltip">Search templates (CTRL+Space)</div>
  4. @tokhi tokhi revised this gist Aug 17, 2015. 1 changed file with 2 additions and 4 deletions.
    6 changes: 2 additions & 4 deletions unixToolbox.md
    Original file line number Diff line number Diff line change
    @@ -2771,9 +2771,7 @@ $ <span class="cmt"># match at the end of a l

    <h2 id="shcmd">Some useful commands</h2>
    The following commands are useful to include in a script or as one liners.
    ```bash

    sort -t. -k1,1n -k2,2n -k3,3n -k4,4n <span class="cmt"># Sort IPv4 ip addresses</span>
    <pre>sort -t. -k1,1n -k2,2n -k3,3n -k4,4n <span class="cmt"># Sort IPv4 ip addresses</span>
    echo 'Test' | tr '[:lower:]' '[:upper:]' <span class="cmt"># Case conversion</span>
    echo foo.bar | cut -d . -f 1 <span class="cmt"># Returns foo</span>
    PID=$(ps | grep script.sh | grep bin | awk '{print $1}') <span class="cmt"># PID of a running script</span>
    @@ -2788,7 +2786,7 @@ testuser=$(cat /usr/local/etc/apache2/passwd | grep -v \ <span class="cmt">#
    root | grep -v \*: | awk -F":" '{ printf("%s\n", $1) }' | grep ^user$)
    :(){ :|:&amp; };: <span class="cmt"># bash fork bomb. Will kill your machine</span>
    tail +2 file &gt; file2 <span class="cmt"># remove the first line from file</span>
    ```
    </pre>

    I use this little trick to change the file extension for many files at once. For example from .cxx to .cpp. Test it first without the <code>| sh</code> at the end. You can also do this with the command <code>rename</code> if installed. Or with bash builtins.
    <pre># ls *.cxx | awk -F. '{print "mv "$0" "$1".cpp"}' | sh
  5. @tokhi tokhi revised this gist Aug 17, 2015. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions unixToolbox.md
    Original file line number Diff line number Diff line change
    @@ -2771,7 +2771,9 @@ $ <span class="cmt"># match at the end of a l

    <h2 id="shcmd">Some useful commands</h2>
    The following commands are useful to include in a script or as one liners.
    <pre>sort -t. -k1,1n -k2,2n -k3,3n -k4,4n <span class="cmt"># Sort IPv4 ip addresses</span>
    ```bash

    sort -t. -k1,1n -k2,2n -k3,3n -k4,4n <span class="cmt"># Sort IPv4 ip addresses</span>
    echo 'Test' | tr '[:lower:]' '[:upper:]' <span class="cmt"># Case conversion</span>
    echo foo.bar | cut -d . -f 1 <span class="cmt"># Returns foo</span>
    PID=$(ps | grep script.sh | grep bin | awk '{print $1}') <span class="cmt"># PID of a running script</span>
    @@ -2786,7 +2788,8 @@ testuser=$(cat /usr/local/etc/apache2/passwd | grep -v \ <span class="cmt">#
    root | grep -v \*: | awk -F":" '{ printf("%s\n", $1) }' | grep ^user$)
    :(){ :|:&amp; };: <span class="cmt"># bash fork bomb. Will kill your machine</span>
    tail +2 file &gt; file2 <span class="cmt"># remove the first line from file</span>
    </pre>
    ```

    I use this little trick to change the file extension for many files at once. For example from .cxx to .cpp. Test it first without the <code>| sh</code> at the end. You can also do this with the command <code>rename</code> if installed. Or with bash builtins.
    <pre># ls *.cxx | awk -F. '{print "mv "$0" "$1".cpp"}' | sh
    # ls *.c | sed "s/.*/cp &amp; &amp;.$(date "+%Y%m%d")/" | sh <span class="cmt"># e.g. copy *.c to *.c.20080401</span>
  6. @tokhi tokhi renamed this gist Aug 17, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  7. @tokhi tokhi revised this gist Aug 17, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions unixCommands.md
    Original file line number Diff line number Diff line change
    @@ -3,9 +3,9 @@
    <div class="abstract">
    This document is a collection of Unix/Linux/BSD commands and tasks which are useful for IT work or for advanced users. This is a practical guide with concise explanations, however the reader is supposed to know what s/he is doing.<br /><br />
    </div>
    <div class="footerfirst">
    ##Unix Toolbox revision 14.4

    ##Unix Toolbox revision 14.4
    <div class="footerfirst">
    The latest version of this document can be found at <a href="http://cb.vu/unixtoolbox.xhtml">http://cb.vu/unixtoolbox.xhtml</a>. Replace .xhtml on the link with <a href="http://cb.vu/unixtoolbox.pdf">.pdf</a> for the PDF version and with <a href="http://cb.vu/unixtoolbox.book.pdf">.book.pdf</a> for the booklet version. On a duplex printer the booklet will create a small book ready to bind. <span class="web">This XHTML page can be converted into a nice PDF document with a CSS3 compliant application (see the <a class="xref" href="#bourneexample">script example</a>).</span> See also the <a href="http://cb.vu/unixtoolbox">about page</a>.<br />
    Error reports and comments are most welcome - <a href="mailto:c\at\cb.vu">[email protected]</a> Colin Barschel.
    <p class="copyright">© <a href="mailto:c_at_cb.vu">Colin Barschel</a> 2007-2012. <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Some rights reserved under Creative Commons</a>.
  8. @tokhi tokhi revised this gist Aug 17, 2015. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions unixCommands.md
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,7 @@ This document is a collection of Unix/Linux/BSD commands and tasks which are use
    </div>
    <div class="footerfirst">
    ##Unix Toolbox revision 14.4

    The latest version of this document can be found at <a href="http://cb.vu/unixtoolbox.xhtml">http://cb.vu/unixtoolbox.xhtml</a>. Replace .xhtml on the link with <a href="http://cb.vu/unixtoolbox.pdf">.pdf</a> for the PDF version and with <a href="http://cb.vu/unixtoolbox.book.pdf">.book.pdf</a> for the booklet version. On a duplex printer the booklet will create a small book ready to bind. <span class="web">This XHTML page can be converted into a nice PDF document with a CSS3 compliant application (see the <a class="xref" href="#bourneexample">script example</a>).</span> See also the <a href="http://cb.vu/unixtoolbox">about page</a>.<br />
    Error reports and comments are most welcome - <a href="mailto:c\at\cb.vu">[email protected]</a> Colin Barschel.
    <p class="copyright">© <a href="mailto:c_at_cb.vu">Colin Barschel</a> 2007-2012. <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Some rights reserved under Creative Commons</a>.
  9. @tokhi tokhi revised this gist Aug 17, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion unixCommands.md
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    This document is a collection of Unix/Linux/BSD commands and tasks which are useful for IT work or for advanced users. This is a practical guide with concise explanations, however the reader is supposed to know what s/he is doing.<br /><br />
    </div>
    <div class="footerfirst">
    Unix Toolbox revision 14.4<br />
    ##Unix Toolbox revision 14.4
    The latest version of this document can be found at <a href="http://cb.vu/unixtoolbox.xhtml">http://cb.vu/unixtoolbox.xhtml</a>. Replace .xhtml on the link with <a href="http://cb.vu/unixtoolbox.pdf">.pdf</a> for the PDF version and with <a href="http://cb.vu/unixtoolbox.book.pdf">.book.pdf</a> for the booklet version. On a duplex printer the booklet will create a small book ready to bind. <span class="web">This XHTML page can be converted into a nice PDF document with a CSS3 compliant application (see the <a class="xref" href="#bourneexample">script example</a>).</span> See also the <a href="http://cb.vu/unixtoolbox">about page</a>.<br />
    Error reports and comments are most welcome - <a href="mailto:c\at\cb.vu">[email protected]</a> Colin Barschel.
    <p class="copyright">© <a href="mailto:c_at_cb.vu">Colin Barschel</a> 2007-2012. <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Some rights reserved under Creative Commons</a>.
  10. @tokhi tokhi revised this gist Aug 17, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion unixCommands.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@

    <div class="title">Unix Toolbox</div>
    #Unix Toolbox
    <div class="abstract">
    This document is a collection of Unix/Linux/BSD commands and tasks which are useful for IT work or for advanced users. This is a practical guide with concise explanations, however the reader is supposed to know what s/he is doing.<br /><br />
    </div>
  11. @tokhi tokhi revised this gist Aug 17, 2015. 1 changed file with 2647 additions and 2 deletions.
    2,649 changes: 2,647 additions & 2 deletions unixCommands.md
    2,647 additions, 2 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
  12. @tokhi tokhi created this gist Aug 17, 2015.
    293 changes: 293 additions & 0 deletions unixCommands.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,293 @@
    <div xmlns="http://www.w3.org/1999/xhtml" id="sysinfo"><h1><a>System</a></h1>
    <p class="xrefp"><a class="xrefp" href="#hardwareinfo">Hardware</a> | <a class="xrefp" href="#loadstats">Statistics</a> | <a class="xrefp" href="#users">Users</a> | <a class="xrefp" href="#limits">Limits</a> | <a class="xrefp" href="#runlevels">Runlevels</a> | <a class="xrefp" href="#resetpasswd">root password</a> | <a class="xrefp" href="#compilekernel">Compile kernel</a> | <a class="xrefp" href="#grub">Repair grub</a> | <a class="xrefp" href="#sysmisc">Misc</a></p>
    Running kernel and system information
    <pre># uname -a <span class="cmt"># Get the kernel version (and BSD version)</span>
    # lsb_release -a <span class="cmt"># Full release info of any LSB distribution</span>
    # cat /etc/SuSE-release <span class="cmt"># Get SuSE version</span>
    # cat /etc/debian_version <span class="cmt"># Get Debian version</span>
    </pre>
    Use /etc/<code>DISTR</code>-release with <code>DISTR=</code> lsb (Ubuntu), redhat, gentoo, mandrake, sun (Solaris), and so on. See also <code>/etc/issue</code>.
    <pre># uptime <span class="cmt"># Show how long the system has been running + load</span>
    # hostname <span class="cmt"># system's host name</span>
    # hostname -i <span class="cmt"># Display the IP address of the host. (Linux only)</span>
    # man hier <span class="cmt"># Description of the file system hierarchy</span>
    # last reboot <span class="cmt"># Show system reboot history</span>
    </pre>
    <h2 id="hardwareinfo">Hardware Informations</h2>
    Kernel detected hardware
    <pre># dmesg <span class="cmt"># Detected hardware and boot messages</span>
    # lsdev <span class="cmt"># information about installed hardware</span>
    # dd if=/dev/mem bs=1k skip=768 count=256 2&gt;/dev/null | strings -n 8 <span class="cmt"># Read BIOS</span>
    </pre>
    <h3>Linux</h3>
    <pre># cat /proc/cpuinfo <span class="cmt"># CPU model</span>
    # cat /proc/meminfo <span class="cmt"># Hardware memory</span>
    # grep MemTotal /proc/meminfo <span class="cmt"># Display the physical memory</span>
    # watch -n1 'cat /proc/interrupts' <span class="cmt"># Watch changeable interrupts continuously</span>
    # free -m <span class="cmt"># Used and free memory (-m for MB)</span>
    # cat /proc/devices <span class="cmt"># Configured devices</span>
    # lspci -tv <span class="cmt"># Show PCI devices</span>
    # lsusb -tv <span class="cmt"># Show USB devices</span>
    # lshal <span class="cmt"># Show a list of all devices with their properties</span>
    # dmidecode <span class="cmt"># Show DMI/SMBIOS: hw info from the BIOS</span>
    </pre>
    <h3>FreeBSD</h3>
    <pre># sysctl hw.model <span class="cmt"># CPU model</span>
    # sysctl hw <span class="cmt"># Gives a lot of hardware information</span>
    # sysctl hw.ncpu <span class="cmt"># number of active CPUs installed</span>
    # sysctl vm <span class="cmt"># Memory usage</span>
    # sysctl hw.realmem <span class="cmt"># Hardware memory</span>
    # sysctl -a | grep mem <span class="cmt"># Kernel memory settings and info</span>
    # sysctl dev <span class="cmt"># Configured devices</span>
    # pciconf -l -cv <span class="cmt"># Show PCI devices</span>
    # usbdevs -v <span class="cmt"># Show USB devices</span>
    # atacontrol list <span class="cmt"># Show ATA devices</span>
    # camcontrol devlist -v <span class="cmt"># Show SCSI devices</span>
    </pre>
    <h2 id="loadstats">Load, statistics and messages</h2>
    The following commands are useful to find out what is going on on the system.
    <pre># top <span class="cmt"># display and update the top cpu processes</span>
    # mpstat 1 <span class="cmt"># display processors related statistics</span>
    # vmstat 2 <span class="cmt"># display virtual memory statistics</span>
    # iostat 2 <span class="cmt"># display I/O statistics (2 s intervals)</span>
    # systat -vmstat 1 <span class="cmt"># BSD summary of system statistics (1 s intervals)</span>
    # systat -tcp 1 <span class="cmt"># BSD tcp connections (try also -ip)</span>
    # systat -netstat 1 <span class="cmt"># BSD active network connections</span>
    # systat -ifstat 1 <span class="cmt"># BSD network traffic through active interfaces</span>
    # systat -iostat 1 <span class="cmt"># BSD CPU and and disk throughput</span>
    # ipcs -a <span class="cmt"># information on System V interprocess</span>
    # tail -n 500 /var/log/messages <span class="cmt"># Last 500 kernel/syslog messages</span>
    # tail /var/log/warn <span class="cmt"># System warnings messages see syslog.conf</span>
    </pre>
    <h2 id="users">Users</h2>
    <pre># id <span class="cmt"># Show the active user id with login and group</span>
    # last <span class="cmt"># Show last logins on the system</span>
    # who <span class="cmt"># Show who is logged on the system</span>
    # groupadd admin <span class="cmt"># Add group "admin" and user colin (Linux/Solaris)</span>
    # useradd -c "Colin Barschel" -g admin -m colin
    # usermod -a -G &lt;group&gt; &lt;user&gt; <span class="cmt"># Add existing user to group (Debian)</span>
    # groupmod -A &lt;user&gt; &lt;group&gt; <span class="cmt"># Add existing user to group (SuSE)</span>
    # userdel colin <span class="cmt"># Delete user colin (Linux/Solaris)</span>
    # adduser joe <span class="cmt"># FreeBSD add user joe (interactive)</span>
    # rmuser joe <span class="cmt"># FreeBSD delete user joe (interactive)</span>
    # pw groupadd admin <span class="cmt"># Use pw on FreeBSD</span>
    # pw groupmod admin -m newmember <span class="cmt"># Add a new member to a group</span>
    # pw useradd colin -c "Colin Barschel" -g admin -m -s /bin/tcsh
    # pw userdel colin; pw groupdel admin
    </pre>
    Encrypted passwords are stored in /etc/shadow for Linux and Solaris and /etc/master.passwd on FreeBSD. If the master.passwd is modified manually (say to delete a password), run <code># pwd_mkdb -p master.passwd</code> to rebuild the database.<br /><br />
    To temporarily prevent logins system wide (for all users but root) use nologin. The message in nologin will be displayed (might not work with ssh pre-shared keys).
    <pre># echo "Sorry no login now" &gt; /etc/nologin <span class="cmt"># (Linux)</span>
    # echo "Sorry no login now" &gt; /var/run/nologin <span class="cmt"># (FreeBSD)</span>
    </pre>

    <h2 id="limits">Limits</h2>
    Some application require higher limits on open files and sockets (like a proxy
    web server, database). The default limits are usually too low.
    <h3>Linux</h3>
    <h4>Per shell/script</h4>
    The shell limits are governed by <code>ulimit</code>. The status is checked
    with <code>ulimit -a</code>. For example to change the open files limit from
    1024 to 10240 do:
    <pre># ulimit -n 10240 <span class="cmt"># This is only valid within the shell</span>
    </pre>
    The <code>ulimit</code> command can be used in a script to change the limits for the script only.

    <h4>Per user/process</h4>
    Login users and applications can be configured in <code>/etc/security/limits.conf</code>. For example:
    <pre># cat /etc/security/limits.conf
    * hard nproc 250 <span class="cmt"># Limit user processes</span>
    asterisk hard nofile 409600 <span class="cmt"># Limit application open files</span>
    </pre>
    <h4>System wide</h4>
    Kernel limits are set with sysctl. Permanent limits are set in <code>/etc/sysctl.conf</code>.
    <pre># sysctl -a <span class="cmt"># View all system limits</span>
    # sysctl fs.file-max <span class="cmt"># View max open files limit</span>
    # sysctl fs.file-max=102400 <span class="cmt"># Change max open files limit</span>
    # echo "1024 50000" &gt; /proc/sys/net/ipv4/ip_local_port_range <span class="cmt"># port range</span>
    # cat /etc/sysctl.conf
    fs.file-max=102400 <span class="cmt"># Permanent entry in sysctl.conf</span>
    # cat /proc/sys/fs/file-nr <span class="cmt"># How many file descriptors are in use</span>
    </pre>

    <h3>FreeBSD</h3>
    <h4>Per shell/script</h4>
    Use the command <code>limits</code> in csh or tcsh or as in Linux, use <code>ulimit</code> in an sh or bash shell.
    <h4>Per user/process</h4>
    The default limits on login are set in <code>/etc/login.conf</code>. An unlimited value is still limited by the system maximal value.
    <h4>System wide</h4>
    Kernel limits are also set with sysctl. Permanent limits are set in <code>/etc/sysctl.conf</code> or <code>/boot/loader.conf</code>. The syntax is the same as Linux but the keys are different.
    <pre># sysctl -a <span class="cmt"># View all system limits</span>
    # sysctl kern.maxfiles=XXXX <span class="cmt"># maximum number of file descriptors</span>
    kern.ipc.nmbclusters=32768 <span class="cmt"># Permanent entry in /etc/sysctl.conf</span>
    kern.maxfiles=65536 <span class="cmt"># Typical values for Squid</span>
    kern.maxfilesperproc=32768
    kern.ipc.somaxconn=8192 <span class="cmt"># TCP queue. Better for apache/sendmail</span>
    # sysctl kern.openfiles <span class="cmt"># How many file descriptors are in use</span>
    # sysctl kern.ipc.numopensockets <span class="cmt"># How many open sockets are in use</span>
    # sysctl net.inet.ip.portrange.last=50000 <span class="cmt"># Default is 1024-5000</span>
    # netstat -m <span class="cmt"># network memory buffers statistics</span>
    </pre>
    See The <a href="http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/configtuning-kernel-limits.html">FreeBSD handbook Chapter 11</a><span class="fn">http://www.freebsd.org/handbook/configtuning-kernel-limits.html</span> for details. And also <a href="http://serverfault.com/questions/64356/freebsd-performance-tuning-sysctls-loader-conf-kernel">FreeBSD performance tuning</a><span class="fn">http://serverfault.com/questions/64356/freebsd-performance-tuning-sysctls-loader-conf-kernel</span>

    <h3>Solaris</h3>
    The following values in <code>/etc/system</code> will increase the maximum file descriptors per proc:
    <pre>set rlim_fd_max = 4096 <span class="cmt"># Hard limit on file descriptors for a single proc</span>
    set rlim_fd_cur = 1024 <span class="cmt"># Soft limit on file descriptors for a single proc</span>
    </pre>

    <h2 id="runlevels">Runlevels</h2>
    <h3>Linux</h3>
    Once booted, the kernel starts <code>init</code> which then starts <code>rc</code> which starts all scripts belonging to a runlevel. The scripts are stored in /etc/init.d and are linked into /etc/rc.d/rcN.d with N the runlevel number.<br />
    The default runlevel is configured in /etc/inittab. It is usually 3 or 5:
    <pre># grep default: /etc/inittab
    id:3:initdefault:
    </pre>
    The actual runlevel can be changed with <code>init</code>. For example to go from 3 to 5:
    <pre># init 5 <span class="cmt"># Enters runlevel 5</span></pre>
    <ul style="list-style-type:none; page-break-inside:avoid;">
    <li>0       Shutdown and halt</li>
    <li>1       Single-User mode (also S)</li>
    <li>2       Multi-user without network</li>
    <li>3       Multi-user with network</li>
    <li>5       Multi-user with X</li>
    <li>6       Reboot</li>
    </ul>
    Use <code>chkconfig</code> to configure the programs that will be started at boot in a runlevel.
    <pre># chkconfig --list <span class="cmt"># List all init scripts</span>
    # chkconfig --list sshd <span class="cmt"># Report the status of sshd</span>
    # chkconfig sshd --level 35 on <span class="cmt"># Configure sshd for levels 3 and 5</span>
    # chkconfig sshd off <span class="cmt"># Disable sshd for all runlevels</span>
    </pre>
    Debian and Debian based distributions like Ubuntu or Knoppix use the command <code>update-rc.d</code> to manage the runlevels scripts. Default is to start in 2,3,4 and 5 and shutdown in 0,1 and 6.
    <pre># update-rc.d sshd defaults <span class="cmt"># Activate sshd with the default runlevels</span>
    # update-rc.d sshd start 20 2 3 4 5 . stop 20 0 1 6 . <span class="cmt"># With explicit arguments</span>
    # update-rc.d -f sshd remove <span class="cmt"># Disable sshd for all runlevels</span>
    # shutdown -h now (or # poweroff) <span class="cmt"># Shutdown and halt the system</span>
    </pre>

    <h3>FreeBSD</h3>
    The BSD boot approach is different from the SysV, there are no runlevels. The final boot state (single user, with or without X) is configured in <code>/etc/ttys</code>. All OS scripts are located in <code>/etc/rc.d/</code> and in <code>/usr/local/etc/rc.d/</code> for third-party applications. The activation of the service is configured in <code>/etc/rc.conf</code> and <code>/etc/rc.conf.local</code>. The default behavior is configured in <code>/etc/defaults/rc.conf</code>. The scripts responds at least to start|stop|status.
    <pre># /etc/rc.d/sshd status
    sshd is running as pid 552.
    # shutdown now <span class="cmt"># Go into single-user mode</span>
    # exit <span class="cmt"># Go back to multi-user mode</span>
    # shutdown -p now <span class="cmt"># Shutdown and halt the system</span>
    # shutdown -r now <span class="cmt"># Reboot</span>
    </pre>
    The process <code>init</code> can also be used to reach one of the following states level. For example <code># init 6</code> for reboot.
    <ul style="list-style-type:none; page-break-inside:avoid;">
    <li>0       Halt and turn the power off (signal <code>USR2</code>)</li>
    <li>1       Go to single-user mode (signal <code>TERM</code>)</li>
    <li>6       Reboot the machine (signal <code>INT</code>)</li>
    <li>c       Block further logins (signal <code>TSTP</code>)</li>
    <li>q       Rescan the ttys(5) file (signal <code>HUP</code>)</li>
    </ul>
    <h3>Windows</h3>
    Start and stop a service with either the <code>service name</code> or <code>"service description"</code> (shown in the Services Control Panel) as follows:
    <pre>net stop WSearch
    net start WSearch <span class="cmt"># start search service</span>
    net stop "Windows Search"
    net start "Windows Search" <span class="cmt"># same as above using descr.</span>
    </pre>
    <h2 id="resetpasswd">Reset root password</h2>
    <h3>Linux method 1</h3>
    At the boot loader (lilo or grub), enter the following boot option:
    <pre>init=/bin/sh</pre>
    The kernel will mount the root partition and <code>init</code> will start the bourne shell
    instead of <code>rc</code> and then a runlevel. Use the command <code>passwd</code> at the prompt to change the password and then reboot. Forget the single user mode as you need the password for that.<br />
    If, after booting, the root partition is mounted read only, remount it rw:
    <pre># mount -o remount,rw /
    # passwd <span class="cmt"># or delete the root password (/etc/shadow)</span>
    # sync; mount -o remount,ro / <span class="cmt"># sync before to remount read only</span>
    # reboot
    </pre>
    <h3>FreeBSD method 1</h3>
    On FreeBSD, boot in single user mode, remount / rw and use passwd. You can select the single user mode on the boot menu (option 4) which is displayed for 10 seconds at startup. The single user mode will give you a root shell on the / partition.
    <pre># mount -u /; mount -a <span class="cmt"># will mount / rw</span>
    # passwd
    # reboot
    </pre>

    <h3>Unixes and FreeBSD and Linux method 2</h3>
    Other Unixes might not let you go away with the simple init trick. The solution is to mount the root partition from an other OS (like a rescue CD) and change the password on the disk.
    <ul>
    <li>Boot a live CD or installation CD into a rescue mode which will give you a shell.</li>
    <li>Find the root partition with fdisk e.g. fdisk /dev/sda</li>
    <li>Mount it and use chroot:</li>
    </ul>
    <pre># mount -o rw /dev/ad4s3a /mnt
    # chroot /mnt <span class="cmt"># chroot into /mnt</span>
    # passwd
    # reboot
    </pre>

    <h2 id="kernelmodules">Kernel modules</h2>
    <h3>Linux</h3>
    <pre># lsmod <span class="cmt"># List all modules loaded in the kernel</span>
    # modprobe isdn <span class="cmt"># To load a module (here isdn)</span>
    </pre>
    <h3>FreeBSD</h3>
    <pre># kldstat <span class="cmt"># List all modules loaded in the kernel</span>
    # kldload crypto <span class="cmt"># To load a module (here crypto)</span>
    </pre>
    <h2 id="compilekernel">Compile Kernel</h2>
    <h3>Linux</h3>
    <pre># cd /usr/src/linux
    # make mrproper <span class="cmt"># Clean everything, including config files</span>
    # make oldconfig <span class="cmt"># Reuse the old .config if existent</span>
    # make menuconfig <span class="cmt"># or xconfig (Qt) or gconfig (GTK)</span>
    # make <span class="cmt"># Create a compressed kernel image</span>
    # make modules <span class="cmt"># Compile the modules</span>
    # make modules_install <span class="cmt"># Install the modules</span>
    # make install <span class="cmt"># Install the kernel</span>
    # reboot
    </pre>
    <h3>FreeBSD</h3>
    Optionally update the source tree (in <code>/usr/src</code>) with csup (as of FreeBSD 6.2 or later):
    <pre># csup &lt;supfile&gt;</pre>
    I use the following supfile:
    <pre>*default host=cvsup5.FreeBSD.org # www.freebsd.org/handbook/cvsup.html#CVSUP-MIRRORS
    *default prefix=/usr
    *default base=/var/db
    *default release=cvs delete tag=RELENG_7
    src-all
    </pre>
    To modify and rebuild the kernel, copy the generic configuration file to a new name and edit it as needed (you can also edit the file <code>GENERIC</code> directly). To restart the build after an interruption, add the option <code>NO_CLEAN=YES</code> to the make command to avoid cleaning the objects already build.
    <pre># cd /usr/src/sys/i386/conf/
    # cp GENERIC MYKERNEL
    # cd /usr/src
    # make buildkernel KERNCONF=MYKERNEL
    # make installkernel KERNCONF=MYKERNEL
    </pre>
    To rebuild the full OS:
    <pre># make buildworld <span class="cmt"># Build the full OS but not the kernel</span>
    # make buildkernel <span class="cmt"># Use KERNCONF as above if appropriate</span>
    # make installkernel
    # reboot
    # mergemaster -p <span class="cmt"># Compares only files known to be essential</span>
    # make installworld
    # mergemaster -i -U <span class="cmt"># Update all configurations and other files</span>
    # reboot
    </pre>
    For small changes in the source you can use NO_CLEAN=yes to avoid rebuilding the whole tree.
    <pre># make buildworld NO_CLEAN=yes <span class="cmt"># Don't delete the old objects</span>
    # make buildkernel KERNCONF=MYKERNEL NO_CLEAN=yes
    </pre>

    <h2 id="grub">Repair grub</h2>
    So you broke grub? Boot from a live cd, [find your linux partition under <code>/dev</code> and use <code>fdisk</code> to find the linux partion] mount the linux partition, add /proc and /dev and use <code>grub-install /dev/xyz</code>. Suppose linux lies on <code>/dev/sda6</code>:
    <pre># mount /dev/sda6 /mnt <span class="cmt"># mount the linux partition on /mnt</span>
    # mount --bind /proc /mnt/proc <span class="cmt"># mount the proc subsystem into /mnt</span>
    # mount --bind /dev /mnt/dev <span class="cmt"># mount the devices into /mnt</span>
    # chroot /mnt <span class="cmt"># change root to the linux partition</span>
    # grub-install /dev/sda <span class="cmt"># reinstall grub with your old settings</span>
    </pre>
    <h2 id="sysmisc">Misc</h2>
    Disable OSX virtual memory (repeat with <code>load</code> to re-enable). Faster system, but a little risky.
    <pre># sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist
    # sleep 3600; pmset sleepnow <span class="cmt"># go to standby in one hour (OSX)</span>
    # defaults write -g com.apple.mouse.scaling -float 8
    <span class="cmt"># OSX mouse acceleration (use -1 to reverse)</span>
    </pre>
    </div>