2/4/2010 3:52:07 PM

Memorize this site!!   FreeBSD Handbook
Much the information below pertains to 5.x but should be relevant to most versions.
Read the FreeBSD Handbook

Zombie process, how to find them
sshd reload config file changes without reboot
Cvsup the FBSD box
Boot to default generic kernel after a panic!
Return to the installation configuration
Build new kernel
Mount Cdrom
Find command
Changing Shells
Remove ^M characters from files
Start files on boot
Useful commands
Bash prompt & how to change it
Startup Disks
Grep & Tail
Append output to a file
When your system won't boot due to a file you edited
List all user accounts
Time - set server time with ntpdate
Create ISO from CD to HD

  • Find zombie process
      ps aux | awk '{ print $8 " " $2 }' | grep -w Z

  • sshd reload config file changes without reboot
      kill -HUP `cat /var/run/sshd.pid`

  • Symlinks are similar to 'shortcuts'.
      ln -s /wwwroot/dirname /userhomedir/www
      chown -R user /wwwroot/dirname
      This example creates a link from the users homedir to a web serving dir.

  • Cvsup the FBSD box


  • Boot to default generic kernel after a panic!
      At countdown to boot prompt, hit any key except "return"
      You should see an "OK" prompt
      unload kernel (hit enter)
      load kernel.GENERIC (hit enter)
      boot (hit enter)

  • Return to the installation configuration
      Type: /stand/sysinstall

  • Mount CDrom
      mount -t cd9660 /dev/acd0c /cdrom

  • Find Command
      find / -name filename
      find /usr/local -name filename
      find . -type d -maxdepth 1 && find . -type f -maxdepth 1
      find . -type f -exec grep -H "LoadModule" {} \;

  • Changing Shells
      To add Bash shell to "user" after installing
      from /stand/sysinstall or ports:
      chpass  -s  /usr/local/bin/bash  username

  • TAR

  • Remove ^M characters from files
      col -bx < dosfile > newfile
      perl  -pi  -e  "s:^V^M::  g"  filename
      (must use ctrl-V & M not just type the text)

  • Start files on boot
      cd  /usr/local/etc/rc.d/
      Create a file with .sh extension in this directory.
      make filename.sh executable:
      chmod 500 filename.sh
      If there are multiple files in this directory
      they will boot in alphabetical order. For example:

  • Useful commands
      mv filename /directory -> move file or dir
      mkdir /directoryname -> make directory
      rmdir /directoryname -> remove directory
      rm -rf /dirname -> remove dir with files
      pwd -> shows present working directory
      ls -> lists directory contents
      ls -l -> lists directory contents with properties
      cd /directoryname -> change directory

  • Bash prompt & how to change it
      For "root" user.
      From your /root dir
      cp .profile  .bash_profile
      At the bottom of the file, enter this text.
      PS1='\[\e]\e[0;31m\]${PWD}  #\[\e[m\]'
      This will give you a prompt
      which looks like this.
      /directory  #
      Which will be red. To change the color of the prompt, edit the [0;31m\]
      part of the code, and enter your color choice.

  • How to make Startup Disks
      To create startup disks from a Win9x box:
      Must use 2 formatted floppies.
      You can not use copy to create the disks.
      c:\temp\fdimage.exe -v a:\mfsroot.flp
      c:\temp\fdimage.exe -v a:\kern.flp
      Boot system with kern.flp and follow
      onscreen instructions.

  • Grep & Tail
      Say i wanted to grab specific text from files.
      grep & tail commands do this.
      grep FTP /var/log/messages > ftp.txt
      tail -20 ftp.txt | mail user
      What this has done is search the file "messages"
      /var/log/ directory for the text "FTP", and saved it to a text file named "ftp.txt"
      Then, with the "tail" command, we have taken the
      last 20 lines of "ftp.txt" and mailed it to a user.

  • Append output to a file
      This will create one file, named today.log
      It will append all three outputs to a single file
      Using the >> command
      more security.log > today.log
      more firewall.log >> today.log
      grep FTP /var/log/messages >> today.log

      We can group the commands into one line as well
      (more /var/log/security.log; more /var/log/firewall.log; grep
      FTP /var/log/messages) >> /usr/home/user/today.log

  • When your system won't boot due to a file you edited
      Restart the system, type boot -s at the Boot: prompt
      to enter Single User mode.
      At the question about the shell to use, hit ENTER.
      You'll be dropped to a # prompt. Enter mount -u  / to remount your
      root filesystem read/write, then run mount -a to remount all the filesystems.
      Now you should be able to use an editor to fix files. Or commands like
      chpass /usr/local/bin/bash  user to fix your shell.
      Before you apply a shell to a user, make sure you have installed that shell.
  • List of users on your system
      The first example lists users by login name.
      The second example lists users by full name.
      cat /etc/passwd | cut -d: -f1 | grep -v \#
      cat /etc/passwd | cut -d: -f5 | grep -v \#

  • Time - set server time with ntpdate
      ntpdate -v time.apple.com
      -v -> Be verbose. This option will cause ntpdate's version identification string to be logged.
      -q -> Query only - don't set the clock.