Home arrow FreeBSD Tips arrow Miscellaneous Tips
Miscellaneous Tips PDF
Monday, 05 May 2008

Tip 1. Remove ^M Character

#col -bx < win_file > unix_file

Tip 2. Add support for USB Keyboard

If you want to use USB keyboard, edit /boot/device.hints file and add the following line:


With this option kernel will load usb keyboard driver.

Tip 3. Monitor your hard drive transfer rate

If you want to monitor your hard drive transfer rate, to find if you have hard drive bottlenecks, use this command:

#iostat -d -n 5 5

Legend: KB/t = kilobytes per transfer
             tps  =   transfers per second
             MB/s =  megabytes per second

Tip 4. Extract username from /etc/passwd
#cat /etc/passwd | cut -f 1 -d ':'
(content of /etc/paddwd is piped to cut command, using -f parameter for field and -d parameter for delimiter string)

Tip 5. Check if a service is running

For example we want to check if a particular service is running, let's say we want to check that Apache is running, on port 80:

#netstat -ant | grep "*.80 "

Don't forget after .80 to leave a blank space before ", otherwise you will status for all ports that begin with 80. If you want to build a script to check if Apache is started on port 80 (or other http server), you could redirect output to /dev/null, then issue echo $? to see error code, if is 0 then a service is present on port 80, if is 1, nothing is running on port 80.

Tip 6. Replace your boot record

If you have multiple operating systems to boot from, and you've reinstalled windows box, and you've lost boot menu to choose operation system to boot from you could restore, booting a FreeBSD Live CD (like freesbie for example), then issue boot0cfg command:

boot0cfg -o packet -B -m 0xf ad0

(this will replace your boot sector for ad0 drive with a new one).

Tip 7. Convert a string from lowecase to uppercase (shell programming)
To convert a string from lower case to upper case do:

echo "this is lowercase" | tr "[:lower:]" "[:upper:]"

Tip 8. Find a pattern in a file


To find (for example) ssh keyword in all pkg_descr files from /usr/ports use this:

find /usr/ports -name pkg-descr | xargs cat | grep ssh

< Prev   Next >

Other BSD Systems





Best BSD firewall?