Aug
13
2009

Freebsd usefull commands

Disk, filesystem

Disk usage
{linux}$ du -sh
{freebsd}$ du -sh

Count subdirectories in current directory:
{linux}$ du –max-depth=1
{freebsd}$ du -d1

Typical approach to find biggest directories/files on disk:
{linux}$ du –max-depth=1 -kx|sort -n
{freebsd}$ du -d1 -kx|sort -n

Find some kinds of files (regex is a mask for full path, no need for begin/end marks)
{linux}$ find . -regextype posix-extended -type f -regex “.*\.(java|class)”
{freebsd}$ find -E . -type f -regex “.*\.(java|class)”

Show open files and programs:
{linux}$ lsof
{freebsd}$ fstat

Real time disk usage (is there something which shows results for every disk in linux?):
{linux}$ vmstat 3
{freebsd}$ iostat 3

Swap info:
{linux}$ free
{freebsd}$ swapinfo

Networking

Show open ports and apps connected to them:
{linux}$ netstat -apne –inet
{freebsd}$ sockstat

Kernel issues

Show loaded modules:
{linux}$ lsmod
{freebsd}$ kldstat

Load kernel module:
{linux}$ modprobe SomeModule
{freebsd}$ kldload SomeModule

Remove loaded module:
{linux}$ rmmod SomeModule
{freebsd}$ kldunload SomeModule

Program development

Trace the system calls of a program:
{linux}$ strace
{freebsd}$ truss
(strace is also available in /usr/ports/devel/strace)

libraries – show all paths + libs:
{linux}$ ldconfig -p
{freebsd}$ ldconfig -r

Packages management

Different linux distros make it own way. I’ll focus on debian-based distributions like Debian, Ubuntu, Kubuntu etc.

Find which package this file belongs to?
{freebsd}$ pkg_info -W /path/to/checked_file
{linux}$ dpkg -S /path/to/checked_file

Have we got a package like… (in (k)ubuntu you can use more friendly tools like synaptic, apt-get)
{linux}$ apt-cache search your_name
{freebsd}$ cd /usr/ports; make search key=your_name
make search name=pear display=name,path
you can also try simple locate (only in package names):
{freebsd}$ locate -i your_name | grep “/usr/ports/”

Install a binary package
{linux}$ apt-get install package_name
{freebsd}$ pkg_add -r package_name
In FreeBSD you have packages made in distribution release time – unfortunately there are no binary upgrades for released version)

Install a package from sources
{linux}$ apt-src
{freebsd}$ cd /usr/ports/path/package; make install clean

About the Author: Urban Cetinski

Urban Cetinski :)

Leave a comment

Get Adobe Flash playerPlugin by wpburn.com wordpress themes