FreeBSD FAQ
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
Symlink
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
TAR
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
top
-
ps aux | awk '{ print $8 " " $2 }' | grep -w Z
top
-
kill -HUP `cat /var/run/sshd.pid`
top
-
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.
top
top
-
At countdown to boot prompt, hit any key except "return"
You should see an "OK" prompt
Type:
unload kernel (hit enter)
load kernel.GENERIC (hit enter)
boot (hit enter)
top
-
Type: /stand/sysinstall
top
-
mount -t cd9660 /dev/acd0c /cdrom
top
-
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" {} \;
top
-
To add Bash shell to "user" after installing
from /stand/sysinstall or ports:
chpass -s /usr/local/bin/bash username
top
-
tar xvfz filename
How to use TAR to backup
top
-
col -bx < dosfile > newfile
or
perl -pi -e "s:^V^M:: g" filename
(must use ctrl-V & M not just type the text)
top
-
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:
000_startfirst.sh
010_startsecond.sh
020_startthird.sh
top
-
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
top
-
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.
top
-
ftp.freebsd.org
pub/freebsd/tools/fdimage.exe
pub/freebse/releases/i386/[release]/floppies/mfsroot.flp
pub/freebse/releases/i386/[release]/floppies/kern.flp
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.
top
-
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"
in /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.
top
-
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
top
-
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.
top
-
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 \#
top
-
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.